00001 /* 00002 * ScriptExecuter.h 00003 * 00004 * Created on: Oct 17, 2013 00005 * Author: blackpc 00006 */ 00007 00008 #ifndef ScriptExecuter_H_ 00009 #define ScriptExecuter_H_ 00010 00011 #include <python2.7/Python.h> 00012 #include <ros/ros.h> 00013 #include <iostream> 00014 #include <map> 00015 #include <boost/thread.hpp> 00016 #include <boost/foreach.hpp> 00017 #include <boost/lexical_cast.hpp> 00018 #include <boost/algorithm/string.hpp> 00019 00020 #include <scriptable_monitor/YamlFunctions.h> 00021 #include <scriptable_monitor/InternalFunction.h> 00022 00023 #include "PythonScript.h" 00024 #include "PythonExecuter.h" 00025 00026 #define foreach BOOST_FOREACH 00027 00028 typedef map<string, string> ScriptInputType; 00029 00030 using namespace std; 00031 00032 class ScriptExecuter 00033 { 00034 public: 00035 ScriptExecuter(); 00036 00042 CompilationResult compile(PythonScript& script); 00043 void execute(PythonScript& pythonScript, ScriptInputType input); 00044 00050 void simulate(PythonScript& pythonScript); 00051 00052 private: 00053 00054 // ////////////////////////////////////////////////////////////////// 00055 // // Execution context ///////////////////////////////////////////// 00056 // ////////////////////////////////////////////////////////////////// 00057 00058 static boost::mutex _executionMutex; 00059 static PythonScript* _currentScript; 00060 00061 static bool _runtime; 00062 static bool _simulation; 00063 static bool _validationFailed; 00064 static vector<string> _validationsPassed; 00065 static vector<string> _validationsFailed; 00066 static map<string, string> _topicValues; 00067 static PyMethodDef MonitorPythonLib[]; 00068 00069 static PyObject* convertToPythonType(string value); 00070 00071 static PyObject* internalTopic(PyObject* self, PyObject* args); 00072 static PyObject* internalValidation(PyObject* self, PyObject* args); 00073 static PyObject* internalFunction(PyObject* self, PyObject* args); 00074 00075 }; 00076 00077 00078 #endif /* ScriptExecuter_H_ */