- Rename Policy to CPUPolicy where appropriate

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@811 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-02 21:57:36 +00:00
parent 5b577c5979
commit 43b817aaed
31 changed files with 222 additions and 225 deletions

View file

@ -20,7 +20,7 @@
#include "concrete_simulation.hh"
#include "scheduler.hh"
#include "policies_gatekeeper.hh"
#include "cpu_policies_gatekeeper.hh"
#include <glibmm/timer.h>
#include <cassert>
@ -155,16 +155,16 @@ ConcreteSimulation::get_history()
}
void
ConcreteSimulation::set_policy(Policy* p)
ConcreteSimulation::set_policy(CPUPolicy* p)
{
_policy = p;
if(p != NULL)
PoliciesGatekeeper::get_instance().activate_policy(&_history, p);
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
}
Policy*
CPUPolicy*
ConcreteSimulation::get_policy()
{
return _policy;

View file

@ -49,18 +49,18 @@ namespace sgpem
state get_state() const;
void set_policy(Policy*);
void set_policy(CPUPolicy*);
ConcreteHistory& get_history();
Policy* get_policy();
CPUPolicy* get_policy();
private:
state _state;
bool _mode;
int _timer_interval;
ConcreteHistory _history;
Policy* _policy;
CPUPolicy* _policy;
};
}

View file

