From 17ca8156d9af95f7267a887c2262c8b9d0648a63 Mon Sep 17 00:00:00 2001 From: elvez Date: Thu, 10 Aug 2006 22:59:00 +0000 Subject: [PATCH] - Completed policy-related error handling code git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@839 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/concrete_simulation.cc | 9 ++++----- src/backend/concrete_simulation.hh | 2 +- src/backend/cpu_policies_gatekeeper.cc | 10 ++++++++-- src/backend/scheduler.cc | 5 +++-- src/backend/scheduler.hh | 3 ++- src/backend/simulation.hh | 3 ++- src/text_simulation.cc | 12 ++++++++++-- 7 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/backend/concrete_simulation.cc b/src/backend/concrete_simulation.cc index 9bf053a..05c7592 100644 --- a/src/backend/concrete_simulation.cc +++ b/src/backend/concrete_simulation.cc @@ -73,7 +73,7 @@ ConcreteSimulation::stop() } void -ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException) +ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, MalformedPolicyException) { switch (_state) { @@ -108,7 +108,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException) //sleep Glib::usleep(_timer_interval*1000); } - catch (UserInterruptException e) + catch (const CPUPolicyException& e) { stop(); throw; @@ -134,7 +134,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException) else stop(); } - catch (UserInterruptException e) + catch (const CPUPolicyException& e) { stop(); throw; @@ -159,8 +159,7 @@ ConcreteSimulation::set_policy(CPUPolicy* p) { _policy = p; - if (p != NULL) - CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p); + CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p); } diff --git a/src/backend/concrete_simulation.hh b/src/backend/concrete_simulation.hh index e83e194..f72b27c 100644 --- a/src/backend/concrete_simulation.hh +++ b/src/backend/concrete_simulation.hh @@ -33,7 +33,7 @@ namespace sgpem public: ConcreteSimulation(); - void run() throw(UserInterruptException, NullPolicyException); + void run() throw(UserInterruptException, NullPolicyException, MalformedPolicyException); void pause(); diff --git a/src/backend/cpu_policies_gatekeeper.cc b/src/backend/cpu_policies_gatekeeper.cc index 69a0834..2637cdc 100644 --- a/src/backend/cpu_policies_gatekeeper.cc +++ b/src/backend/cpu_policies_gatekeeper.cc @@ -91,7 +91,7 @@ CPUPoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error) void CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) { - assert(history != NULL && policy != NULL); + assert(history != NULL); ActiveIterator end = _active_policies.end(); ActiveIterator pos = _active_policies.find(history); @@ -99,6 +99,12 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) if (pos != end && pos->second != policy) _active_policies[history]->deactivate(); + if(policy == NULL) + { + _active_policies.erase(pos); + return; + } + if (pos == end || pos->second != policy) { try @@ -106,7 +112,7 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) policy->activate(); _active_policies[history] = policy; } - catch(UserInterruptException e) + catch(const CPUPolicyException& e) { //FIXME what to do here??? //probably throwing again a MalformedPolicyException diff --git a/src/backend/scheduler.cc b/src/backend/scheduler.cc index 483f09a..6da165f 100644 --- a/src/backend/scheduler.cc +++ b/src/backend/scheduler.cc @@ -23,6 +23,7 @@ #include "cpu_policy.hh" #include "scheduler.hh" #include "user_interrupt_exception.hh" +#include "malformed_policy_exception.hh" // Do not include full template definition in the header file #include "singleton.tcc" @@ -497,7 +498,7 @@ Scheduler::get_policy() bool -Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException) +Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException, MalformedPolicyException) { // 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 @@ -725,7 +726,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter } // end of try - catch (UserInterruptException& e) + catch (const CPUPolicyException& e) { // Reset values that the policy doesn't need anymore _policy = NULL; diff --git a/src/backend/scheduler.hh b/src/backend/scheduler.hh index 6d44d83..eb9fa3e 100644 --- a/src/backend/scheduler.hh +++ b/src/backend/scheduler.hh @@ -32,6 +32,7 @@ namespace sgpem #include "cpu_policy.hh" #include "ready_queue.hh" #include "user_interrupt_exception.hh" +#include "malformed_policy_exception.hh" // Do not include full template definition here #include "singleton.hh" @@ -76,7 +77,7 @@ namespace sgpem \return false If the simulation has ended, true otherwise */ - bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException); + bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException, MalformedPolicyException); /** Returns the policy that will be used to generate the simulation at the next instant. diff --git a/src/backend/simulation.hh b/src/backend/simulation.hh index 3f522e5..e7c2813 100644 --- a/src/backend/simulation.hh +++ b/src/backend/simulation.hh @@ -33,6 +33,7 @@ namespace sgpem #include "singleton.hh" #include "user_interrupt_exception.hh" #include "null_policy_exception.hh" +#include "malformed_policy_exception.hh" #include namespace sgpem @@ -77,7 +78,7 @@ namespace sgpem Advances the simulation by one or more steps, depending on the actual state and on the value set with set_mode(). */ - virtual void run() throw(UserInterruptException, NullPolicyException) = 0; + virtual void run() throw(UserInterruptException, NullPolicyException, MalformedPolicyException) = 0; /** \brief Pauses a running simulation. diff --git a/src/text_simulation.cc b/src/text_simulation.cc index 6cbf157..8dd6f55 100644 --- a/src/text_simulation.cc +++ b/src/text_simulation.cc @@ -359,13 +359,21 @@ TextSimulation::on_run(const Tokens& arguments) { Simulation::get_instance().run(); } - catch (UserInterruptException e) + catch (const UserInterruptException& e) { p_stderr(_("ERROR: ")); p_stderr(e.what()); p_stderr(_("\nSimulation is now stopped\n")); } - catch (NullPolicyException e) + catch (const MalformedPolicyException& e) + { + p_stderr(_("ERROR: ")); + p_stderr(e.what()); + p_stderr(_("\nSimulation is now stopped, and " + "the current policy will be deactivated\n")); + Simulation::get_instance().set_policy(NULL); + } + catch (const NullPolicyException& e) { p_stderr(_("ERROR: ")); p_stderr(e.what());