- Finish writing ConcreteHistory. That was nasty!

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@700 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-07-03 20:10:51 +00:00
parent cb8e8dabc7
commit e2fc34f16b
3 changed files with 53 additions and 15 deletions

View File

@ -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<DynamicThread*> Threads;
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{
typedef std::vector<DynamicRequest*> Requests;
Requests& reqs = (*it2)->get_dynamic_requests();
for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
typedef std::vector<DynamicSubRequest*> 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<Process>(processes, dyn_proc);
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(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<resource_key_t,Resource*>(index, resource)).first;
notify_change();
return *temp;
}

View File

@ -45,11 +45,9 @@ namespace sgpem
class SG_DLLLOCAL ConcreteHistory : public History
{
public:
typedef const std::pair<resource_key_t, DynamicResource&> 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);

View File

@ -62,7 +62,7 @@ namespace sgpem
typedef int prio_t;
typedef Environment::resource_key_t resource_key_t;
typedef const std::pair<resource_key_t, Resource&> ResourcePair;
typedef const std::pair<resource_key_t, Resource*> 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;