From 2ff87baadf27f44e0962bd587797e3164b880eed Mon Sep 17 00:00:00 2001 From: tchernobog Date: Thu, 17 Aug 2006 22:04:25 +0000 Subject: [PATCH] - Give finishing touches to PythonCPUPolicy: implement describe() taking the __doc__ class attribute from the Python policy git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@896 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/builtin-policies/fcfs.py | 2 ++ plugins/pyloader/src/python_cpu_policy.cc | 10 ++++++++-- plugins/pyloader/src/python_cpu_policy.hh | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/pyloader/src/builtin-policies/fcfs.py b/plugins/pyloader/src/builtin-policies/fcfs.py index 4846db6..0e58f0b 100644 --- a/plugins/pyloader/src/builtin-policies/fcfs.py +++ b/plugins/pyloader/src/builtin-policies/fcfs.py @@ -24,6 +24,8 @@ import sys #from sgpem import policy_sorts_processes class fcfs(CPUPolicy) : + """First Come First Served""" + def __init__(self): pass; diff --git a/plugins/pyloader/src/python_cpu_policy.cc b/plugins/pyloader/src/python_cpu_policy.cc index c5ae4b8..e91574c 100644 --- a/plugins/pyloader/src/python_cpu_policy.cc +++ b/plugins/pyloader/src/python_cpu_policy.cc @@ -38,7 +38,7 @@ Glib::StaticRecMutex PythonCPUPolicy::_mtx = GLIBMM_STATIC_REC_MUTEX_INIT; // *strong* exception checking / handling! PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyException) - : _upolicy_dict(NULL), _adapter(NULL), _name(name) + : _upolicy_dict(NULL), _adapter(NULL), _name(name), _description() { PyObject* pLoadmeStr = PyString_FromString(name); PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr); @@ -63,6 +63,12 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio PyObject* pCPUPolicyClass = PyDict_GetItemString(_upolicy_dict, name); assert(pCPUPolicyClass); // FIXME needs stricter checking and exception throwing + // Retrieve a description for the policy using the __doc__ attribute + PyObject* pDescriptionString = PyObject_GetAttrString(pCPUPolicyClass, "__doc__"); + if(pDescriptionString != Py_None) + _description = PyString_AsString(pDescriptionString); + Py_DECREF(pDescriptionString); + // Creates a new object of type ScriptAdapter : // takes init function from ScriptAdapter class PyObject* pAdapterClass = PyDict_GetItemString(pAdapterDict, "ScriptAdapter"); @@ -157,7 +163,7 @@ PythonCPUPolicy::sort_queue() const throw(UserInterruptException, MalformedPolic Glib::ustring PythonCPUPolicy::get_description() const { - return _name; + return _description; } diff --git a/plugins/pyloader/src/python_cpu_policy.hh b/plugins/pyloader/src/python_cpu_policy.hh index d1f0497..7568f57 100644 --- a/plugins/pyloader/src/python_cpu_policy.hh +++ b/plugins/pyloader/src/python_cpu_policy.hh @@ -94,6 +94,7 @@ namespace sgpem PyObject* _adapter; Glib::ustring _name; + Glib::ustring _description; }; }