- Add preliminary code for Python policy management
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@370 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
2e1a699b65
commit
633416f340
|
@ -20,9 +20,11 @@
|
||||||
|
|
||||||
#include "python_policy_manager.hh"
|
#include "python_policy_manager.hh"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdio>
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
//static object
|
//static object
|
||||||
PythonPolicyManager* PythonPolicyManager::_instance = NULL;
|
PythonPolicyManager* PythonPolicyManager::_instance = NULL;
|
||||||
|
|
||||||
|
@ -63,8 +65,79 @@ PythonPolicyManager::init()
|
||||||
|
|
||||||
PyRun_SimpleString("import sys\n"
|
PyRun_SimpleString("import sys\n"
|
||||||
"sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n");
|
"sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n");
|
||||||
|
|
||||||
|
// Okay, here we go.
|
||||||
|
// Black magic at work.
|
||||||
|
|
||||||
|
// FIXME : Hardcoded policy
|
||||||
|
char* policy_name = "fcfs_policy";
|
||||||
|
PyObject* pLoadmeStr = PyString_FromString(policy_name);
|
||||||
|
PyObject *pModule = PyImport_Import(pLoadmeStr);
|
||||||
|
Py_DECREF(pLoadmeStr);
|
||||||
|
|
||||||
|
if( !pModule )
|
||||||
|
{
|
||||||
|
PyErr_Print(); // Error in import
|
||||||
|
// FIXME : don't exit abruptly, but fall back gracefully
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dictionary with defined ``symbols'' for .pyc file
|
||||||
|
PyObject* pDict = PyModule_GetDict(pModule);
|
||||||
|
assert(pDict);
|
||||||
|
|
||||||
|
// Build up UserPythonScriptAdapter
|
||||||
|
{
|
||||||
|
std::string py_adapter = std::string("class UserPythonScriptAdapter(") +
|
||||||
|
policy_name + "):\n"
|
||||||
|
" def __init__(self):\n"
|
||||||
|
" pass;\n"
|
||||||
|
" def async_configure():\n"
|
||||||
|
" pass;\n"
|
||||||
|
" def async_sort_queue():\n"
|
||||||
|
" pass;\n"
|
||||||
|
" def async_is_preemptible():\n"
|
||||||
|
" pass;\n"
|
||||||
|
" def async_is_timesliced():\n"
|
||||||
|
" pass;\n"
|
||||||
|
"\n";
|
||||||
|
PyRun_SimpleString(py_adapter.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//build SWIG proxy object inside the interpreter
|
||||||
|
PyRun_SimpleString("py_ad = UserPythonScriptAdapter");
|
||||||
|
/* const char *buildPyProcess =
|
||||||
|
"import proto_process\n"
|
||||||
|
"p = proto_process.Process(19, 'param')\n"
|
||||||
|
"#set ownership to C++ code\n"
|
||||||
|
"p.thisown = 0\n";
|
||||||
|
|
||||||
|
PyRun_SimpleString(buildPyProcess);
|
||||||
|
*/
|
||||||
|
|
||||||
|
Py_DECREF(pModule);
|
||||||
|
|
||||||
|
pModule = PyImport_AddModule("__main__");
|
||||||
|
pDict = PyModule_GetDict(pModule);
|
||||||
|
|
||||||
|
// PyObject *pPyProcess = PyMapping_GetItemString(pDict, "p");
|
||||||
|
// assert(pPyProcess);
|
||||||
|
|
||||||
|
// Matteo: PyTuple_SetItem steals the reference, so
|
||||||
|
// we don't DECREF pPyProcess.
|
||||||
|
// See http://www.python.org/doc/2.4.2/api/refcountDetails.html#l2h-13
|
||||||
|
// PyTuple_SetItem(pArgs, 0, pPyProcess);
|
||||||
|
|
||||||
|
// assert(pFunc);
|
||||||
|
|
||||||
|
/* if(PyCallable_Check(pFunc))
|
||||||
|
{
|
||||||
|
PyObject* ret = PyObject_CallObject(pFunc, pArgs);
|
||||||
|
Py_DECREF(pArgs);
|
||||||
|
if(!ret) PyErr_Print();
|
||||||
|
else Py_DECREF(ret);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue