From e2fc34f16b5a1295ec39e8694b073722c155c482 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Mon, 3 Jul 2006 20:10:51 +0000 Subject: [PATCH] - Finish writing ConcreteHistory. That was nasty! git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@700 3ecf2c5c-341e-0410-92b4-d18e462d057c --- src/backend/concrete_history.cc | 54 ++++++++++++++++++++++++++++----- src/backend/concrete_history.hh | 10 +++--- src/backend/history.hh | 4 +-- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/backend/concrete_history.cc b/src/backend/concrete_history.cc index 8e20851..1d3a191 100644 --- a/src/backend/concrete_history.cc +++ b/src/backend/concrete_history.cc @@ -137,8 +137,36 @@ ConcreteHistory::remove(resource_key_t resource_key) delete found->second; resources.erase(found); -#warning "write me!" - // FIXME write me : check for subrequests to remove + // 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; it4 != subr.end(); it4++) + { + if((*it4)->get_resource_key() == resource_key) + { + delete *it4; + subr.erase(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. + // Although the above construct really rates between the first tens. notify_change(); } @@ -189,7 +217,7 @@ ConcreteHistory::remove(Request& request) ConcreteEnvironment& initial = *_snapshots.front(); ConcreteEnvironment::Processes& processes = initial.get_processes(); - Process* proc_ref = deep_find(processes, dyn_proc); + Process* proc_ref = deep_find(processes, dyn_proc); DynamicProcess* dyn_proc_ref = dynamic_cast(proc_ref); if(dyn_proc_ref == NULL) return; // not found, just return. @@ -234,7 +262,7 @@ ConcreteHistory::remove(SubRequest& subrequest) } -ConcreteHistory::ResourcePair& +ConcreteHistory::ResourcePair ConcreteHistory::add_resource(const Glib::ustring& name, bool preemptable, size_t places, @@ -242,15 +270,27 @@ ConcreteHistory::add_resource(const Glib::ustring& name, { reset(false); + typedef ConcreteEnvironment::Resources Resources; + // And preemptable and availability?? FIXME! StaticResource* core = new StaticResource(name, places); DynamicResource* resource = new DynamicResource(core); -#warning "write me! insert into map and get iterator in an efficient way." - + ConcreteEnvironment::Resources& resources = _snapshots.front()->get_resources(); + + // alakazam! Black magic at work... get a unique index for this resource + resource_key_t index = 0; + while(resources.find(index) != resources.end()) + index++; + + // Found a hole in the map, fill it like little Hans, + // its finger and the spilling dam. + Resources::iterator temp = resources.insert(pair(index, resource)).first; + notify_change(); - + + return *temp; } diff --git a/src/backend/concrete_history.hh b/src/backend/concrete_history.hh index 0c83a63..9a67c64 100644 --- a/src/backend/concrete_history.hh +++ b/src/backend/concrete_history.hh @@ -45,11 +45,9 @@ namespace sgpem class SG_DLLLOCAL ConcreteHistory : public History { public: - typedef const std::pair DynamicResourcePair; - - ConcreteHistory(); - ConcreteHistory(const ConcreteHistory&); - virtual ~ConcreteHistory(); + ConcreteHistory(); + ConcreteHistory(const ConcreteHistory&); + virtual ~ConcreteHistory(); virtual void append_new_environment(ConcreteEnvironment* environment); virtual size_t get_size(); @@ -63,7 +61,7 @@ namespace sgpem virtual void remove(SubRequest& subrequest); - virtual ResourcePair& add_resource(const Glib::ustring& name, + virtual ResourcePair add_resource(const Glib::ustring& name, bool preemptable = false, size_t places = 1, size_t availability = 0); diff --git a/src/backend/history.hh b/src/backend/history.hh index f157b3b..b36e7c2 100644 --- a/src/backend/history.hh +++ b/src/backend/history.hh @@ -62,7 +62,7 @@ namespace sgpem typedef int prio_t; typedef Environment::resource_key_t resource_key_t; - typedef const std::pair ResourcePair; + typedef const std::pair ResourcePair; virtual ~History() = 0; @@ -77,7 +77,7 @@ namespace sgpem virtual void remove(SubRequest& subrequest) = 0; - virtual ResourcePair& add_resource(const Glib::ustring& name, + virtual ResourcePair add_resource(const Glib::ustring& name, bool preemptable = false, size_t places = 1, size_t availability = 0) = 0;