- 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,28 +21,42 @@
* 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 {
@ -54,12 +66,13 @@ namespace sgpem {
}; };
// -------------------------------------------- // --------------------------------------------
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
@ -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 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
// -------------------------------------------- // --------------------------------------------
@ -195,9 +203,7 @@ namespace sgpem {
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);
@ -212,7 +218,7 @@ 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:

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