@ -1,4 +1,4 @@
// src/backend/policies_gatekeeper.cc - Copyright 2005, 2006, University
// src/backend/cpu_policies_gatekeeper.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -20,9 +20,9 @@
#include "config.h"
#include "policies_gatekeeper.hh"
#include "policy_manager.hh"
#include "policy.hh"
#include "cpu_policies_gatekeeper.hh"
#include "cpu_policy_manager.hh"
#include "cpu_policy.hh"
// Include full template definition only in implementation files:
#include "singleton.tcc"
@ -37,19 +37,19 @@ using std::runtime_error;
using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
template class SG_DLLEXPORT Singleton<PoliciesGatekeeper>;
template class SG_DLLEXPORT Singleton<CPUPoliciesGatekeeper>;
typedef vector<PolicyManager*>::iterator ManagerIterator;
typedef map<History*, Policy*>::iterator ActiveIterator;
typedef vector<CPUPolicyManager*>::iterator ManagerIterator;
typedef map<History*, CPUPolicy*>::iterator ActiveIterator;
vector<PolicyManager*>
PoliciesGatekeeper::get_registered() const
vector<CPUPolicyManager*>
CPUPoliciesGatekeeper::get_registered() const
{
return _registered;
}
void
PoliciesGatekeeper::register_manager(PolicyManager* manager)
CPUPoliciesGatekeeper::register_manager(CPUPolicyManager* manager)
{
assert(manager != NULL);
@ -60,7 +60,7 @@ PoliciesGatekeeper::register_manager(PolicyManager* manager)
}
void
PoliciesGatekeeper::unregister_manager(PolicyManager* manager)
CPUPoliciesGatekeeper::unregister_manager(CPUPolicyManager* manager)
{
assert(manager != NULL);
@ -74,8 +74,8 @@ PoliciesGatekeeper::unregister_manager(PolicyManager* manager)
}
}
Policy*
PoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
CPUPolicy*
CPUPoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
{
assert(history != NULL);
@ -89,7 +89,7 @@ PoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
}
void
PoliciesGatekeeper::activate_policy(History *history, Policy* policy)
CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
{
assert(history != NULL && policy != NULL);
@ -106,18 +106,18 @@ PoliciesGatekeeper::activate_policy(History *history, Policy* policy)
}
}
PoliciesGatekeeper::PoliciesGatekeeper()
CPUPoliciesGatekeeper::CPUPoliciesGatekeeper()
{}
void
PoliciesGatekeeper::deactivate_policies(PolicyManager* manager)
CPUPoliciesGatekeeper::deactivate_policies(CPUPolicyManager* manager)
{
typedef vector<Policy*>::iterator PolicyIterator;
typedef vector<CPUPolicy*>::iterator CPUPolicyIterator;
vector<Policy*> avail_policies = manager->get_avail_policies();
vector<CPUPolicy*> avail_policies = manager->get_avail_policies();
PolicyIterator avail_it = avail_policies.begin();
PolicyIterator avail_end = avail_policies.end();
CPUPolicyIterator avail_it = avail_policies.begin();
CPUPolicyIterator avail_end = avail_policies.end();
for(; avail_it != avail_end; ++avail_it)
{

View file

@ -1,4 +1,4 @@
// src/backend/policies_gatekeeper.hh - Copyright 2005, 2006, University
// src/backend/cpu_policies_gatekeeper.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -18,13 +18,13 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef POLICIES_GATEKEEPER_HH
#define POLICIES_GATEKEEPER_HH 1
#ifndef CPU_POLICIES_GATEKEEPER_HH
#define CPU_POLICIES_GATEKEEPER_HH 1
namespace sgpem
{
class PolicyManager;
class Policy;
class CPUPolicyManager;
class CPUPolicy;
class History;
}
@ -38,41 +38,41 @@ namespace sgpem
namespace sgpem
{
class PoliciesGatekeeper;
class CPUPoliciesGatekeeper;
/** \brief FIXME document me
*/
class SG_DLLEXPORT PoliciesGatekeeper : public Singleton<PoliciesGatekeeper>
class SG_DLLEXPORT CPUPoliciesGatekeeper : public Singleton<CPUPoliciesGatekeeper>
{
friend class Singleton<PoliciesGatekeeper>;
friend class Singleton<CPUPoliciesGatekeeper>;
public:
std::vector<PolicyManager*> get_registered() const;
std::vector<CPUPolicyManager*> get_registered() const;
void register_manager(PolicyManager* manager);
void register_manager(CPUPolicyManager* manager);
void unregister_manager(PolicyManager* manager);
void unregister_manager(CPUPolicyManager* manager);
Policy* get_current_policy(History* history) throw(std::runtime_error);
CPUPolicy* get_current_policy(History* history) throw(std::runtime_error);
void activate_policy(History* history, Policy* policy);
void activate_policy(History* history, CPUPolicy* policy);
private:
PoliciesGatekeeper(); //private constructor.
PoliciesGatekeeper(const PoliciesGatekeeper&);
PoliciesGatekeeper& operator=(const PoliciesGatekeeper&);
CPUPoliciesGatekeeper(); //private constructor.
CPUPoliciesGatekeeper(const CPUPoliciesGatekeeper&);
CPUPoliciesGatekeeper& operator=(const CPUPoliciesGatekeeper&);
// Deactivates active policies managed by the specified manager.
void deactivate_policies(PolicyManager* manager);
void deactivate_policies(CPUPolicyManager* manager);
std::vector<PolicyManager*> _registered;
std::map<History*, Policy*> _active_policies;
std::vector<CPUPolicyManager*> _registered;
std::map<History*, CPUPolicy*> _active_policies;
};
}//~ namespace sgpem
#endif //POLICIES_GATEKEEPER_HH
#endif //~ CPU_POLICIES_GATEKEEPER_HH

View file

@ -1,4 +1,4 @@
// src/backend/policy.cc - Copyright 2005, 2006, University
// src/backend/cpu_policy.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -18,16 +18,16 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "policy.hh"
#include "cpu_policy.hh"
using namespace std;
using namespace sgpem;
Policy::~Policy()
CPUPolicy::~CPUPolicy()
{}
PolicyParameters&
Policy::get_parameters()
CPUPolicy::get_parameters()
{
return _parameters;
}

View file

@ -1,4 +1,4 @@
// src/backend/policy.hh - Copyright 2005, 2006, University
// src/backend/cpu_policy.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -18,8 +18,8 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef POLICY_HH
#define POLICY_HH 1
#ifndef CPU_POLICY_HH
#define CPU_POLICY_HH 1
#include "config.h"
#include "gettext.h"
@ -31,7 +31,7 @@
namespace sgpem
{
class Policy;
class CPUPolicy;
/** \brief
It's a Strategy wich stay for a scheduling algorithm.
@ -39,10 +39,10 @@ namespace sgpem
Its goal is, usually, to keep a list of Schedulable objects
mantained in a ReadyQueue.
*/
class SG_DLLEXPORT Policy
class SG_DLLEXPORT CPUPolicy
{
public:
virtual ~Policy();
virtual ~CPUPolicy();
/**
Initialize the inner components of the policy.
@ -107,5 +107,4 @@ namespace sgpem
}//~ namespace sgpem
#endif
#endif //~ CPU_POLICY_HH

View file

@ -1,4 +1,4 @@
// src/backend/policy_manager.cc - Copyright 2005, 2006, University
// src/backend/cpu_policy_manager.cc - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -19,32 +19,32 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "policy_manager.hh"
#include "policies_gatekeeper.hh"
#include "cpu_policy_manager.hh"
#include "cpu_policies_gatekeeper.hh"
PolicyManager*
PolicyManager::_registered = NULL;
CPUPolicyManager*
CPUPolicyManager::_registered = NULL;
PolicyManager::PolicyManager()
CPUPolicyManager::CPUPolicyManager()
{
//FIXME remove this when get_registered_manager is dropped
_registered = this;
PoliciesGatekeeper::get_instance().register_manager(this);
CPUPoliciesGatekeeper::get_instance().register_manager(this);
}
PolicyManager::~PolicyManager()
CPUPolicyManager::~CPUPolicyManager()
{
// This check is necessary:
//FIXME remove this when get_registered_manager is dropped
if(_registered == this) _registered = NULL;
PoliciesGatekeeper::get_instance().unregister_manager(this);
CPUPoliciesGatekeeper::get_instance().unregister_manager(this);
}
PolicyManager&
PolicyManager::get_registered_manager()
CPUPolicyManager&
CPUPolicyManager::get_registered_manager()
{
return *_registered;
}

View file

@ -1,4 +1,4 @@
// src/backend/policy_manager.hh - Copyright 2005, 2006, University
// src/backend/cpu_policy_manager.hh - Copyright 2005, 2006, University
// of Padova, dept. of Pure and Applied
// Mathematics
//
@ -18,38 +18,38 @@
// along with SGPEMv2; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef POLICY_MANAGER_HH
#define POLICY_MANAGER_HH 1
#ifndef CPU_POLICY_MANAGER_HH
#define CPU_POLICY_MANAGER_HH 1
#include "config.h"
#include "policy.hh"
#include "cpu_policy.hh"
#include <vector>
namespace sgpem
{
class PolicyManager;
class CPUPolicyManager;
/**
PolicyManager is the Abstract Factory for \ref Policy objects.
CPUPolicyManager is the Abstract Factory for \ref CPUPolicy objects.
*/
class SG_DLLEXPORT PolicyManager
class SG_DLLEXPORT CPUPolicyManager
{
public:
/** \brief PolicyManager constructor
/** \brief CPUPolicyManager constructor
*
* Saves ``this'' pointer into the _registered attribute, so it can access
* it when requested. This is done so that concrete subclasses can be defined
* even if they are found in external dynamic modules not known at compile time.
*
* For the moment, just an instance of PolicyManager can be saved. This will
* For the moment, just an instance of CPUPolicyManager can be saved. This will
* be expanded in next milestones.
*/
PolicyManager();
CPUPolicyManager();
virtual ~PolicyManager() = 0;
virtual ~CPUPolicyManager() = 0;
/**
Gets THE policy (the only today) used.
@ -57,7 +57,7 @@ namespace sgpem
\return A reference to the policy.
FIXME deprecated
*/
//virtual Policy& get_policy() = 0;
//virtual CPUPolicy& get_policy() = 0;
/**
Init (or reset if yet initialized) the manager.
@ -65,23 +65,23 @@ namespace sgpem
*/
virtual void init() = 0;
virtual const std::vector<Policy*>& get_avail_policies() = 0;
virtual const std::vector<CPUPolicy*>& get_avail_policies() = 0;
/** \brief Get the registered manager instance
* FIXME deprecated
*
* \return The registered policy manager instance.
*/
static PolicyManager& get_registered_manager();
static CPUPolicyManager& get_registered_manager();
protected:
virtual void collect_policies() = 0;
std::vector<Policy*> _policies;
std::vector<CPUPolicy*> _policies;
private:
/** A pointer to the registered instance */
static PolicyManager* _registered;
static CPUPolicyManager* _registered;
};
} //~ namespace sgpem

View file

@ -20,7 +20,7 @@
#include "concrete_environment.hh"
#include "concrete_history.hh"
#include "policy.hh"
#include "cpu_policy.hh"
#include "scheduler.hh"
#include "user_interrupt_exception.hh"
@ -154,7 +154,7 @@ Scheduler::reset_status()
}
Policy*
CPUPolicy*
Scheduler::get_policy()
{
return _policy;
@ -162,7 +162,7 @@ Scheduler::get_policy()
bool
Scheduler::step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException)
Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException)
{
// This very method should be exclusive: no concurrent behaviour, from when we
// store a readyqueue and policy pointer for the user-policy to retrieve, to when

View file

@ -23,14 +23,13 @@
namespace sgpem
{
class Scheduler;
class PolicyManager;
class Policy;
class CPUPolicy;
}
#include "config.h"
#include "history.hh"
#include "policy.hh"
#include "cpu_policy.hh"
#include "ready_queue.hh"
#include "user_interrupt_exception.hh"
@ -77,19 +76,19 @@ namespace sgpem
\return false If the simulation has ended, true otherwise
*/
bool step_forward(History& history, Policy& cpu_policy) throw(UserInterruptException);
bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException);
/**
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();
CPUPolicy* get_policy();
private:
Scheduler(); //private constructor.
ReadyQueue* _ready_queue;
Policy* _policy;
CPUPolicy* _policy;
Glib::Mutex _step_mutex;
};

View file

@ -24,7 +24,7 @@
namespace sgpem
{
class ConcreteSimulation;
class Policy;
class CPUPolicy;
class History;
}
@ -54,7 +54,7 @@ namespace sgpem
check which schedulng algorithm is currently in use.
\remarks Implements the Observer pattern: observes classes \ref History, \ref Scheduler,
\ref Policy.
\ref CPUPolicy.
\remarks Implements the Controller pattern: ensures Low Coupling between the Frontend and
the Backend layers.
*/
@ -132,12 +132,12 @@ namespace sgpem
/**
\brief Setup the policy to be used by the system.
*/
virtual void set_policy(Policy*) = 0;
virtual void set_policy(CPUPolicy*) = 0;
/**
\return The policy currently in use.
*/
virtual Policy* get_policy() = 0;
virtual CPUPolicy* get_policy() = 0;
virtual History& get_history() = 0;

View file

@ -28,10 +28,6 @@
#include <stdexcept>
#include <glibmm/ustring.h>
// FIXME : mark this file as deprecated.
#warning "This file is obsolete and deprecated."
#warning "It will be removed soon. Please update your code!"
namespace sgpem
{
typedef std::vector<Glib::ustring> Tokens;

View file

@ -23,14 +23,14 @@
#include "backend/global_preferences.hh"
#include "backend/plugin_manager.hh"
#include "backend/policy_manager.hh"
#include "backend/policies_gatekeeper.hh"
#include "backend/cpu_policy_manager.hh"
#include "backend/cpu_policies_gatekeeper.hh"
#include "backend/module.hh"
#include "text_simulation.hh"
#include "io_manager.hh"
#include "gui_builder.hh"
#include "parse_opts.hh"
#
#include <glibmm/optioncontext.h>
#include <gtkmm/main.h>
@ -119,9 +119,9 @@ parse_options(int argc, char** argv)
for(vector<Module*>::iterator it = modules.begin(); it != modules.end(); ++it)
(*it)->set_enabled(true);
vector<PolicyManager*> managers = PoliciesGatekeeper::get_instance().get_registered();
vector<CPUPolicyManager*> managers = CPUPoliciesGatekeeper::get_instance().get_registered();
for(vector<PolicyManager*>::iterator it = managers.begin(); it != managers.end(); ++it)
for(vector<CPUPolicyManager*>::iterator it = managers.begin(); it != managers.end(); ++it)
(*it)->init();

View file

@ -19,8 +19,8 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "backend/string_utils.hh"
#include "backend/policies_gatekeeper.hh"
#include "backend/policy_manager.hh"
#include "backend/cpu_policies_gatekeeper.hh"
#include "backend/cpu_policy_manager.hh"
#include "backend/policy_parameters.hh"
#include "backend/history.hh"
#include "backend/static_process.hh"
@ -382,7 +382,7 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
{
check_arguments_num(arguments, 0);
Policy* policy = Simulation::get_instance().get_policy();
CPUPolicy* policy = Simulation::get_instance().get_policy();
if(policy == NULL)
{
@ -620,17 +620,17 @@ TextSimulation::on_set(const Tokens& arguments)
if(policy < 0)
throw domain_error("");
typedef vector<PolicyManager*> ManagerVec;
typedef vector<Policy*>::iterator PolicyIt;
typedef vector<CPUPolicyManager*> ManagerVec;
typedef vector<CPUPolicy*>::iterator CPUPolicyIt;
PoliciesGatekeeper& gatekeeper = PoliciesGatekeeper::get_instance();
CPUPoliciesGatekeeper& gatekeeper = CPUPoliciesGatekeeper::get_instance();
ManagerVec managers = gatekeeper.get_registered();
for(ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it)
{
vector<Policy*> policies = (*it)->get_avail_policies();
for(PolicyIt it = policies.begin(); it != policies.end(); ++it)
vector<CPUPolicy*> policies = (*it)->get_avail_policies();
for(CPUPolicyIt it = policies.begin(); it != policies.end(); ++it)
{
if(policy == 0)
Simulation::get_instance().set_policy(*it);
@ -828,20 +828,20 @@ TextSimulation::on_show_subrequests(const Tokens& arguments)
void
TextSimulation::on_show_cpu_policies(const Tokens& arguments)
{
typedef vector<PolicyManager*> ManagerVec;
typedef vector<Policy*>::iterator PolicyIt;
typedef vector<CPUPolicyManager*> ManagerVec;
typedef vector<CPUPolicy*>::iterator CPUPolicyIt;
check_arguments_num(arguments, 0);
PoliciesGatekeeper& gatekeeper = PoliciesGatekeeper::get_instance();
CPUPoliciesGatekeeper& gatekeeper = CPUPoliciesGatekeeper::get_instance();
ManagerVec managers = gatekeeper.get_registered();
unsigned int index = 1;
for(ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it)
{
vector<Policy*> policies = (*it)->get_avail_policies();
for(PolicyIt it = policies.begin(); it != policies.end(); ++it)
vector<CPUPolicy*> policies = (*it)->get_avail_policies();
for(CPUPolicyIt it = policies.begin(); it != policies.end(); ++it)
{
ostringstream oss;
oss << index << ". " << (*it)->get_name() << endl;