- 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:
|
||||
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,182 +21,190 @@
|
|||
* 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 {
|
||||
public:
|
||||
virtual ~Policy() = 0;
|
||||
sgpem::PolicyParameters& get_parameters();
|
||||
};
|
||||
class Policy {
|
||||
public:
|
||||
virtual ~Policy() = 0;
|
||||
sgpem::PolicyParameters& get_parameters();
|
||||
};
|
||||
|
||||
// --------------------------------------------
|
||||
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
|
||||
{
|
||||
public:
|
||||
//methods to CREATE PARAMETERS
|
||||
// (rewrapped correctly for SWIG usage)
|
||||
%ignore register_int(const Glib::ustring&, const int&,
|
||||
const int&, const bool&, const int&);
|
||||
%ignore register_float(const Glib::ustring&, const float&,
|
||||
const float&, const bool&, const float&);
|
||||
%ignore register_string(const Glib::ustring&, const bool&,
|
||||
const char*);
|
||||
|
||||
class PolicyParameters
|
||||
{
|
||||
public:
|
||||
//methods to CREATE PARAMETERS
|
||||
// (rewrapped correctly for SWIG usage)
|
||||
%ignore register_int(const Glib::ustring&, const int&,
|
||||
const int&, const bool&, const int&);
|
||||
%ignore register_float(const Glib::ustring&, const float&,
|
||||
const float&, const bool&, const float&);
|
||||
%ignore register_string(const Glib::ustring&, const bool&,
|
||||
const char*);
|
||||
|
||||
%extend {
|
||||
void register_int(const char* name,
|
||||
const int& lower_bound,
|
||||
const int& upper_bound,
|
||||
const bool& required,
|
||||
const int& default_value = 0)
|
||||
void register_int(const char* name,
|
||||
const int& lower_bound,
|
||||
const int& upper_bound,
|
||||
const bool& required,
|
||||
const int& default_value = 0)
|
||||
{
|
||||
self->register_int(name, lower_bound, upper_bound,
|
||||
required, default_value);
|
||||
self->register_int(name, lower_bound, upper_bound,
|
||||
required, default_value);
|
||||
}
|
||||
|
||||
void register_float(const char* name,
|
||||
const float& lower_bound,
|
||||
const float& upper_bound,
|
||||
const bool& required,
|
||||
const float& default_value = 0.0f)
|
||||
|
||||
void register_float(const char* name,
|
||||
const float& lower_bound,
|
||||
const float& upper_bound,
|
||||
const bool& required,
|
||||
const float& default_value = 0.0f)
|
||||
{
|
||||
self->register_float(name, lower_bound, upper_bound,
|
||||
required, default_value);
|
||||
self->register_float(name, lower_bound, upper_bound,
|
||||
required, default_value);
|
||||
}
|
||||
|
||||
void register_string(const char* name,
|
||||
const bool& required,
|
||||
const char* default_value = "")
|
||||
|
||||
void register_string(const char* name,
|
||||
const bool& required,
|
||||
const char* default_value = "")
|
||||
{
|
||||
self->register_string(name, required, default_value);
|
||||
self->register_string(name, required, default_value);
|
||||
}
|
||||
}
|
||||
|
||||
//methods to SET the VALUE of PARAMETERS
|
||||
// (rewrapped correctly for SWIG usage)
|
||||
%ignore set_int(const Glib::ustring&, const int&);
|
||||
%ignore set_float(const Glib::ustring&, const float&);
|
||||
%ignore set_string(const Glib::ustring&, const Glib::ustring&);
|
||||
|
||||
%extend {
|
||||
|
||||
//methods to SET the VALUE of PARAMETERS
|
||||
// (rewrapped correctly for SWIG usage)
|
||||
%ignore set_int(const Glib::ustring&, const int&);
|
||||
%ignore set_float(const Glib::ustring&, const float&);
|
||||
%ignore set_string(const Glib::ustring&, const Glib::ustring&);
|
||||
|
||||
%extend {
|
||||
bool set_int(const char* name, const int& value)
|
||||
{ return self->set_int(name, value); }
|
||||
{ return self->set_int(name, value); }
|
||||
bool set_float(const char* name, const float& value)
|
||||
{ return self->set_float(name, value); }
|
||||
{ return self->set_float(name, value); }
|
||||
bool set_string(const char* name, const char* value)
|
||||
{ return self->set_string(name, value); }
|
||||
}
|
||||
|
||||
//methods to GET the VALUE of PARAMETERS
|
||||
// (rewrapped correctly for SWIG usage)
|
||||
%ignore get_int(const Glib::ustring&) const;
|
||||
%ignore get_float(const Glib::ustring&) const;
|
||||
%ignore get_string(const Glib::ustring&) const;
|
||||
|
||||
%extend {
|
||||
{ return self->set_string(name, value); }
|
||||
}
|
||||
|
||||
//methods to GET the VALUE of PARAMETERS
|
||||
// (rewrapped correctly for SWIG usage)
|
||||
%ignore get_int(const Glib::ustring&) const;
|
||||
%ignore get_float(const Glib::ustring&) const;
|
||||
%ignore get_string(const Glib::ustring&) const;
|
||||
|
||||
%extend {
|
||||
int get_int(const char* name) const
|
||||
{ return self->get_int(name); }
|
||||
{ return self->get_int(name); }
|
||||
float get_float(const char* name) const
|
||||
{ return self->get_float(name); }
|
||||
{ return self->get_float(name); }
|
||||
const char* get_string(const char* name) const
|
||||
{ return self->get_string(name).c_str(); }
|
||||
}
|
||||
|
||||
}; //~ class PolicyParameters
|
||||
|
||||
// --------------------------------------------
|
||||
class Schedulable
|
||||
{
|
||||
public:
|
||||
virtual ~Schedulable() = 0;
|
||||
|
||||
enum state
|
||||
{
|
||||
state_running = 1<<0,
|
||||
state_ready = 1<<1,
|
||||
state_blocked = 1<<2,
|
||||
state_future = 1<<3,
|
||||
state_terminated = 1<<4
|
||||
};
|
||||
{ return self->get_string(name).c_str(); }
|
||||
}
|
||||
|
||||
}; //~ class PolicyParameters
|
||||
|
||||
virtual unsigned int get_arrival_time() const = 0;
|
||||
virtual unsigned int get_elapsed_time() const = 0;
|
||||
virtual int get_base_priority() const = 0;
|
||||
virtual int get_current_priority() const = 0;
|
||||
virtual unsigned int get_total_cpu_time() const = 0;
|
||||
virtual state get_state() const = 0;
|
||||
|
||||
%ignore Schedulable::get_name() const;
|
||||
%extend {
|
||||
const char* get_name() const
|
||||
{ return self->get_name().c_str(); }
|
||||
}
|
||||
}; //~ class Schedulable
|
||||
|
||||
// --------------------------------------------
|
||||
// --------------------------------------------
|
||||
class Schedulable
|
||||
{
|
||||
public:
|
||||
virtual ~Schedulable() = 0;
|
||||
|
||||
enum state
|
||||
{
|
||||
state_running = 1<<0,
|
||||
state_ready = 1<<1,
|
||||
state_blocked = 1<<2,
|
||||
state_future = 1<<3,
|
||||
state_terminated = 1<<4
|
||||
};
|
||||
|
||||
// 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*>;
|
||||
}
|
||||
|
||||
virtual unsigned int get_arrival_time() const = 0;
|
||||
virtual unsigned int get_elapsed_time() const = 0;
|
||||
virtual int get_base_priority() const = 0;
|
||||
virtual int get_current_priority() const = 0;
|
||||
virtual unsigned int get_total_cpu_time() const = 0;
|
||||
virtual state get_state() const = 0;
|
||||
|
||||
%ignore Schedulable::get_name() const;
|
||||
%extend {
|
||||
const char* get_name() const
|
||||
{ return self->get_name().c_str(); }
|
||||
}
|
||||
}; //~ class Schedulable
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
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
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
class ReadyQueue
|
||||
virtual ~Thread() = 0;
|
||||
}; //~ class Thread
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
class ReadyQueue
|
||||
{
|
||||
public:
|
||||
typedef unsigned int position;
|
||||
typedef unsigned int size_t;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
|
@ -212,9 +218,9 @@ namespace sgpem {
|
|||
// ---------------------------------------------
|
||||
class Scheduler {
|
||||
public:
|
||||
sgpem::Policy& get_policy();
|
||||
sgpem::Policy* get_policy();
|
||||
static sgpem::Scheduler& get_instance();
|
||||
sgpem::ReadyQueue* get_ready_queue();
|
||||
sgpem::ReadyQueue* get_ready_queue();
|
||||
private:
|
||||
Scheduler();
|
||||
~Scheduler();
|
||||
|
|
|
@ -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