- 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:
parent
cb8e8dabc7
commit
e2fc34f16b
|
@ -137,8 +137,36 @@ ConcreteHistory::remove(resource_key_t resource_key)
|
||||||
delete found->second;
|
delete found->second;
|
||||||
resources.erase(found);
|
resources.erase(found);
|
||||||
|
|
||||||
#warning "write me!"
|
// Listening to "The Thing That Should Not Be"...
|
||||||
// FIXME write me : check for subrequests to remove
|
// 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();
|
notify_change();
|
||||||
}
|
}
|
||||||
|
@ -234,7 +262,7 @@ ConcreteHistory::remove(SubRequest& subrequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConcreteHistory::ResourcePair&
|
ConcreteHistory::ResourcePair
|
||||||
ConcreteHistory::add_resource(const Glib::ustring& name,
|
ConcreteHistory::add_resource(const Glib::ustring& name,
|
||||||
bool preemptable,
|
bool preemptable,
|
||||||
size_t places,
|
size_t places,
|
||||||
|
@ -242,15 +270,27 @@ ConcreteHistory::add_resource(const Glib::ustring& name,
|
||||||
{
|
{
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
|
typedef ConcreteEnvironment::Resources Resources;
|
||||||
|
|
||||||
// And preemptable and availability?? FIXME!
|
// And preemptable and availability?? FIXME!
|
||||||
|
|
||||||
StaticResource* core = new StaticResource(name, places);
|
StaticResource* core = new StaticResource(name, places);
|
||||||
DynamicResource* resource = new DynamicResource(core);
|
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();
|
notify_change();
|
||||||
|
|
||||||
|
return *temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,6 @@ namespace sgpem
|
||||||
class SG_DLLLOCAL ConcreteHistory : public History
|
class SG_DLLLOCAL ConcreteHistory : public History
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef const std::pair<resource_key_t, DynamicResource&> DynamicResourcePair;
|
|
||||||
|
|
||||||
ConcreteHistory();
|
ConcreteHistory();
|
||||||
ConcreteHistory(const ConcreteHistory&);
|
ConcreteHistory(const ConcreteHistory&);
|
||||||
virtual ~ConcreteHistory();
|
virtual ~ConcreteHistory();
|
||||||
|
@ -63,7 +61,7 @@ namespace sgpem
|
||||||
virtual void remove(SubRequest& subrequest);
|
virtual void remove(SubRequest& subrequest);
|
||||||
|
|
||||||
|
|
||||||
virtual ResourcePair& add_resource(const Glib::ustring& name,
|
virtual ResourcePair add_resource(const Glib::ustring& name,
|
||||||
bool preemptable = false,
|
bool preemptable = false,
|
||||||
size_t places = 1,
|
size_t places = 1,
|
||||||
size_t availability = 0);
|
size_t availability = 0);
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace sgpem
|
||||||
typedef int prio_t;
|
typedef int prio_t;
|
||||||
|
|
||||||
typedef Environment::resource_key_t resource_key_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;
|
virtual ~History() = 0;
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ namespace sgpem
|
||||||
virtual void remove(SubRequest& subrequest) = 0;
|
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,
|
bool preemptable = false,
|
||||||
size_t places = 1,
|
size_t places = 1,
|
||||||
size_t availability = 0) = 0;
|
size_t availability = 0) = 0;
|
||||||
|
|
Loading…
Reference in New Issue