git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@365 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-21 10:31:01 +00:00
parent 7d58c965ff
commit ea70e2f092
3 changed files with 39 additions and 38 deletions

View File

@ -1,8 +1,6 @@
import sgpem
from Abstract import * from Abstract import *
class Policy(sgpem.Policy): class Policy:
## @var Avoid instantiation of an abstract class ## @var Avoid instantiation of an abstract class
__metaclass__ = Metaclass __metaclass__ = Metaclass
@ -10,3 +8,4 @@ class Policy(sgpem.Policy):
sort_queue = AbstractMethod('sort_queue') sort_queue = AbstractMethod('sort_queue')
is_preemptive = AbstractMethod('is_preemptive') is_preemptive = AbstractMethod('is_preemptive')
is_time_sliced = AbstractMethod('is_time_sliced') is_time_sliced = AbstractMethod('is_time_sliced')

View File

@ -26,8 +26,8 @@ using namespace sgpem;
//static object //static object
PythonPolicyManager* PythonPolicyManager::_instance = NULL; PythonPolicyManager* PythonPolicyManager::_instance = NULL;
PythonPolicyManager::PythonPolicyManager()
PythonPolicyManager::PythonPolicyManager() //private constructor. The parameter is discarded : _initialized(false)
{ {
} }
@ -35,7 +35,7 @@ PythonPolicyManager&
PythonPolicyManager::get_instance() PythonPolicyManager::get_instance()
{ {
if(!_instance) if(!_instance)
_instance = new PythonPolicyManager(); _instance = new PythonPolicyManager();
return *_instance; return *_instance;
} }
@ -49,22 +49,20 @@ PythonPolicyManager::get_policy()
void void
PythonPolicyManager::init() PythonPolicyManager::init()
{ {
static bool initialized = false; if(_initialized)
Py_Finalize();
if(initialized) Py_Initialize();
Py_Finalize(); _initialized = true;
Py_Initialize(); // The following line is ugly, but necessary if we use
initialized = true; // non-standard installation directories. Theoretically,
// it should be up to the user to set correct
// environment variables.
// FIXME: find better way to achieve this.
// The following line is ugly, but necessary if we use PyRun_SimpleString("import sys\n"
// non-standard installation directories. Theoretically, "sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n");
// it should be up to the user to set correct
// environment variables.
// FIXME: find better way to achieve this.
PyRun_SimpleString("import sys\n"
"sys.path[:0] = [ '" MODDIR "', '" PYCDIR "' ]\n");
} }

View File

@ -30,24 +30,28 @@
namespace sgpem namespace sgpem
{ {
//class PolicyManager; //class PolicyManager;
class PythonPolicyManager; class PythonPolicyManager;
class SG_DLLEXPORT PythonPolicyManager : public PolicyManager class SG_DLLEXPORT PythonPolicyManager : public PolicyManager
{ {
public: public:
Policy& get_policy();
void init();
PyObject* get_py_dict();
Policy& get_policy(); static PythonPolicyManager& get_instance();
void init();
PyObject* get_py_dict();
static PythonPolicyManager& get_instance(); private:
PythonPolicyManager();
PythonPolicyManager(const PythonPolicyManager&);
PythonPolicyManager& operator=(const PythonPolicyManager&);
private: static PythonPolicyManager* _instance;
PythonPolicyManager(); //dummy parameter std::auto_ptr<PythonPolicy> _python_policy;
static PythonPolicyManager* _instance;
std::auto_ptr<PythonPolicy> _python_policy; bool _initialized;
}; };
} }