#include "action.h"
+#include <cstdlib>
+#include <unistd.h>
+#include <sys/wait.h>
#include <iostream>
using namespace std;
using namespace __gnu_cxx;
-const literals Action::_empty;
+const Literals Action::_empty;
-Action::Action(std::string name, preconditionsVector preconditions, effectsMap effects){
+Action::Action(std::string name,const Preconditions& preconditions, std::string executable,const EffectsMap& effects){
_name = name;
+ _executable = executable;
_preconditions = preconditions;
_effects = effects;
- _currentPrecondition = _preconditions.begin();
}
Action::Action(const Action& action){
_name = action._name;
_preconditions = action._preconditions;
_effects = action._effects;
+ _executable = action._executable;
}
-const literals& Action::effects(int value) const{
- effectsMap::const_iterator effects = _effects.find(value);
+const Literals& Action::effects(int value) const{
+ EffectsMap::const_iterator effects = _effects.find(value);
if (effects != _effects.end())
return effects->second;
return _empty;
}
-const literals& Action::preconditions() const{
- return _currentPrecondition->second;
+const Preconditions& Action::preconditions() const{
+ return _preconditions;
}
int Action::execute() const{
- cout << "Executing: " << _currentPrecondition->first << endl;
- return 0;
+ cout << "Executing: " << _name << endl;
+ //return system(_executable.c_str());
+ pid_t proc = fork();
+ if (proc == -1) return proc;
+
+ int retval;
+ if (proc == 0) {
+ //execl("/bin/sh", "-c", _executable.c_str(), (char*) NULL);
+ retval = system(_executable.c_str());
+ _exit(WEXITSTATUS(retval));
+ }
+ waitpid(proc,&retval,0);
+ cout << "Done executing: " << _name << ", returnvalue: " << WEXITSTATUS(retval) << endl;
+ return WEXITSTATUS(retval);
}
const string& Action::name() const{
return _name;
}
-
-bool Action::nextExecutable(){
- if (++_currentPrecondition != _preconditions.end())
- return true;
- return false;
-}
-
-void Action::reset(){
- _currentPrecondition = _preconditions.begin();
-}