- All policy-related errors should now be handled. I hope this is the last time I say this...

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@850 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-08-13 14:20:04 +00:00
parent cb4f0e878d
commit 1be6a9ca58
7 changed files with 102 additions and 36 deletions

View file

@ -90,46 +90,57 @@ CPUPoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
}
void
CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy) throw(UserInterruptException, MalformedPolicyException)
{
assert(history != NULL);
ActiveIterator end = _active_policies.end();
ActiveIterator pos = _active_policies.find(history);
if (pos != end && pos->second != policy)
_active_policies[history]->deactivate();
// deactivate the policy, if necessary
if (pos != end)
{
// nothing to do in this case
if(pos->second == policy)
return;
pos->second->deactivate();
}
// if policy is NULL, simply erase the entry and return, since we are sure the policy is
// not active due to the previous lines
if(policy == NULL)
{
_active_policies.erase(pos);
// this is a no-op if history is not a key used in the map
_active_policies.erase(history);
return;
}
if (pos == end || pos->second != policy)
try
{
try
{
// policy->activate() needs already an active policy, because:
// * it calls the configure() method on the
// insert-your-favourite-scripting-language-here-policy
// * which in turn calls the configure() method in the
// code written by the user
// * which probably uses Simulation to get the _active_ C++ policy,
// so it can get its policy_parameters()
// ... so **DON'T** play Mr. Clever Dick and swap the following two
// lines in an optimization frenzy! Or the user policy WILL fail.
_active_policies[history] = policy;
policy->activate();
}
catch(const CPUPolicyException& e)
{
std::cerr << e.what() << std::endl;
// See the comment above to understand why we do this
// in this way
_active_policies.erase(_active_policies.find(history));
}
// policy->activate() needs already an active policy, because:
// * it calls the configure() method on the
// insert-your-favourite-scripting-language-here-policy
// * which in turn calls the configure() method in the
// code written by the user
// * which probably uses Simulation to get the _active_ C++ policy,
// so it can get its policy_parameters()
// ... so **DON'T** play Mr. Clever Dick and swap the following two
// lines in an optimization frenzy! Or the user policy WILL fail.
_active_policies[history] = policy;
policy->activate();
}
catch(const CPUPolicyException& e)
{
//std::cerr << e.what() << std::endl;
// See the comment above to understand why we do this
// in this way
_active_policies.erase(_active_policies.find(history));
// the caller need to know if it failed
throw;
}
}
CPUPoliciesGatekeeper::CPUPoliciesGatekeeper()