- Added SETPOLICY and LISTPOLICIES commands to text-based interface

- Fixed a bug preventing registration of managers in PoliciesGatekeeper

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@634 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-06-15 20:07:03 +00:00
parent 9642918dd8
commit 30d070a420
11 changed files with 96 additions and 11 deletions

View file

@ -57,7 +57,7 @@ PoliciesGatekeeper::register_manager(PolicyManager* manager)
ManagerIterator end = _registered.end();
if(find(_registered.begin(), end, manager) != end)
if(find(_registered.begin(), end, manager) == end)
_registered.push_back(manager);
}

View file

@ -43,7 +43,7 @@ namespace sgpem
*/
class PoliciesGatekeeper
class SG_DLLEXPORT PoliciesGatekeeper
{
public:
/** \brief Returns the unique instance of this class, conforming to the Singleton pattern.

View file

@ -85,6 +85,8 @@ namespace sgpem
*/
virtual Glib::ustring get_description() const = 0;
virtual Glib::ustring get_name() const = 0;
/**
Tell if this policy is preemptible.

View file

@ -55,7 +55,7 @@ namespace sgpem
\return A reference to the policy.
FIXME deprecated
*/
virtual Policy& get_policy() = 0;
//virtual Policy& get_policy() = 0;
/**
Init (or reset if yet initialized) the manager.

View file

@ -21,6 +21,7 @@
#include "policy.hh"
#include "scheduler.hh"
#include "policy_manager.hh"
#include "policies_gatekeeper.hh"
#include "user_interrupt_exception.hh"
#include <iostream>
@ -76,7 +77,8 @@ Scheduler::set_policy(Policy* p)
Policy&
Scheduler::get_policy()
{
return _policy_manager.get_policy();
//return _policy_manager.get_policy();
return *PoliciesGatekeeper::get_instance().get_current_policy(&History::get_instance());
}

View file

@ -19,6 +19,9 @@
// 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/history.hh"
#include "text_simulation.hh"
using namespace std;
@ -295,6 +298,66 @@ check:
}
obj->_devices[quale]->write_buffer(obj->get_policy()->get_description());
}
else if(arguments[param] == "SETPOLICY")
{
if(show_help)
{
obj->_devices[quale]->write_buffer(_(
"\n-- SetPolicy COMMAND --\nSelects the current applied policy."
"Syntax: SetPolicy <name>"));
return;
}
//FIXME assuming only one policy manager is present, but who cares, this
//is only temporary code...
PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0];
vector<Policy*> available = manager->get_avail_policies();
obj->_devices[quale]->write_buffer(arguments[1] + "\n");
for(vector<Policy*>::iterator it = available.begin(); it != available.end(); ++it)
{
if((*it)->get_name().casefold() == arguments[1].casefold())
{
obj->stop();
PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), *it);
return;
}
}
obj->_devices[quale]->write_buffer(_(
"\nERROR: no policy found with that name."
"\nType HELP SETPOLICY for the description of the sintax"));
}
else if(arguments[param] == "LISTPOLICIES")
{
if(show_help)
{
obj->_devices[quale]->write_buffer(_(
"\n-- ListPolicies COMMAND --\nShows the name of available policies."));
return;
}
//FIXME assuming only one policy manager is present, but who cares, this
//is only temporary code...
PolicyManager* manager = PoliciesGatekeeper::get_instance().get_registered()[0];
vector<Policy*> available = manager->get_avail_policies();
for(vector<Policy*>::iterator it = available.begin(); it != available.end(); ++it)
{
// Glib::ustring str;
// int_to_string((int)*it, str);
// obj->_devices[quale]->write_buffer(str + "\n");
obj->_devices[quale]->write_buffer("\n" + (*it)->get_name());
}
}
else if (arguments[param] == "GETPOLICYATTRIBUTES")
{
if (show_help)