From 0dd711657f2fbf6bbe6fb2125e86c509e4c34c24 Mon Sep 17 00:00:00 2001 From: elvez Date: Fri, 21 Jul 2006 13:10:31 +0000 Subject: [PATCH] - Added the "set cpu-policy" command. It`s still not useful until we initialize the pyloader plugin... git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@789 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/concrete_simulation.cc | 2 +- src/backend/concrete_simulation.hh | 2 +- src/backend/simulation.hh | 2 +- src/text_simulation.cc | 51 +++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/backend/concrete_simulation.cc b/src/backend/concrete_simulation.cc index 54a4411..2b1c876 100644 --- a/src/backend/concrete_simulation.cc +++ b/src/backend/concrete_simulation.cc @@ -37,7 +37,7 @@ ConcreteSimulation::ConcreteSimulation() : {} void -ConcreteSimulation::set_timer(const int& t) +ConcreteSimulation::set_timer(unsigned int t) { _timer_interval = t; } diff --git a/src/backend/concrete_simulation.hh b/src/backend/concrete_simulation.hh index bd47433..fe56b92 100644 --- a/src/backend/concrete_simulation.hh +++ b/src/backend/concrete_simulation.hh @@ -39,7 +39,7 @@ namespace sgpem void stop(); - void set_timer(const int&); + void set_timer(const unsigned int); int get_timer() const; diff --git a/src/backend/simulation.hh b/src/backend/simulation.hh index 3b2c571..0a9eb6e 100644 --- a/src/backend/simulation.hh +++ b/src/backend/simulation.hh @@ -102,7 +102,7 @@ namespace sgpem interpreted when the simulation advancement mode is continue. The input value is in milliseconds, and it must be in range [0, 10000]. */ - virtual void set_timer(const int&) = 0; + virtual void set_timer(unsigned int) = 0; /** \see set_timer() diff --git a/src/text_simulation.cc b/src/text_simulation.cc index d19b2aa..dff82f6 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -677,20 +677,63 @@ TextSimulation::on_set(const Tokens& arguments) else value = arguments[1]; - if(attr == "SIMULATION_TICK") + if(attr == "SIMULATION-TICK") { try { - Simulation::get_instance().set_timer(string_to(value)); + int timer = string_to(value); + + if(timer < 0) + throw domain_error(""); + + Simulation::get_instance().set_timer(timer); } catch(domain_error e) { - p_stderr(_("\nERROR: you must provide a valid integer value\n")); + p_stderr(_("\nERROR: you must provide a valid unsigned integer value\n")); } } + else if(attr == "CPU-POLICY") + { + int policy; + + try + { + policy = string_to(value) - 1; + + if(policy < 0) + throw domain_error(""); + + typedef vector ManagerVec; + typedef vector::iterator PolicyIt; + + PoliciesGatekeeper& gatekeeper = PoliciesGatekeeper::get_instance(); + + ManagerVec managers = gatekeeper.get_registered(); + + for(ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it) + { + vector policies = (*it)->get_avail_policies(); + for(PolicyIt it = policies.begin(); it != policies.end(); ++it) + { + if(policy == 0) + Simulation::get_instance().set_policy(*it); + + --policy; + } + } + + if(policy >= 0) + throw domain_error(""); + } + catch(domain_error e) + { + p_stderr(_("\nERROR: invalid unsigned integer or not a valid policy index\n")); + } + } else - p_stderr(_("\nERROR: invalid attribute. Accepted are: simulation_tick\n")); + p_stderr(_("\nERROR: invalid attribute. Accepted are: simulation-tick, cpu-policy\n")); } void