X-Git-Url: https://ruin.nu/git/%3CTMPL_VAR%20NAME=PAGE%3E?a=blobdiff_plain;f=action.cpp;h=52c1686f21f3bc09ac096c8cae91327013fc5d7c;hb=3f82360c5e0c61eccacdbaf3bd077852b9326f34;hp=3e9cddf692163b41a515655c33e37ef29bffd270;hpb=dc49c0c521090f0eb4b9692b25a129537c07e19e;p=popboot.git diff --git a/action.cpp b/action.cpp index 3e9cddf..52c1686 100644 --- a/action.cpp +++ b/action.cpp @@ -1,26 +1,57 @@ #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; } -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; } -literals Action::preconditions() const{ +const Preconditions& Action::preconditions() const{ return _preconditions; } int Action::execute() const{ + cout << "Executing: " << _name << endl; + //return system(_executable.c_str()); + pid_t proc = fork(); + if (proc == -1) return proc; + + if (proc == 0) { + //execl("/bin/sh", "-c", _executable.c_str(), (char*) NULL); + int val = system(_executable.c_str()); + exit(val); + } + int retval; + + waitpid(proc,&retval,0); + + cout << "Done executing: " << _name << endl; + return retval; +} - return 0; +const string& Action::name() const{ + return _name; }