- Add first undocumented (and quite useless) test for libpyloader.
It doesn't work properly for no apparent reason. - Add SWIG interface generation for Scheduler git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@375 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
cc26da0b59
commit
712e14f558
7 changed files with 126 additions and 81 deletions
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
using namespace sgpem;
|
||||
|
||||
//static object
|
||||
|
@ -33,12 +33,12 @@ PythonPolicyManager::PythonPolicyManager()
|
|||
{
|
||||
}
|
||||
|
||||
PythonPolicyManager&
|
||||
PythonPolicyManager* const
|
||||
PythonPolicyManager::get_instance()
|
||||
{
|
||||
if(!_instance)
|
||||
_instance = new PythonPolicyManager();
|
||||
return *_instance;
|
||||
if(!_instance)
|
||||
_instance = new PythonPolicyManager();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Policy&
|
||||
|
@ -70,16 +70,16 @@ PythonPolicyManager::init()
|
|||
// Black magic at work.
|
||||
|
||||
// FIXME : Hardcoded policy
|
||||
char* policy_name = "fcfs_policy";
|
||||
char* policy_name = "fcfs";
|
||||
PyObject* pLoadmeStr = PyString_FromString(policy_name);
|
||||
PyObject *pModule = PyImport_Import(pLoadmeStr);
|
||||
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);
|
||||
PyErr_Print(); // Error in import
|
||||
// FIXME : don't exit abruptly, but fall back gracefully
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Dictionary with defined ``symbols'' for .pyc file
|
||||
|
@ -88,37 +88,25 @@ PythonPolicyManager::init()
|
|||
|
||||
// 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());
|
||||
// FIXME : Warning!! "import fcfs" shouldn't be here!!
|
||||
std::string s = std::string("import ") + policy_name + "\n"
|
||||
"import ScriptAdapter\n"
|
||||
"_adapter = ScriptAdapter.ScriptAdapter(" +
|
||||
policy_name + "." + policy_name + ")";
|
||||
PyRun_SimpleString(s.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);
|
||||
*/
|
||||
// try code
|
||||
const char* tryExecute =
|
||||
"_adapter.async_configure()\n"
|
||||
"#set ownership to C++ code\n";
|
||||
//"_adapter.thisown = 0\n";
|
||||
PyRun_SimpleString(tryExecute);
|
||||
|
||||
Py_DECREF(pModule);
|
||||
|
||||
pModule = PyImport_AddModule("__main__");
|
||||
pDict = PyModule_GetDict(pModule);
|
||||
// pModule = PyImport_AddModule("__main__");
|
||||
// pDict = PyModule_GetDict(pModule);
|
||||
|
||||
// PyObject *pPyProcess = PyMapping_GetItemString(pDict, "p");
|
||||
// assert(pPyProcess);
|
||||
|
@ -137,7 +125,5 @@ PythonPolicyManager::init()
|
|||
if(!ret) PyErr_Print();
|
||||
else Py_DECREF(ret);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue