- Make me compile! (this doesn't necessarily mean it runs, though.)
- Fix SWIG interface to correctly manage things - PythonPolicyManager isn't a singleton anymore. Since I did this in a bit of a hurry, check the modifications are right git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@725 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
fee643d3f3
commit
1b018234be
|
@ -1,4 +1,4 @@
|
|||
// src/backend/pyloader/python_policy_manager.cc - Copyright 2005, 2006, University
|
||||
// src/python_policy_manager.cc - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
|
@ -57,11 +57,6 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
//static object
|
||||
PythonPolicyManager* PythonPolicyManager::_instance = NULL;
|
||||
|
||||
|
||||
PythonPolicyManager::PythonPolicyManager()
|
||||
: _initialized(false)
|
||||
{
|
||||
|
@ -74,22 +69,6 @@ PythonPolicyManager::~PythonPolicyManager()
|
|||
for_each(_policies.begin(), _policies.end(), ptr_fun(operator delete));
|
||||
}
|
||||
|
||||
PythonPolicyManager* const
|
||||
PythonPolicyManager::get_instance()
|
||||
{
|
||||
if(!_instance)
|
||||
_instance = new PythonPolicyManager();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
|
||||
// Policy&
|
||||
// PythonPolicyManager::get_policy()
|
||||
// {
|
||||
// // FIXME : assumes that _python_policy is always != NULL!
|
||||
// return *_python_policy;
|
||||
// }
|
||||
|
||||
|
||||
void
|
||||
PythonPolicyManager::init()
|
||||
|
@ -105,7 +84,6 @@ PythonPolicyManager::init()
|
|||
// non-standard installation directories. Theoretically,
|
||||
// it should be up to the user to set correct
|
||||
// environment variables.
|
||||
// FIXME: find better way to achieve this.
|
||||
|
||||
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
||||
Glib::ustring importdirs = "import sys\n"
|
||||
|
@ -119,11 +97,10 @@ PythonPolicyManager::init()
|
|||
|
||||
// Okay, here we go.
|
||||
// Black magic at work.
|
||||
|
||||
collect_policies();
|
||||
}
|
||||
|
||||
vector<Policy*>
|
||||
const vector<Policy*>&
|
||||
PythonPolicyManager::get_avail_policies()
|
||||
{
|
||||
return _policies;
|
||||
|
@ -158,13 +135,6 @@ PythonPolicyManager::collect_policies()
|
|||
PythonPolicy *pypolicy = new PythonPolicy(policy_name.c_str());
|
||||
|
||||
_policies.push_back(pypolicy);
|
||||
|
||||
//FIXME remove me when get_policy is dropped
|
||||
if(policy_name == "fcfs")
|
||||
{
|
||||
_python_policy = pypolicy;
|
||||
PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), pypolicy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// src/backend/pyloader/python_policy_manager.hh - Copyright 2005, 2006, University
|
||||
// src/python_policy_manager.hh - Copyright 2005, 2006, University
|
||||
// of Padova, dept. of Pure and Applied
|
||||
// Mathematics
|
||||
//
|
||||
|
@ -41,16 +41,8 @@ namespace sgpem
|
|||
class SG_DLLEXPORT PythonPolicyManager : public PolicyManager
|
||||
{
|
||||
public:
|
||||
/** \brief Returns a reference to the active policy.
|
||||
*
|
||||
* For the moment, it will sufficit to keep and return
|
||||
* just one Policy for PolicyManager.
|
||||
* In the next milestones it will be possible to manage
|
||||
* more than one, and to retrieve the correct Policy by
|
||||
* passing a unique ID.
|
||||
FIXME depreceated
|
||||
*/
|
||||
//Policy& get_policy();
|
||||
PythonPolicyManager();
|
||||
~PythonPolicyManager();
|
||||
|
||||
/** \brief Initialize the Python interpreter.
|
||||
*
|
||||
|
@ -59,33 +51,16 @@ namespace sgpem
|
|||
*/
|
||||
void init();
|
||||
|
||||
std::vector<Policy*> get_avail_policies();
|
||||
|
||||
/** \brief Returns the singleton instance of
|
||||
* PythonPolicyManager.
|
||||
*
|
||||
* Please note that the first time you'll request
|
||||
* it, it will be still uninitialized.
|
||||
* @see init()
|
||||
*/
|
||||
static PythonPolicyManager* const get_instance();
|
||||
const std::vector<Policy*>& get_avail_policies();
|
||||
|
||||
protected:
|
||||
/** The selected and active PyhonPolicy object. */
|
||||
PythonPolicyManager();
|
||||
~PythonPolicyManager();
|
||||
|
||||
void collect_policies();
|
||||
|
||||
PythonPolicy* _python_policy;
|
||||
|
||||
private:
|
||||
PythonPolicyManager(const PythonPolicyManager&);
|
||||
PythonPolicyManager& operator=(const PythonPolicyManager&);
|
||||
|
||||
/** Singleton support. */
|
||||
static PythonPolicyManager* _instance;
|
||||
|
||||
bool _initialized;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
%include "std_vector.i"
|
||||
|
||||
%module sgpem
|
||||
%{
|
||||
#include "policy.hh"
|
||||
|
@ -23,28 +21,42 @@
|
|||
* objects different to the one you're declaring.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// ------------- EXCEPTIONS -------------------------------
|
||||
|
||||
/* FIXME : look up into Swig manual the management of
|
||||
* STL exceptions and write wrappers for them.
|
||||
*/
|
||||
%include "exception.i"
|
||||
%exception
|
||||
{
|
||||
try {
|
||||
$action
|
||||
} catch (const std::exception& e) {
|
||||
SWIG_exception(SWIG_RuntimeError, e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std {
|
||||
class exception {
|
||||
public:
|
||||
virtual const char* what() const throw();
|
||||
private:
|
||||
exception();
|
||||
};
|
||||
|
||||
class runtime_error : public std::exception {
|
||||
public:
|
||||
virtual const char* what() const throw();
|
||||
private:
|
||||
runtime_error();
|
||||
};
|
||||
// ------------- TEMPLATES -------------------------------
|
||||
|
||||
// Instantiate a Thread* vector for usage with sgpem::Process
|
||||
// std::out_of_range should be automatically defined,
|
||||
// see Swig manual at the STL Vector §.
|
||||
%include "std_vector.i"
|
||||
namespace std
|
||||
{
|
||||
%template(ThreadVector) vector<sgpem::Thread*>;
|
||||
}
|
||||
|
||||
// (See last comment): Wrap the above exceptions in the SWIG way.
|
||||
|
||||
|
||||
|
||||
// ------------- DECLARATIONS -------------------------------
|
||||
|
||||
namespace sgpem {
|
||||
|
||||
class Policy {
|
||||
|
@ -54,12 +66,13 @@ namespace sgpem {
|
|||
};
|
||||
|
||||
// --------------------------------------------
|
||||
class PolicyParametersException : public std::runtime_error {
|
||||
public:
|
||||
PolicyParametersException(char* msg);
|
||||
%rename (__str__) what;
|
||||
virtual const char* what();
|
||||
}; //~ class PolicyParametersException
|
||||
|
||||
// class PolicyParametersException : public std::runtime_error {
|
||||
// public:
|
||||
// PolicyParametersException(char* msg);
|
||||
// %rename (__str__) what;
|
||||
// virtual const char* what();
|
||||
// }; //~ class PolicyParametersException
|
||||
|
||||
// --------------------------------------------
|
||||
class PolicyParameters
|
||||
|
@ -166,24 +179,19 @@ namespace sgpem {
|
|||
|
||||
// --------------------------------------------
|
||||
|
||||
// Instantiate a Thread* vector for usage with Process
|
||||
// std::out_of_range should be automatically defined,
|
||||
// see Swig manual at the STL Vector §.
|
||||
namespace std {
|
||||
%template(ThreadVector) vector<Thread*>;
|
||||
}
|
||||
|
||||
class Process : public virtual Schedulable
|
||||
{
|
||||
public:
|
||||
virtual std::vector<Thread*> get_threads();
|
||||
} //~ class Process
|
||||
virtual ~Process() = 0;
|
||||
}; //~ class Process
|
||||
|
||||
class Thread : public virtual Schedulable
|
||||
{
|
||||
public:
|
||||
virtual Process& get_process();
|
||||
} //~ class Thread
|
||||
virtual ~Thread() = 0;
|
||||
}; //~ class Thread
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
|
@ -195,9 +203,7 @@ namespace sgpem {
|
|||
|
||||
size_t size() const;
|
||||
|
||||
sgpem::Thread* get_item_at(position index);
|
||||
|
||||
%typename(out) sgpem::Schedulable*;
|
||||
sgpem::Thread& get_item_at(position index);
|
||||
|
||||
void swap(position a, position b) throw(std::out_of_range);
|
||||
|
||||
|
@ -212,7 +218,7 @@ namespace sgpem {
|
|||
// ---------------------------------------------
|
||||
class Scheduler {
|
||||
public:
|
||||
sgpem::Policy& get_policy();
|
||||
sgpem::Policy* get_policy();
|
||||
static sgpem::Scheduler& get_instance();
|
||||
sgpem::ReadyQueue* get_ready_queue();
|
||||
private:
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace sgpem
|
|||
*/
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual std::vector<Policy*> get_avail_policies() = 0;
|
||||
virtual const std::vector<Policy*>& get_avail_policies() = 0;
|
||||
|
||||
/** \brief Get the registered manager instance
|
||||
* FIXME deprecated
|
||||
|
|
Loading…
Reference in New Issue