25 #ifndef __I6ENGINE_MODULES_PYTHONSCRIPTINGMANAGER_H__ 
   26 #define __I6ENGINE_MODULES_PYTHONSCRIPTINGMANAGER_H__ 
   36 #include "boost/python.hpp" 
   40         class ScriptingFacade;
 
   44         class PythonScriptingMailbox;
 
   66                 template<
typename Ret, 
typename... args>
 
   67                 typename std::enable_if<std::is_void<Ret>::value, Ret>::type 
callScript(
const std::string & file, 
const std::string & func, args... B) {
 
   68                         _callScripts.push(std::bind([
this, file, func](args... A) {
 
   69                                 ASSERT_THREAD_SAFETY_FUNCTION
 
   70                                 parseScript(file, false);
 
   73                                         boost::python::object module = boost::python::import(
"__main__");
 
   74                                         boost::python::object global = module.attr(
"__dict__");
 
   75                                         boost::python::object f = global[func];
 
   76                                         boost::python::call<Ret>(f.ptr(), A...);
 
   77                                 } catch (
const boost::python::error_already_set &) {
 
   86                 template<
typename Ret, 
typename... args>
 
   87                 typename std::enable_if<!std::is_void<Ret>::value, std::shared_ptr<utils::Future<Ret>>>::type 
callScript(
const std::string & file, 
const std::string & func, args... B) {
 
   88                         std::shared_ptr<utils::Future<Ret>> ret = std::make_shared<utils::Future<Ret>>();
 
   89                         _callScripts.push(std::bind([
this, file, func, ret](args... A) {
 
   90                                 ASSERT_THREAD_SAFETY_FUNCTION
 
   91                                 parseScript(file, false);
 
   94                                         boost::python::object module = boost::python::import(
"__main__");
 
   95                                         boost::python::object global = module.attr(
"__dict__");
 
   96                                         boost::python::object f = global[func];
 
   97                                         ret->push(boost::python::call<Ret>(f.ptr(), A...));
 
   98                                 } catch (
const boost::python::error_already_set &) {
 
  108                 template<
typename Ret, 
typename... args>
 
  109                 typename std::enable_if<std::is_void<Ret>::value, Ret>::type 
callFunction(
const std::string & func, args... B) {
 
  110                         _callScripts.push(std::bind([
this, func](args... A) {
 
  111                                 ASSERT_THREAD_SAFETY_FUNCTION
 
  113                                         boost::python::object module = boost::python::import(
"__main__");
 
  114                                         boost::python::object global = module.attr(
"__dict__");
 
  115                                         boost::python::object f = global[func];
 
  116                                         boost::python::call<Ret>(f.ptr(), A...);
 
  117                                 } catch (
const boost::python::error_already_set &) {
 
  126                 template<
typename Ret, 
typename... args>
 
  127                 typename std::enable_if<!std::is_void<Ret>::value, std::shared_ptr<utils::Future<Ret>>>::type 
callFunction(
const std::string & func, args... B) {
 
  128                         std::shared_ptr<utils::Future<Ret>> ret = std::make_shared<utils::Future<Ret>>();
 
  129                         _callScripts.push(std::bind([
this, func, ret](args... A) {
 
  130                                 ASSERT_THREAD_SAFETY_FUNCTION
 
  132                                         boost::python::object module = boost::python::import(
"__main__");
 
  133                                         boost::python::object global = module.attr(
"__dict__");
 
  134                                         boost::python::object f = global[func];
 
  135                                         ret->push(boost::python::call<Ret>(f.ptr(), A...));
 
  136                                 } catch (
const boost::python::error_already_set &) {
 
  146                 template<
typename Ret, 
typename... args>
 
  147                 typename std::enable_if<std::is_void<Ret>::value, Ret>::type 
callScriptWithCallback(
const std::string & file, 
const std::string & func, 
const std::function<
void(
void)> & callback, args... B) {
 
  148                         _callScripts.push(std::bind([
this, file, func, callback](args... A) {
 
  149                                 ASSERT_THREAD_SAFETY_FUNCTION
 
  150                                 parseScript(file, false);
 
  152                                         boost::python::object module = boost::python::import(
"__main__");
 
  153                                         boost::python::object global = module.attr(
"__dict__");
 
  154                                         boost::python::object f = global[func];
 
  155                                         boost::python::call<Ret>(f.ptr(), A...);
 
  156                                 } catch (
const boost::python::error_already_set &) {
 
  166                 template<
typename Ret, 
typename... args>
 
  167                 typename std::enable_if<!std::is_void<Ret>::value, std::shared_ptr<utils::Future<Ret>>>::type 
callScriptWithCallback(
const std::string & file, 
const std::string & func, 
const std::function<
void(
void)> & callback, args... B) {
 
  168                         std::shared_ptr<utils::Future<Ret>> ret = std::make_shared<utils::Future<Ret>>();
 
  169                         _callScripts.push(std::bind([
this, file, func, callback, ret](args... A) {
 
  170                                 ASSERT_THREAD_SAFETY_FUNCTION
 
  171                                 parseScript(file, false);
 
  173                                         boost::python::object module = boost::python::import(
"__main__");
 
  174                                         boost::python::object global = module.attr(
"__dict__");
 
  175                                         boost::python::object f = global[func];
 
  176                                         ret->push(boost::python::call<Ret>(f.ptr(), A...));
 
  177                                 } catch (
const boost::python::error_already_set &) {
 
  188                 template<
typename Ret, 
typename... args>
 
  189                 typename std::enable_if<std::is_void<Ret>::value, Ret>::type 
callFunctionWithCallback(
const std::string & func, 
const std::function<
void(
void)> & callback, args... B) {
 
  190                         _callScripts.push(std::bind([
this, func, callback](args... A) {
 
  191                                 ASSERT_THREAD_SAFETY_FUNCTION
 
  193                                         boost::python::object module = boost::python::import(
"__main__");
 
  194                                         boost::python::object global = module.attr(
"__dict__");
 
  195                                         boost::python::object f = global[func];
 
  196                                         boost::python::call<Ret>(f.ptr(), A...);
 
  197                                 } catch (
const boost::python::error_already_set &) {
 
  207                 template<
typename Ret, 
typename... args>
 
  208                 typename std::enable_if<!std::is_void<Ret>::value, std::shared_ptr<utils::Future<Ret>>>::type 
callFunctionWithCallback(
const std::string & func, 
const std::function<
void(
void)> & callback, args... B) {
 
  209                         std::shared_ptr<utils::Future<Ret>> ret = std::make_shared<utils::Future<Ret>>();
 
  210                         _callScripts.push(std::bind([
this, func, callback, ret](args... A) {
 
  211                                 ASSERT_THREAD_SAFETY_FUNCTION
 
  213                                         boost::python::object module = boost::python::import(
"__main__");
 
  214                                         boost::python::object global = module.attr(
"__dict__");
 
  215                                         boost::python::object f = global[func];
 
  216                                         ret->push(boost::python::call<Ret>(f.ptr(), A...));
 
  217                                 } catch (
const boost::python::error_already_set &) {
 
  229                 typename std::enable_if<std::is_pointer<T>::value>::type 
setGlobalVariable(
const std::string & name, T value) {
 
  230                         _callScripts.push(std::bind([
this, name, value]() {
 
  232                                 boost::python::scope().attr(name.c_str()) = value;
 
  239                 void loadAllScripts();
 
  242                 std::set<std::string> _scripts;
 
  243                 std::string _scriptsPath;
 
  254                 void parseScript(
const std::string & file, 
bool completePath);
 
  259                 void logStacktrace();
 
std::enable_if<!std::is_void< Ret >::value, std::shared_ptr< utils::Future< Ret > > >::type callScriptWithCallback(const std::string &file, const std::string &func, const std::function< void(void)> &callback, args...B)
executes the given method in the given script with return type non-void and calls callback after exec...
std::enable_if< std::is_void< Ret >::value, Ret >::type callScriptWithCallback(const std::string &file, const std::string &func, const std::function< void(void)> &callback, args...B)
executes the given method in the given script with return type void and calls callback after executio...
#define ASSERT_THREAD_SAFETY_FUNCTION
#define ISIXE_MODULES_API
std::enable_if< std::is_void< Ret >::value, Ret >::type callFunctionWithCallback(const std::string &func, const std::function< void(void)> &callback, args...B)
executes the given method with return type void and calls callback after execution of the script ...
boost::shared_ptr< Message > Ptr
std::enable_if< std::is_pointer< T >::value >::type setGlobalVariable(const std::string &name, T value)
sets a global variable 
std::enable_if< std::is_void< Ret >::value, Ret >::type callScript(const std::string &file, const std::string &func, args...B)
executes the given method in the given script with return type void 
#define ASSERT_THREAD_SAFETY_HEADER
std::enable_if< std::is_void< Ret >::value, Ret >::type callFunction(const std::string &func, args...B)
executes the given method with return type void 
std::enable_if<!std::is_void< Ret >::value, std::shared_ptr< utils::Future< Ret > > >::type callFunctionWithCallback(const std::string &func, const std::function< void(void)> &callback, args...B)
executes the given method with return type non-void and calls callback after execution of the script ...
std::enable_if<!std::is_void< Ret >::value, std::shared_ptr< utils::Future< Ret > > >::type callFunction(const std::string &func, args...B)
executes the given method with return type non-void 
Handles the incoming messages on the scripting channel and calls the corresponding methods...
std::enable_if<!std::is_void< Ret >::value, std::shared_ptr< utils::Future< Ret > > >::type callScript(const std::string &file, const std::string &func, args...B)
executes the given method in the given script with return type non-void