diff --git a/plugins/pyloader/src/python_policy.cc b/plugins/pyloader/src/python_policy.cc index 44d3738..faebe04 100644 --- a/plugins/pyloader/src/python_policy.cc +++ b/plugins/pyloader/src/python_policy.cc @@ -120,6 +120,12 @@ PythonPolicy::get_description() const } +Glib::ustring +PythonPolicy::get_name() const +{ + return _name; +} + bool PythonPolicy::is_pre_emptive() const throw(UserInterruptException) { diff --git a/plugins/pyloader/src/python_policy.hh b/plugins/pyloader/src/python_policy.hh index 83126db..7430c4d 100644 --- a/plugins/pyloader/src/python_policy.hh +++ b/plugins/pyloader/src/python_policy.hh @@ -63,6 +63,8 @@ namespace sgpem */ Glib::ustring get_description() const; + Glib::ustring get_name() const; + /** \returns \c TRUE if the policy is preemptive. \returns \c FALSE if the policy is not preemptive. diff --git a/plugins/pyloader/src/python_policy_manager.cc b/plugins/pyloader/src/python_policy_manager.cc index d661483..424c477 100644 --- a/plugins/pyloader/src/python_policy_manager.cc +++ b/plugins/pyloader/src/python_policy_manager.cc @@ -20,6 +20,7 @@ #include "python_policy_manager.hh" #include "global_preferences.hh" +#include "policies_gatekeeper.hh" #include #include @@ -82,12 +83,12 @@ PythonPolicyManager::get_instance() } -Policy& -PythonPolicyManager::get_policy() -{ - // FIXME : assumes that _python_policy is always != NULL! - return *_python_policy; -} +// Policy& +// PythonPolicyManager::get_policy() +// { +// // FIXME : assumes that _python_policy is always != NULL! +// return *_python_policy; +// } void @@ -158,7 +159,10 @@ PythonPolicyManager::collect_policies() //FIXME remove me when get_policy is dropped if(policy_name == "fcfs") + { _python_policy = pypolicy; + PoliciesGatekeeper::get_instance().activate_policy(&History::get_instance(), pypolicy); + } } } } diff --git a/plugins/pyloader/src/python_policy_manager.hh b/plugins/pyloader/src/python_policy_manager.hh index 0655824..a79905b 100644 --- a/plugins/pyloader/src/python_policy_manager.hh +++ b/plugins/pyloader/src/python_policy_manager.hh @@ -48,8 +48,9 @@ namespace sgpem * 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(); + //Policy& get_policy(); /** \brief Initialize the Python interpreter. * diff --git a/plugins/pyloader/src/testsuite/test-python_loader.cc b/plugins/pyloader/src/testsuite/test-python_loader.cc index a242efa..9c8ba66 100644 --- a/plugins/pyloader/src/testsuite/test-python_loader.cc +++ b/plugins/pyloader/src/testsuite/test-python_loader.cc @@ -44,6 +44,11 @@ public: void test_init(const char* policy_name) { init(); _python_policy = new PythonPolicy(policy_name); + + } + + Policy& get_policy() { + return *_python_policy; } }; diff --git a/src/backend/policies_gatekeeper.cc b/src/backend/policies_gatekeeper.cc index 66b1a0d..1083633 100644 --- a/src/backend/policies_gatekeeper.cc +++ b/src/backend/policies_gatekeeper.cc @@ -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); } diff --git a/src/backend/policies_gatekeeper.hh b/src/backend/policies_gatekeeper.hh index 42d7e82..939aeb6 100644 --- a/src/backend/policies_gatekeeper.hh +++ b/src/backend/policies_gatekeeper.hh @@ -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. diff --git a/src/backend/policy.hh b/src/backend/policy.hh index baa8968..370af2b 100644 --- a/src/backend/policy.hh +++ b/src/backend/policy.hh @@ -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. diff --git a/src/backend/policy_manager.hh b/src/backend/policy_manager.hh index 3c6cce5..3e14410 100644 --- a/src/backend/policy_manager.hh +++ b/src/backend/policy_manager.hh @@ -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. diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index aae85a5..b60ed4e 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -21,6 +21,7 @@ #include "policy.hh" #include "scheduler.hh" #include "policy_manager.hh" +#include "policies_gatekeeper.hh" #include "user_interrupt_exception.hh" #include @@ -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()); } diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 9b12c61..2c8acf9 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -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 ")); + 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 available = manager->get_avail_policies(); + + + obj->_devices[quale]->write_buffer(arguments[1] + "\n"); + + for(vector::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 available = manager->get_avail_policies(); + + for(vector::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)