- 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:
tchernobog 2006-07-05 12:46:12 +00:00
parent fee643d3f3
commit 1b018234be
4 changed files with 150 additions and 199 deletions

View File

@ -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 // of Padova, dept. of Pure and Applied
// Mathematics // Mathematics
// //
@ -57,11 +57,6 @@ private:
}; };
//static object
PythonPolicyManager* PythonPolicyManager::_instance = NULL;
PythonPolicyManager::PythonPolicyManager() PythonPolicyManager::PythonPolicyManager()
: _initialized(false) : _initialized(false)
{ {
@ -74,22 +69,6 @@ PythonPolicyManager::~PythonPolicyManager()
for_each(_policies.begin(), _policies.end(), ptr_fun(operator delete)); 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 void
PythonPolicyManager::init() PythonPolicyManager::init()
@ -105,7 +84,6 @@ PythonPolicyManager::init()
// non-standard installation directories. Theoretically, // non-standard installation directories. Theoretically,
// it should be up to the user to set correct // it should be up to the user to set correct
// environment variables. // environment variables.
// FIXME: find better way to achieve this.
GlobalPreferences& prefs = GlobalPreferences::get_instance(); GlobalPreferences& prefs = GlobalPreferences::get_instance();
Glib::ustring importdirs = "import sys\n" Glib::ustring importdirs = "import sys\n"
@ -119,11 +97,10 @@ PythonPolicyManager::init()
// Okay, here we go. // Okay, here we go.
// Black magic at work. // Black magic at work.
collect_policies(); collect_policies();
} }
vector<Policy*> const vector<Policy*>&
PythonPolicyManager::get_avail_policies() PythonPolicyManager::get_avail_policies()
{ {
return _policies; return _policies;
@ -158,13 +135,6 @@ PythonPolicyManager::collect_policies()
PythonPolicy *pypolicy = new PythonPolicy(policy_name.c_str()); PythonPolicy *pypolicy = new PythonPolicy(policy_name.c_str());
_policies.push_back(pypolicy); _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);
}
} }
} }
} }

View File

@ -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 // of Padova, dept. of Pure and Applied
// Mathematics // Mathematics
// //
@ -41,16 +41,8 @@ namespace sgpem
class SG_DLLEXPORT PythonPolicyManager : public PolicyManager class SG_DLLEXPORT PythonPolicyManager : public PolicyManager
{ {
public: public:
/** \brief Returns a reference to the active policy. PythonPolicyManager();
* ~PythonPolicyManager();
* 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();
/** \brief Initialize the Python interpreter. /** \brief Initialize the Python interpreter.
* *
@ -59,33 +51,16 @@ namespace sgpem
*/ */
void init(); void init();
std::vector<Policy*> get_avail_policies(); const 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();
protected: protected:
/** The selected and active PyhonPolicy object. */ /** The selected and active PyhonPolicy object. */
PythonPolicyManager();
~PythonPolicyManager();
void collect_policies(); void collect_policies();
PythonPolicy* _python_policy; private:
private:
PythonPolicyManager(const PythonPolicyManager&); PythonPolicyManager(const PythonPolicyManager&);
PythonPolicyManager& operator=(const PythonPolicyManager&); PythonPolicyManager& operator=(const PythonPolicyManager&);
/** Singleton support. */
static PythonPolicyManager* _instance;
bool _initialized; bool _initialized;
}; };

View File

