- Completed policy-related error handling code

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@839 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-10 22:59:00 +00:00
parent 48fc2f5a00
commit 17ca8156d9
7 changed files with 30 additions and 14 deletions

View File

@ -73,7 +73,7 @@ ConcreteSimulation::stop()
} }
void void
ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException) ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException, MalformedPolicyException)
{ {
switch (_state) switch (_state)
{ {
@ -108,7 +108,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
//sleep //sleep
Glib::usleep(_timer_interval*1000); Glib::usleep(_timer_interval*1000);
} }
catch (UserInterruptException e) catch (const CPUPolicyException& e)
{ {
stop(); stop();
throw; throw;
@ -134,7 +134,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
else else
stop(); stop();
} }
catch (UserInterruptException e) catch (const CPUPolicyException& e)
{ {
stop(); stop();
throw; throw;
@ -159,8 +159,7 @@ ConcreteSimulation::set_policy(CPUPolicy* p)
{ {
_policy = p; _policy = p;
if (p != NULL) CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
} }

View File

@ -33,7 +33,7 @@ namespace sgpem
public: public:
ConcreteSimulation(); ConcreteSimulation();
void run() throw(UserInterruptException, NullPolicyException); void run() throw(UserInterruptException, NullPolicyException, MalformedPolicyException);
void pause(); void pause();

View File

@ -91,7 +91,7 @@ CPUPoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
void void
CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
{ {
assert(history != NULL && policy != NULL); assert(history != NULL);
ActiveIterator end = _active_policies.end(); ActiveIterator end = _active_policies.end();
ActiveIterator pos = _active_policies.find(history); ActiveIterator pos = _active_policies.find(history);
@ -99,6 +99,12 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
if (pos != end && pos->second != policy) if (pos != end && pos->second != policy)
_active_policies[history]->deactivate(); _active_policies[history]->deactivate();
if(policy == NULL)
{
_active_policies.erase(pos);
return;
}
if (pos == end || pos->second != policy) if (pos == end || pos->second != policy)
{ {
try try
@ -106,7 +112,7 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
policy->activate(); policy->activate();
_active_policies[history] = policy; _active_policies[history] = policy;
} }
catch(UserInterruptException e) catch(const CPUPolicyException& e)
{ {
//FIXME what to do here??? //FIXME what to do here???
//probably throwing again a MalformedPolicyException //probably throwing again a MalformedPolicyException

View File

@ -23,6 +23,7 @@
#include "cpu_policy.hh" #include "cpu_policy.hh"
#include "scheduler.hh" #include "scheduler.hh"
#include "user_interrupt_exception.hh" #include "user_interrupt_exception.hh"
#include "malformed_policy_exception.hh"
// Do not include full template definition in the header file // Do not include full template definition in the header file
#include "singleton.tcc" #include "singleton.tcc"
@ -497,7 +498,7 @@ Scheduler::get_policy()
bool 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 // 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 // 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 } // end of try
catch (UserInterruptException& e) catch (const CPUPolicyException& e)
{ {
// Reset values that the policy doesn't need anymore // Reset values that the policy doesn't need anymore
_policy = NULL; _policy = NULL;

View File

@ -32,6 +32,7 @@ namespace sgpem
#include "cpu_policy.hh" #include "cpu_policy.hh"
#include "ready_queue.hh" #include "ready_queue.hh"
#include "user_interrupt_exception.hh" #include "user_interrupt_exception.hh"
#include "malformed_policy_exception.hh"
// Do not include full template definition here // Do not include full template definition here
#include "singleton.hh" #include "singleton.hh"
@ -76,7 +77,7 @@ namespace sgpem
\return false If the simulation has ended, true otherwise \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. Returns the policy that will be used to generate the simulation at the next instant.

View File

@ -33,6 +33,7 @@ namespace sgpem
#include "singleton.hh" #include "singleton.hh"
#include "user_interrupt_exception.hh" #include "user_interrupt_exception.hh"
#include "null_policy_exception.hh" #include "null_policy_exception.hh"
#include "malformed_policy_exception.hh"
#include <vector> #include <vector>
namespace sgpem namespace sgpem
@ -77,7 +78,7 @@ namespace sgpem
Advances the simulation by one or more steps, depending on the Advances the simulation by one or more steps, depending on the
actual state and on the value set with set_mode(). 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. \brief Pauses a running simulation.

View File

@ -359,13 +359,21 @@ TextSimulation::on_run(const Tokens& arguments)
{ {
Simulation::get_instance().run(); Simulation::get_instance().run();
} }
catch (UserInterruptException e) catch (const UserInterruptException& e)
{ {
p_stderr(_("ERROR: ")); p_stderr(_("ERROR: "));
p_stderr(e.what()); p_stderr(e.what());
p_stderr(_("\nSimulation is now stopped\n")); 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(_("ERROR: "));
p_stderr(e.what()); p_stderr(e.what());