X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=blobdiff_plain;f=action.cpp;h=5dbe86954cbbd29644ba710d35dd8585b2774c62;hp=626eb37475bb5487756381dafcd823fd2188380f;hb=HEAD;hpb=e26fd7b3195576b25ffe51253a391b53f412a650 diff --git a/action.cpp b/action.cpp index 626eb37..5dbe869 100644 --- a/action.cpp +++ b/action.cpp @@ -1,32 +1,55 @@ #include "action.h" +#include +#include +#include #include using namespace std; +using namespace __gnu_cxx; -Action::Action(std::string executable, literals preconditions, literals effects){ +const Literals Action::_empty; + +Action::Action(std::string name,const Preconditions& preconditions, std::string executable,const EffectsMap& effects){ + _name = name; _executable = executable; _preconditions = preconditions; _effects = effects; } Action::Action(const Action& action){ - _executable = action._executable; + _name = action._name; _preconditions = action._preconditions; _effects = action._effects; + _executable = action._executable; } -const literals& Action::effects() const{ - return _effects; +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{ +const Preconditions& Action::preconditions() const{ return _preconditions; } int Action::execute() const{ - cout << "Executing: " << _executable << 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::executable() const{ - return _executable; +const string& Action::name() const{ + return _name; }