- Finish implementing async setup for Python policies' access
- Correct method names for the Python policy (design problem?) - Compiles, but can't run it on this machine. I'll test it later (and I expect quite a lot of SIGSEGVs). git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@382 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
882a6acf5e
commit
8f655f2f69
8 changed files with 211 additions and 96 deletions
|
@ -76,50 +76,7 @@ PythonPolicyManager::init()
|
|||
|
||||
// FIXME : Hardcoded policy name
|
||||
char* policy_name = "fcfs";
|
||||
PyObject* pLoadmeStr = PyString_FromString(policy_name);
|
||||
PyObject* pUserPolicyModule = PyImport_Import(pLoadmeStr);
|
||||
Py_DECREF(pLoadmeStr);
|
||||
|
||||
if( !pUserPolicyModule )
|
||||
{
|
||||
PyErr_Print(); // Error in import
|
||||
// FIXME : don't exit abruptly, but fall back gracefully
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// Dictionary with defined ``symbols'' for .pyc file
|
||||
PyObject* pUserPolicyDict = PyModule_GetDict(pUserPolicyModule);
|
||||
assert(pUserPolicyDict);
|
||||
|
||||
// Loads ScriptAdapter module and get its dictionary
|
||||
pLoadmeStr = PyString_FromString("ScriptAdapter");
|
||||
PyObject* pScriptAdapterModule = PyImport_Import(pLoadmeStr);
|
||||
Py_DECREF(pLoadmeStr);
|
||||
assert(pScriptAdapterModule);
|
||||
PyObject* pScriptAdapterDict = PyModule_GetDict(pScriptAdapterModule);
|
||||
assert(pScriptAdapterDict);
|
||||
|
||||
// Now takes the user-defined policy class from pUserPolicyDict
|
||||
PyObject* pPolicyClass = PyDict_GetItemString(pUserPolicyDict, policy_name);
|
||||
assert(pPolicyClass); // FIXME needs stricter checking and exception throwing
|
||||
|
||||
// Creates a new object of type ScriptAdapter :
|
||||
// takes init function from ScriptAdapter class
|
||||
PyObject* pAdapterClass = PyDict_GetItemString(pScriptAdapterDict, "ScriptAdapter");
|
||||
PyObject* pAdapterCtorParam = PyTuple_New(1);
|
||||
Py_INCREF(pPolicyClass); // PyTuple_SetItem steals a reference
|
||||
PyTuple_SetItem(pAdapterCtorParam, 0, pPolicyClass);
|
||||
PyObject* pAdapterObject = PyInstance_New(pAdapterClass, pAdapterCtorParam, NULL);
|
||||
|
||||
// try code
|
||||
PyObject_CallMethod(pAdapterObject, "async_configure", NULL);
|
||||
|
||||
PyThreadState *_save;
|
||||
Py_UNBLOCK_THREADS
|
||||
sleep(5); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
|
||||
|
||||
Py_BLOCK_THREADS
|
||||
|
||||
// And now, who's your daddy, huh?
|
||||
PythonPolicy policy(policy_name);
|
||||
policy.configure();
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue