- Add unified Singleton support
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@643 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
8ca3a61730
commit
383889a203
17 changed files with 193 additions and 136 deletions
|
@ -23,17 +23,6 @@
|
|||
|
||||
using namespace sgpem;
|
||||
|
||||
GlobalPreferences* GlobalPreferences::_instance = 0;
|
||||
|
||||
GlobalPreferences&
|
||||
GlobalPreferences::instance()
|
||||
{
|
||||
if(!_instance)
|
||||
_instance = new GlobalPreferences();
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
|
||||
GlobalPreferences::GlobalPreferences()
|
||||
: _mod_dirs(1, PLUGDIR), _pol_dirs(1, POLDIR)
|
||||
{}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <glibmm/ustring.h>
|
||||
#include <vector>
|
||||
|
||||
#include "singleton.hh"
|
||||
|
||||
namespace sgpem {
|
||||
class GlobalPreferences;
|
||||
}
|
||||
|
@ -33,12 +35,13 @@ namespace sgpem {
|
|||
#include "config.h"
|
||||
|
||||
namespace sgpem {
|
||||
class SG_DLLEXPORT GlobalPreferences {
|
||||
public:
|
||||
class SG_DLLEXPORT GlobalPreferences : public Singleton<GlobalPreferences>
|
||||
{
|
||||
friend class Singleton<GlobalPreferences>;
|
||||
|
||||
public:
|
||||
typedef std::vector<Glib::ustring>::const_iterator dir_iterator;
|
||||
|
||||
static GlobalPreferences& instance();
|
||||
|
||||
dir_iterator modules_dir_begin() const;
|
||||
dir_iterator modules_dir_end() const;
|
||||
|
||||
|
@ -53,7 +56,6 @@ namespace sgpem {
|
|||
GlobalPreferences(const GlobalPreferences&);
|
||||
GlobalPreferences& operator=(const GlobalPreferences&);
|
||||
|
||||
static GlobalPreferences* _instance;
|
||||
std::vector<Glib::ustring> _mod_dirs;
|
||||
std::vector<Glib::ustring> _pol_dirs;
|
||||
};
|
||||
|
|
|
@ -23,25 +23,13 @@ using namespace std;
|
|||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
||||
//History::instance; //static object
|
||||
History* History::_instance = 0;
|
||||
|
||||
/**
|
||||
The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS
|
||||
of the simulation which must begin at instant -1 and live for 1 instant.
|
||||
*/
|
||||
History::History() //private constructor. The parameter is discarded
|
||||
History::History() //private constructor.
|
||||
:_total_time_elapsed(-1)
|
||||
{}
|
||||
|
||||
|
||||
History&
|
||||
History::get_instance()
|
||||
{
|
||||
if(!_instance)
|
||||
_instance = new History();
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "dynamic_schedulable.hh"
|
||||
#include "../templates/smartp.hh"
|
||||
|
||||
#include "singleton.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
|
||||
|
@ -47,8 +49,10 @@ namespace sgpem
|
|||
*/
|
||||
class History;
|
||||
|
||||
class SG_DLLEXPORT History : public ObservedSubject
|
||||
class SG_DLLEXPORT History : public Singleton<History>, public ObservedSubject
|
||||
{
|
||||
friend class Singleton<History>;
|
||||
|
||||
public:
|
||||
/**
|
||||
Gets the \ref Schedulable object running at the specified time.
|
||||
|
@ -82,16 +86,9 @@ namespace sgpem
|
|||
*/
|
||||
virtual void truncate_at(int instant);
|
||||
|
||||
|
||||
/**
|
||||
Gets the only instance of History.
|
||||
\return The Singleton instance of this object.
|
||||
*/
|
||||
static History& get_instance();
|
||||
|
||||
|
||||
protected:
|
||||
History(); //private constructor. The parameter is discarded
|
||||
static History* _instance;
|
||||
History(); //private constructor.
|
||||
|
||||
private:
|
||||
int _total_time_elapsed;
|
||||
|
|
|
@ -34,16 +34,6 @@ using namespace sgpem;
|
|||
typedef vector<PolicyManager*>::iterator ManagerIterator;
|
||||
typedef map<History*, Policy*>::iterator ActiveIterator;
|
||||
|
||||
PoliciesGatekeeper* PoliciesGatekeeper::_instance = NULL;
|
||||
|
||||
PoliciesGatekeeper&
|
||||
PoliciesGatekeeper::get_instance()
|
||||
{
|
||||
if(!_instance)
|
||||
_instance = new PoliciesGatekeeper();
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
vector<PolicyManager*>
|
||||
PoliciesGatekeeper::get_registered() const
|
||||
{
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace sgpem
|
|||
#include <map>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "singleton.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class PoliciesGatekeeper;
|
||||
|
@ -43,15 +45,11 @@ namespace sgpem
|
|||
|
||||
*/
|
||||
|
||||
class SG_DLLEXPORT PoliciesGatekeeper
|
||||
class SG_DLLEXPORT PoliciesGatekeeper : public Singleton<PoliciesGatekeeper>
|
||||
{
|
||||
public:
|
||||
/** \brief Returns the unique instance of this class, conforming to the Singleton pattern.
|
||||
*
|
||||
* \return the unique instance of this class, conforming to the Singleton pattern.
|
||||
*/
|
||||
static PoliciesGatekeeper& get_instance();
|
||||
friend class Singleton<PoliciesGatekeeper>;
|
||||
|
||||
public:
|
||||
std::vector<PolicyManager*> get_registered() const;
|
||||
|
||||
void register_manager(PolicyManager* manager);
|
||||
|
@ -68,7 +66,6 @@ namespace sgpem
|
|||
// Deactivates active policies managed by the specified manager.
|
||||
void deactivate_policies(PolicyManager* manager);
|
||||
|
||||
static PoliciesGatekeeper* _instance;
|
||||
std::vector<PolicyManager*> _registered;
|
||||
std::map<History*, Policy*> _active_policies;
|
||||
};
|
||||
|
|
|
@ -29,9 +29,6 @@ using namespace std;
|
|||
using namespace sgpem;
|
||||
using namespace memory;
|
||||
|
||||
Scheduler*
|
||||
Scheduler::_instance = 0;
|
||||
|
||||
//private constructor. The parameter is discarded
|
||||
Scheduler::Scheduler()
|
||||
: _policy_manager(PolicyManager::get_registered_manager())
|
||||
|
@ -39,14 +36,6 @@ Scheduler::Scheduler()
|
|||
_policy_manager.init();
|
||||
}
|
||||
|
||||
Scheduler&
|
||||
Scheduler::get_instance()
|
||||
{
|
||||
if(!_instance)
|
||||
_instance = new Scheduler();
|
||||
return *_instance;
|
||||
}
|
||||
|
||||
SchedulableQueue*
|
||||
Scheduler::get_ready_queue()
|
||||
{
|
||||
|
|
|
@ -37,11 +37,13 @@ namespace sgpem
|
|||
#include "schedulable_queue.hh"
|
||||
#include "user_interrupt_exception.hh"
|
||||
|
||||
#include "singleton.hh"
|
||||
|
||||
namespace sgpem
|
||||
{
|
||||
class Scheduler;
|
||||
class Scheduler;
|
||||
|
||||
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
|
||||
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
|
||||
|
||||
Class Scheduler manages the schedulable entities which are ready to run,
|
||||
ordering them in a queue; it also checks that the current scheduling policy
|
||||
|
@ -50,61 +52,49 @@ namespace sgpem
|
|||
the DynamicSchedulable objects (for further details about this, check
|
||||
class DynamicSchedulable).
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
class SG_DLLEXPORT Scheduler
|
||||
{
|
||||
public:
|
||||
/** \brief Returns the unique instance of this class, conforming to the Singleton pattern.
|
||||
*
|
||||
* If Scheduler isn't initialized, creates it. Should be called at least once before
|
||||
* starting the Simulation.
|
||||
* \return the unique instance of this class, conforming to the Singleton pattern.
|
||||
*/
|
||||
static Scheduler& get_instance();
|
||||
/**
|
||||
Returns a pointer to the queue containing all the ready
|
||||
schedulable objects (for the policy to sort it).
|
||||
\return a pointer to the queue containing all the ready
|
||||
schedulable objects (for the policy to sort it).
|
||||
*/
|
||||
SchedulableQueue* get_ready_queue();
|
||||
/**
|
||||
Resets the simulation to the initial state.
|
||||
*/
|
||||
void reset_status();
|
||||
/**
|
||||
Generates a new SchedulableQueue representing the status of the processes
|
||||
at the simulation instant next to the current one, and extends the History by
|
||||
one instant with it.
|
||||
*/
|
||||
void step_forward() throw(UserInterruptException);
|
||||
/**
|
||||
Sets the policy that will be used to generate the simulation at the next instant.
|
||||
\param policy the policy that will be used to generate the simulation at the next instant.
|
||||
*/
|
||||
/* DISABLED until we don't have PolicyManager::set_policy()
|
||||
void set_policy(Policy* policy);
|
||||
*/
|
||||
/**
|
||||
Returns the policy that will be used to generate the simulation at the next instant.
|
||||
\return the policy that will be used to generate the simulation at the next instant.
|
||||
*/
|
||||
Policy& get_policy();
|
||||
class SG_DLLEXPORT Scheduler : public Singleton<Scheduler>
|
||||
{
|
||||
friend class Singleton<Scheduler>;
|
||||
public:
|
||||
/**
|
||||
Returns a pointer to the queue containing all the ready
|
||||
schedulable objects (for the policy to sort it).
|
||||
\return a pointer to the queue containing all the ready
|
||||
schedulable objects (for the policy to sort it).
|
||||
*/
|
||||
SchedulableQueue* get_ready_queue();
|
||||
/**
|
||||
Resets the simulation to the initial state.
|
||||
*/
|
||||
void reset_status();
|
||||
/**
|
||||
Generates a new SchedulableQueue representing the status of the processes
|
||||
at the simulation instant next to the current one, and extends the History by
|
||||
one instant with it.
|
||||
*/
|
||||
void step_forward() throw(UserInterruptException);
|
||||
/**
|
||||
Sets the policy that will be used to generate the simulation at the next instant.
|
||||
\param policy the policy that will be used to generate the simulation at the next instant.
|
||||
*/
|
||||
/* DISABLED until we don't have PolicyManager::set_policy()
|
||||
void set_policy(Policy* policy);
|
||||
*/
|
||||
/**
|
||||
Returns the policy that will be used to generate the simulation at the next instant.
|
||||
\return the policy that will be used to generate the simulation at the next instant.
|
||||
*/
|
||||
Policy& get_policy();
|
||||
|
||||
|
||||
private:
|
||||
Scheduler(); //private constructor.
|
||||
static Scheduler* _instance;
|
||||
SchedulableQueue _ready_queue;
|
||||
PolicyManager& _policy_manager;
|
||||
};
|
||||
private:
|
||||
Scheduler(); //private constructor.
|
||||
SchedulableQueue _ready_queue;
|
||||
PolicyManager& _policy_manager;
|
||||
};
|
||||
|
||||
}//~ namespace sgpem
|
||||
|
||||
#endif //SCHEDULER_HH
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue