diff --git a/src/backend/concrete_history.cc b/src/backend/concrete_history.cc index 67c7f2a..5628122 100644 --- a/src/backend/concrete_history.cc +++ b/src/backend/concrete_history.cc @@ -20,8 +20,6 @@ #include "config.h" -#include "concrete_history.hh" - #include "dynamic_process.hh" #include "dynamic_thread.hh" #include "dynamic_resource.hh" @@ -34,6 +32,9 @@ #include "static_request.hh" #include "static_sub_request.hh" +#include "history_observer.hh" +#include "concrete_history.hh" + #include "smartp.tcc" #include @@ -145,32 +146,37 @@ ConcreteHistory::remove(resource_key_t resource_key) delete found->second; resources.erase(found); + // Now search and erase subrequest that had a ref to the + // removed resource + + typedef std::vector Threads; + typedef std::vector Requests; + typedef std::vector SubRequests; + // Listening to "The Thing That Should Not Be"... // all hail the cyclomatic complexity! ConcreteEnvironment::Processes& processes = initial.get_processes(); typedef ConcreteEnvironment::Processes::iterator ProcIt; for(ProcIt it1 = processes.begin(); it1 != processes.end(); it1++) { - typedef std::vector Threads; Threads& threads = dynamic_cast(**it1).get_dynamic_threads(); for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++) { - typedef std::vector Requests; Requests& reqs = (*it2)->get_dynamic_requests(); for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++) { - typedef std::vector SubRequests; SubRequests& subr = (*it3)->get_dynamic_subrequests(); - for(SubRequests::iterator it4 = subr.begin(); it4 != subr.end(); it4++) - { - if((*it4)->get_resource_key() == resource_key) - { - delete *it4; - subr.erase(it4); - } - } + SubRequests::iterator it4 = subr.begin(); + while(it4 != subr.end()) + if((*it4)->get_resource_key() == resource_key) + { + delete *it4; + it4 = subr.erase(it4); + } + else + it4++; } - } + } } //~ end monstrous construct, "The Thing That Should Not Be" // Chtulhu ftaghn. There are worse things in life. Mother-in-laws, // for example. Or hangovers. Or being read poetry by a Vogon. @@ -395,5 +401,7 @@ ConcreteHistory::reset(bool notify) void ConcreteHistory::notify_change() { - // FIXME write code for this method. won't link without this stub + History::RegisteredObservers::iterator it; + for(it =_observers.begin(); it != _observers.end(); it++) + (*it)->update(*this); } diff --git a/src/backend/policies_gatekeeper.cc b/src/backend/policies_gatekeeper.cc index 1f88bc7..183fe87 100644 --- a/src/backend/policies_gatekeeper.cc +++ b/src/backend/policies_gatekeeper.cc @@ -125,14 +125,16 @@ PoliciesGatekeeper::deactivate_policies(PolicyManager* manager) // library utilities? ActiveIterator act_it = _active_policies.begin(); - for(; act_it != _active_policies.end(); ++act_it) - { - if(act_it->second == *avail_it) - { - act_it->second->deactivate(); - _active_policies.erase(act_it); - } - } - } + while(act_it != _active_policies.end()) + { + if(act_it->second == *avail_it) + { + act_it->second->deactivate(); + act_it = _active_policies.erase(act_it); + } + else + act_it++; + } + } //~ for(avail_it) }