@ -1,5 +1,3 @@
%include "std_vector.i"
%module sgpem %module sgpem
%{ %{
#include "policy.hh" #include "policy.hh"
@ -23,182 +21,190 @@
* objects different to the one you're declaring. * objects different to the one you're declaring.
*/ */
// ------------- EXCEPTIONS -------------------------------
/* FIXME : look up into Swig manual the management of /* FIXME : look up into Swig manual the management of
* STL exceptions and write wrappers for them. * 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 { // ------------- TEMPLATES -------------------------------
public:
virtual const char* what() const throw(); // Instantiate a Thread* vector for usage with sgpem::Process
private: // std::out_of_range should be automatically defined,
runtime_error(); // 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. // (See last comment): Wrap the above exceptions in the SWIG way.
// ------------- DECLARATIONS -------------------------------
namespace sgpem { namespace sgpem {
class Policy { class Policy {
public: public:
virtual ~Policy() = 0; virtual ~Policy() = 0;
sgpem::PolicyParameters& get_parameters(); sgpem::PolicyParameters& get_parameters();
}; };
// -------------------------------------------- // --------------------------------------------
class PolicyParametersException : public std::runtime_error {
public: // class PolicyParametersException : public std::runtime_error {
PolicyParametersException(char* msg); // public:
%rename (__str__) what; // PolicyParametersException(char* msg);
virtual const char* what(); // %rename (__str__) what;
}; //~ class PolicyParametersException // virtual const char* what();
// }; //~ class PolicyParametersException
// -------------------------------------------- // --------------------------------------------
class PolicyParameters class PolicyParameters
{ {
public: public:
//methods to CREATE PARAMETERS //methods to CREATE PARAMETERS
// (rewrapped correctly for SWIG usage) // (rewrapped correctly for SWIG usage)
%ignore register_int(const Glib::ustring&, const int&, %ignore register_int(const Glib::ustring&, const int&,
const int&, const bool&, const int&); const int&, const bool&, const int&);
%ignore register_float(const Glib::ustring&, const float&, %ignore register_float(const Glib::ustring&, const float&,
const float&, const bool&, const float&); const float&, const bool&, const float&);
%ignore register_string(const Glib::ustring&, const bool&, %ignore register_string(const Glib::ustring&, const bool&,
const char*); const char*);
%extend { %extend {
void register_int(const char* name, void register_int(const char* name,
const int& lower_bound, const int& lower_bound,
const int& upper_bound, const int& upper_bound,
const bool& required, const bool& required,
const int& default_value = 0) const int& default_value = 0)
{ {
self->register_int(name, lower_bound, upper_bound, self->register_int(name, lower_bound, upper_bound,
required, default_value); required, default_value);
} }
void register_float(const char* name, void register_float(const char* name,
const float& lower_bound, const float& lower_bound,
const float& upper_bound, const float& upper_bound,
const bool& required, const bool& required,
const float& default_value = 0.0f) const float& default_value = 0.0f)
{ {
self->register_float(name, lower_bound, upper_bound, self->register_float(name, lower_bound, upper_bound,
required, default_value); required, default_value);
} }
void register_string(const char* name, void register_string(const char* name,
const bool& required, const bool& required,
const char* default_value = "") 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 //methods to SET the VALUE of PARAMETERS
// (rewrapped correctly for SWIG usage) // (rewrapped correctly for SWIG usage)
%ignore set_int(const Glib::ustring&, const int&); %ignore set_int(const Glib::ustring&, const int&);
%ignore set_float(const Glib::ustring&, const float&); %ignore set_float(const Glib::ustring&, const float&);
%ignore set_string(const Glib::ustring&, const Glib::ustring&); %ignore set_string(const Glib::ustring&, const Glib::ustring&);
%extend { %extend {
bool set_int(const char* name, const int& value) 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) 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) bool set_string(const char* name, const char* value)
{ return self->set_string(name, value); } { return self->set_string(name, value); }
} }
//methods to GET the VALUE of PARAMETERS //methods to GET the VALUE of PARAMETERS
// (rewrapped correctly for SWIG usage) // (rewrapped correctly for SWIG usage)
%ignore get_int(const Glib::ustring&) const; %ignore get_int(const Glib::ustring&) const;
%ignore get_float(const Glib::ustring&) const; %ignore get_float(const Glib::ustring&) const;
%ignore get_string(const Glib::ustring&) const; %ignore get_string(const Glib::ustring&) const;
%extend { %extend {
int get_int(const char* name) const int get_int(const char* name) const
{ return self->get_int(name); } { return self->get_int(name); }
float get_float(const char* name) const 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 const char* get_string(const char* name) const
{ return self->get_string(name).c_str(); } { return self->get_string(name).c_str(); }
} }
}; //~ class PolicyParameters }; //~ 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
};
virtual unsigned int get_arrival_time() const = 0; // --------------------------------------------
virtual unsigned int get_elapsed_time() const = 0; class Schedulable
virtual int get_base_priority() const = 0; {
virtual int get_current_priority() const = 0; public:
virtual unsigned int get_total_cpu_time() const = 0; virtual ~Schedulable() = 0;
virtual state get_state() const = 0;
enum state
%ignore Schedulable::get_name() const; {
%extend { state_running = 1<<0,
const char* get_name() const state_ready = 1<<1,
{ return self->get_name().c_str(); } state_blocked = 1<<2,
} state_future = 1<<3,
}; //~ class Schedulable state_terminated = 1<<4
};
// --------------------------------------------
// Instantiate a Thread* vector for usage with Process virtual unsigned int get_arrival_time() const = 0;
// std::out_of_range should be automatically defined, virtual unsigned int get_elapsed_time() const = 0;
// see Swig manual at the STL Vector §. virtual int get_base_priority() const = 0;
namespace std { virtual int get_current_priority() const = 0;
%template(ThreadVector) vector<Thread*>; 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 class Process : public virtual Schedulable
{ {
public: public:
virtual std::vector<Thread*> get_threads(); virtual std::vector<Thread*> get_threads();
} //~ class Process virtual ~Process() = 0;
}; //~ class Process
class Thread : public virtual Schedulable class Thread : public virtual Schedulable
{ {
public: public:
virtual Process& get_process(); virtual Process& get_process();
} //~ class Thread virtual ~Thread() = 0;
}; //~ class Thread
// --------------------------------------------
class ReadyQueue // --------------------------------------------
class ReadyQueue
{ {
public: public:
typedef unsigned int position; typedef unsigned int position;
typedef unsigned int size_t; typedef unsigned int size_t;
size_t size() const; size_t size() const;
sgpem::Thread* get_item_at(position index); sgpem::Thread& get_item_at(position index);
%typename(out) sgpem::Schedulable*;
void swap(position a, position b) throw(std::out_of_range); void swap(position a, position b) throw(std::out_of_range);
private: private:
@ -212,9 +218,9 @@ namespace sgpem {
// --------------------------------------------- // ---------------------------------------------
class Scheduler { class Scheduler {
public: public:
sgpem::Policy& get_policy(); sgpem::Policy* get_policy();
static sgpem::Scheduler& get_instance(); static sgpem::Scheduler& get_instance();
sgpem::ReadyQueue* get_ready_queue(); sgpem::ReadyQueue* get_ready_queue();
private: private:
Scheduler(); Scheduler();
~Scheduler(); ~Scheduler();

View File

@ -63,7 +63,7 @@ namespace sgpem
*/ */
virtual void init() = 0; 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 /** \brief Get the registered manager instance
* FIXME deprecated * FIXME deprecated