- Give code a round of indentation. Thank astyle, not me.

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@837 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-09 14:38:45 +00:00
parent aaf8e068d3
commit d3c7b46853
108 changed files with 3196 additions and 3180 deletions

View file

@ -42,82 +42,82 @@ ConcreteEnvironment::ConcreteEnvironment()
ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
Environment(ce), _resources(ce._resources), _processes(), _sched_queue(), _sreq_queues(ce._sreq_queues)
Environment(ce), _resources(ce._resources), _processes(), _sched_queue(), _sreq_queues(ce._sreq_queues)
{
// The ReadyQueue won't be copied. Pointers to objects contained into
// the ready queue _will_ have changed in the new one. The ready queue
// needs to be reset: it is Scheduler that builds it again from time to time.
// The ReadyQueue won't be copied. Pointers to objects contained into
// the ready queue _will_ have changed in the new one. The ready queue
// needs to be reset: it is Scheduler that builds it again from time to time.
// Update resource pointers in a way you won't like :-)
{
for(Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
it->second = new DynamicResource(dynamic_cast<const DynamicResource&>(*it->second));
}
// Update resource pointers in a way you won't like :-)
{
for (Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
it->second = new DynamicResource(dynamic_cast<const DynamicResource&>(*it->second));
}
// DynamicProcess object need to be copied.
// The deep copy is guaranteed by the DynamicProcess copy constructor
{
const Processes& ce_proc = ce._processes;
insert_iterator<Processes> dest(_processes, _processes.begin());
for(Processes::const_iterator orig = ce_proc.begin(); orig != ce_proc.end(); orig++)
*dest++ = new DynamicProcess(dynamic_cast<const DynamicProcess&>(**orig));
}
{
const Processes& ce_proc = ce._processes;
insert_iterator<Processes> dest(_processes, _processes.begin());
for (Processes::const_iterator orig = ce_proc.begin(); orig != ce_proc.end(); orig++)
*dest++ = new DynamicProcess(dynamic_cast<const DynamicProcess&>(**orig));
}
// Update the subrequest queues.
// Update the subrequest queues.
// for each subrequest
typedef Processes::const_iterator it1_t;
// for each subrequest
typedef Processes::const_iterator it1_t;
typedef std::vector<Thread*> v2_t;
typedef v2_t::const_iterator it2_t;
typedef std::vector<Thread*> v2_t;
typedef v2_t::const_iterator it2_t;
typedef std::vector<Request*> v3_t;
typedef v3_t::const_iterator it3_t;
typedef std::vector<Request*> v3_t;
typedef v3_t::const_iterator it3_t;
typedef std::vector<SubRequest*> v4_t;
typedef v4_t::const_iterator it4_t;
typedef std::vector<SubRequest*> v4_t;
typedef v4_t::const_iterator it4_t;
typedef SubRequestQueue::iterator it5_t;
typedef SubRequestQueue::iterator it5_t;
for (it1_t it1 = _processes.begin(); it1 != _processes.end(); it1++)
{
const v2_t& threads = (*it1)->get_threads();
for (it2_t it2 = threads.begin(); it2 != threads.end(); it2++)
{
const v3_t& reqs = (*it2)->get_requests();
for (it3_t it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
// an optimization here: there is no reason in iterating through
// future or exausted requests. (Do you know why?)
const v4_t& subr = (*it3)->get_subrequests();
for (it4_t it4 = subr.begin(); it4 != subr.end(); it4++)
{
SubRequest::state curr_state = (*it4)->get_state();
if (curr_state != Request::state_future && curr_state != Request::state_exhausted)
{
// the subrequest is the following queue:
SubRequestQueue & queue = get_request_queue((*it4)->get_resource_key());
// we must replace the old pointer:
bool found = false;
for (it5_t it5 = queue.begin(); !found && it5 != queue.end(); it5++)
{
DynamicSubRequest& _old = dynamic_cast<DynamicSubRequest&>(**it5);
DynamicSubRequest& _new = dynamic_cast<DynamicSubRequest&>(**it4);
if (&_old.get_core() == &_new.get_core())
{
found = true;
*it5 = *it4;
}
}
}
}
}
}
}
for(it1_t it1 = _processes.begin(); it1 != _processes.end(); it1++)
{
const v2_t& threads = (*it1)->get_threads();
for(it2_t it2 = threads.begin(); it2 != threads.end(); it2++)
{
const v3_t& reqs = (*it2)->get_requests();
for(it3_t it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
// an optimization here: there is no reason in iterating through
// future or exausted requests. (Do you know why?)
const v4_t& subr = (*it3)->get_subrequests();
for(it4_t it4 = subr.begin(); it4 != subr.end(); it4++)
{
SubRequest::state curr_state = (*it4)->get_state();
if(curr_state != Request::state_future && curr_state != Request::state_exhausted)
{
// the subrequest is the following queue:
SubRequestQueue & queue = get_request_queue((*it4)->get_resource_key());
// we must replace the old pointer:
bool found = false;
for(it5_t it5 = queue.begin(); !found && it5 != queue.end(); it5++)
{
DynamicSubRequest& _old = dynamic_cast<DynamicSubRequest&>(**it5);
DynamicSubRequest& _new = dynamic_cast<DynamicSubRequest&>(**it4);
if (&_old.get_core() == &_new.get_core())
{
found = true;
*it5 = *it4;
}
}
}
}
}
}
}
}
@ -195,14 +195,14 @@ ConcreteEnvironment::get_sorted_queue()
ConcreteEnvironment::~ConcreteEnvironment()
{
// This call will invoke the DynamicProcess virtual destructor
// Which will delete on cascade all DynamicThreads and so on.
for_each(_processes.begin(), _processes.end(),
memory::deletor<Process>());
// This call will invoke the DynamicProcess virtual destructor
// Which will delete on cascade all DynamicThreads and so on.
for_each(_processes.begin(), _processes.end(),
memory::deletor<Process>());
// We do the same with Resources.
for(Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
delete it->second;
// We do the same with Resources.
for (Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
delete it->second;
// After this, the destructor of _sched_queue is invoked (only invalid pointers)
// After that, the destructor of _processes is invoked (only invalid pointers)

View file

@ -62,12 +62,12 @@ namespace sgpem
/// considered instant.
///
/// The Process objects returned are actually DynamicProcess
/// objects. A downcast to DynamicProcess is guaranteed to be
/// objects. A downcast to DynamicProcess is guaranteed to be
/// always safe.
///
/// \return a constant set of snapshots of processes
virtual const Processes&
get_processes() const;
get_processes() const;
@ -76,7 +76,7 @@ namespace sgpem
/// \return a set of snapshots of processes
/// \see get_processes()
virtual Processes&
get_processes();
get_processes();
@ -93,13 +93,13 @@ namespace sgpem
/// class which returns the Resource object indexed.
///
/// The Resource objects returned are actually DynamicResource
/// objects. A downcast to DynamicResource is guaranteed to be
/// objects. A downcast to DynamicResource is guaranteed to be
/// always safe.
///
/// \return a indexed constant set of snapshot of resources.
/// \see DynamicSybrequest::get_resource()
virtual const Resources&
get_resources() const;
get_resources() const;
@ -108,7 +108,7 @@ namespace sgpem
/// \return an indexed set of snapshots of resources
/// \see get_resources()
virtual Resources&
get_resources();
get_resources();
@ -118,16 +118,16 @@ namespace sgpem
/// are waiting for getting control of a limited-access resource.
///
/// The Request objects returned are actually DynamicRequest
/// objects. A downcast to DynamicRequest is guaranteed to be
/// objects. A downcast to DynamicRequest is guaranteed to be
/// always safe.
///
/// \param resource The resource the requests are for
/// \return The current ready requests queue.
virtual const SubRequestQueue&
get_request_queue(resource_key_t resource_key) const;
get_request_queue(resource_key_t resource_key) const;
SubRequestQueue&
get_request_queue(resource_key_t resource_key);
get_request_queue(resource_key_t resource_key);
@ -150,7 +150,7 @@ namespace sgpem
///
/// \return the current ready queue (constant).
virtual const ReadyQueue&
get_sorted_queue() const;
get_sorted_queue() const;
@ -159,14 +159,14 @@ namespace sgpem
/// \return the current ready queue.
/// \see get_sorted_queue()
virtual ReadyQueue&
get_sorted_queue();
get_sorted_queue();
/// \brief The standard virtual destructor.
/// The standard virtual destructor.
virtual
~ConcreteEnvironment();
~ConcreteEnvironment();
private:
@ -175,11 +175,11 @@ namespace sgpem
/// Actually contains only DynamicResource objects.
// resources come before processes because of
// destruction order. See destructor implementation
Resources _resources;
Resources _resources;
/// \brief The container of all Process objecs.
/// Actually contains only DynamicProcess objects.
Processes _processes;
Processes _processes;
/// \brief The queue of the ready schedulables
/// Does not contain the running process.
@ -187,7 +187,8 @@ namespace sgpem
SubRequestQueues _sreq_queues;
}; //~ class ConcreteEnvironment
}
; //~ class ConcreteEnvironment
} //~ namespace sgpem

View file

@ -54,372 +54,372 @@ using memory::deletor;
template<typename T>
static bool deep_remove(std::vector<T*>& v, const T& obj)
{
typedef typename std::vector<T*> Vector;
for(typename Vector::iterator it = v.begin(); it != v.end(); it++)
if(**it == obj)
{
delete *it;
v.erase(it);
return true;
}
return false;
typedef typename std::vector<T*> Vector;
for (typename Vector::iterator it = v.begin(); it != v.end(); it++)
if (**it == obj)
{
delete *it;
v.erase(it);
return true;
}
return false;
}
template<typename T>
static T* deep_find(const std::vector<T*>& v, const T& obj)
{
typedef typename std::vector<T*> Vector;
for(typename Vector::const_iterator it = v.begin(); it != v.end(); it++)
if(**it == obj)
{
return *it;
}
return NULL;
typedef typename std::vector<T*> Vector;
for (typename Vector::const_iterator it = v.begin(); it != v.end(); it++)
if (**it == obj)
{
return *it;
}
return NULL;
}
// -----------------
ConcreteHistory::ConcreteHistory()
: History(), _snapshots()
: History(), _snapshots()
{
_snapshots.push_back(new ConcreteEnvironment());
_snapshots.push_back(new ConcreteEnvironment());
}
ConcreteHistory::~ConcreteHistory()
{
for_each(_snapshots.begin(), _snapshots.end(),
deletor<ConcreteEnvironment>());
for_each(_snapshots.begin(), _snapshots.end(),
deletor<ConcreteEnvironment>());
}
ConcreteHistory::ConcreteHistory(const ConcreteHistory& h) :
History(h)
History(h)
{
typedef Snapshots::const_iterator SnapIt;
for(SnapIt it = h._snapshots.begin(); it != h._snapshots.end(); ++it)
for (SnapIt it = h._snapshots.begin(); it != h._snapshots.end(); ++it)
_snapshots.push_back(new ConcreteEnvironment(*(*it)));
}
void
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
{
_snapshots.push_back(environment);
notify_change();
_snapshots.push_back(environment);
notify_change();
}
ConcreteHistory::size_t
ConcreteHistory::get_size() const
{
return _snapshots.size();
return _snapshots.size();
}
const ConcreteEnvironment&
const ConcreteEnvironment&
ConcreteHistory::get_last_environment() const
{
// Should always be true:
assert(_snapshots.size() > 0);
return *_snapshots.back();
// Should always be true:
assert(_snapshots.size() > 0);
return *_snapshots.back();
}
const ConcreteEnvironment&
ConcreteHistory::get_environment_at(position index) const
throw(std::out_of_range)
const ConcreteEnvironment&
ConcreteHistory::get_environment_at(position index) const
throw(std::out_of_range)
{
return *_snapshots.at(index);
return *_snapshots.at(index);
}
void
void
ConcreteHistory::remove(resource_key_t resource_key)
{
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Resources& resources = initial.get_resources();
ConcreteEnvironment::Resources::iterator found = resources.find(resource_key);
if(found == resources.end())
return;
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Resources& resources = initial.get_resources();
ConcreteEnvironment::Resources::iterator found = resources.find(resource_key);
if (found == resources.end())
return;
reset(false);
reset(false);
delete found->second;
resources.erase(found);
delete found->second;
resources.erase(found);
// Delete the queue associated with the resource.
ConcreteEnvironment::SubRequestQueues& srq = initial.get_subrequest_queues();
ConcreteEnvironment::SubRequestQueues::iterator qfound = srq.find(resource_key);
// There is always one!
assert(qfound != srq.end());
srq.erase(qfound);
// Delete the queue associated with the resource.
ConcreteEnvironment::SubRequestQueues& srq = initial.get_subrequest_queues();
ConcreteEnvironment::SubRequestQueues::iterator qfound = srq.find(resource_key);
// There is always one!
assert(qfound != srq.end());
srq.erase(qfound);
// Now search and erase subrequest that had a ref to the
// removed resource
// Now search and erase subrequest that had a ref to the
// removed resource
typedef std::vector<DynamicThread*> Threads;
typedef std::vector<DynamicRequest*> Requests;
typedef std::vector<DynamicSubRequest*> SubRequests;
typedef std::vector<DynamicThread*> Threads;
typedef std::vector<DynamicRequest*> Requests;
typedef std::vector<DynamicSubRequest*> 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++)
{
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{
Requests& reqs = (*it2)->get_dynamic_requests();
for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
SubRequests& subr = (*it3)->get_dynamic_subrequests();
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.
// Although the above construct really rates between the first tens.
// 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++)
{
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{
Requests& reqs = (*it2)->get_dynamic_requests();
for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{
SubRequests& subr = (*it3)->get_dynamic_subrequests();
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.
// Although the above construct really rates between the first tens.
notify_change();
notify_change();
}
void
ConcreteHistory::remove(Process& process)
{
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
bool found = deep_remove<Process>(processes, process);
if(found)
reset(true);
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
bool found = deep_remove<Process>(processes, process);
if (found)
reset(true);
}
void
void
ConcreteHistory::remove(Thread& thread)
{
DynamicThread& dyn_thr = dynamic_cast<DynamicThread&>(thread);
DynamicThread& dyn_thr = dynamic_cast<DynamicThread&>(thread);
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
Process* found = deep_find<Process>(processes, dyn_thr.get_process());
if(found == NULL)
return; // not found, just return.
DynamicProcess& dynamic_found = dynamic_cast<DynamicProcess&>(*found);
bool removed = deep_remove<DynamicThread>(dynamic_found.get_dynamic_threads(), dyn_thr);
if (found == NULL)
return; // not found, just return.
if(removed)
reset(true);
DynamicProcess& dynamic_found = dynamic_cast<DynamicProcess&>(*found);
bool removed = deep_remove<DynamicThread>(dynamic_found.get_dynamic_threads(), dyn_thr);
if (removed)
reset(true);
}
void
ConcreteHistory::remove(Request& request)
{
DynamicRequest& dyn_req = dynamic_cast<DynamicRequest&>(request);
DynamicThread& dyn_thr = dyn_req.get_thread();
DynamicProcess& dyn_proc = dyn_thr.get_process();
DynamicRequest& dyn_req = dynamic_cast<DynamicRequest&>(request);
DynamicThread& dyn_thr = dyn_req.get_thread();
DynamicProcess& dyn_proc = dyn_thr.get_process();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
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.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
if(thr_ref == NULL)
return; // not found, just return.
bool removed = deep_remove<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
if(removed)
reset(true);
}
void
ConcreteHistory::remove(SubRequest& subrequest)
{
// this function makes one relevant assumption:
// the initial environment does contain empty request queues only.
DynamicSubRequest& dyn_sub = dynamic_cast<DynamicSubRequest&>(subrequest);
DynamicRequest& dyn_req = dyn_sub.get_request();
DynamicThread& dyn_thr = dyn_req.get_thread();
DynamicProcess& dyn_proc = dyn_thr.get_process();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
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.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
if(thr_ref == NULL)
return; // not found, just return.
DynamicRequest* req_ref = deep_find<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
if(req_ref == NULL)
return; // not found, just return.
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
if (dyn_proc_ref == NULL)
return; // not found, just return.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
if (thr_ref == NULL)
return; // not found, just return.
bool removed = deep_remove<DynamicSubRequest>(req_ref->get_dynamic_subrequests(), dyn_sub);
bool removed = deep_remove<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
if(removed)
reset(true);
if (removed)
reset(true);
}
ConcreteHistory::ResourcePair
void
ConcreteHistory::remove(SubRequest& subrequest)
{
// this function makes one relevant assumption:
// the initial environment does contain empty request queues only.
DynamicSubRequest& dyn_sub = dynamic_cast<DynamicSubRequest&>(subrequest);
DynamicRequest& dyn_req = dyn_sub.get_request();
DynamicThread& dyn_thr = dyn_req.get_thread();
DynamicProcess& dyn_proc = dyn_thr.get_process();
// Pay attention that initial isn't deleted by reset()
ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes();
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.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
if (thr_ref == NULL)
return; // not found, just return.
DynamicRequest* req_ref = deep_find<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
if (req_ref == NULL)
return; // not found, just return.
bool removed = deep_remove<DynamicSubRequest>(req_ref->get_dynamic_subrequests(), dyn_sub);
if (removed)
reset(true);
}
ConcreteHistory::ResourcePair
ConcreteHistory::add_resource(const Glib::ustring& name,
bool preemptable,
size_t places,
size_t availability)
bool preemptable,
size_t places,
size_t availability)
{
reset(false);
reset(false);
typedef ConcreteEnvironment::Resources Resources;
typedef ConcreteEnvironment::SubRequestQueue SubRequestQueue;
// And preemptable and availability?? FIXME!
typedef ConcreteEnvironment::Resources Resources;
typedef ConcreteEnvironment::SubRequestQueue SubRequestQueue;
// And preemptable and availability?? FIXME!
StaticResource* core = new StaticResource(name, places);
DynamicResource* resource = new DynamicResource(core);
StaticResource* core = new StaticResource(name, places);
DynamicResource* resource = new DynamicResource(core);
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;
// The same for request queues.
SubRequestQueue emptysrq;
_snapshots.front()->get_subrequest_queues().insert(pair<resource_key_t,SubRequestQueue>(index, emptysrq));
ConcreteEnvironment::Resources& resources = _snapshots.front()->get_resources();
notify_change();
// alakazam! Black magic at work... get a unique index for this resource
resource_key_t index = 0;
while (resources.find(index) != resources.end())
index++;
return *temp;
// 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;
// The same for request queues.
SubRequestQueue emptysrq;
_snapshots.front()->get_subrequest_queues().insert(pair<resource_key_t, SubRequestQueue>(index, emptysrq));
notify_change();
return *temp;
}
DynamicProcess&
DynamicProcess&
ConcreteHistory::add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority)
time_t arrival_time,
prio_t base_priority)
{
reset(false);
StaticProcess* core = new StaticProcess(name, arrival_time, base_priority);
DynamicProcess* proc = new DynamicProcess(core);
reset(false);
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
processes.push_back(proc);
StaticProcess* core = new StaticProcess(name, arrival_time, base_priority);
DynamicProcess* proc = new DynamicProcess(core);
notify_change();
return *proc;
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
processes.push_back(proc);
notify_change();
return *proc;
}
DynamicThread&
DynamicThread&
ConcreteHistory::add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time,
prio_t base_priority)
Process& parent,
time_t cpu_time,
time_t arrival_time,
prio_t base_priority)
{
reset(false);
// Holy cow! *THIS* is ugly!!!!
DynamicProcess& parent_process = dynamic_cast<DynamicProcess&>(parent);
StaticProcess& parent_core = parent_process.get_core();
StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority);
DynamicThread* thread = new DynamicThread(core, &parent_process);
notify_change();
return *thread;
reset(false);
// Holy cow! *THIS* is ugly!!!!
DynamicProcess& parent_process = dynamic_cast<DynamicProcess&>(parent);
StaticProcess& parent_core = parent_process.get_core();
StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority);
DynamicThread* thread = new DynamicThread(core, &parent_process);
notify_change();
return *thread;
}
DynamicRequest&
DynamicRequest&
ConcreteHistory::add_request(Thread& owner,
time_t instant)
time_t instant)
{
reset(false);
DynamicThread& dyn_owner = dynamic_cast<DynamicThread&>(owner);
StaticThread& owner_core = dyn_owner.get_core();
StaticRequest* core = new StaticRequest(&owner_core, instant);
DynamicRequest* req = new DynamicRequest(core, &dyn_owner);
reset(false);
dyn_owner.get_requests().push_back(req);
DynamicThread& dyn_owner = dynamic_cast<DynamicThread&>(owner);
StaticThread& owner_core = dyn_owner.get_core();
notify_change();
return *req;
StaticRequest* core = new StaticRequest(&owner_core, instant);
DynamicRequest* req = new DynamicRequest(core, &dyn_owner);
dyn_owner.get_requests().push_back(req);
notify_change();
return *req;
}
DynamicSubRequest&
DynamicSubRequest&
ConcreteHistory::add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration)
resource_key_t resource_key,
time_t duration)
{
reset(false);
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
StaticSubRequest* core = new StaticSubRequest(resource_key, duration);
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
reset(false);
dyn_request.get_subrequests().push_back(subreq);
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
notify_change();
return *subreq;
StaticSubRequest* core = new StaticSubRequest(resource_key, duration);
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
dyn_request.get_subrequests().push_back(subreq);
notify_change();
return *subreq;
}
void
ConcreteHistory::reset(bool notify)
{
assert(_snapshots.size() > 0);
Snapshots::iterator it = _snapshots.begin();
it++; // Skip first environment that we saved
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
_snapshots.resize(1); // Truncate to keep only our "model"
assert(_snapshots.size() > 0);
Snapshots::iterator it = _snapshots.begin();
it++; // Skip first environment that we saved
if(notify)
notify_change();
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
_snapshots.resize(1); // Truncate to keep only our "model"
if (notify)
notify_change();
}
void
ConcreteHistory::notify_change()
{
History::RegisteredObservers::iterator it;
for(it =_observers.begin(); it != _observers.end(); it++)
(*it)->update(*this);
History::RegisteredObservers::iterator it;
for (it = _observers.begin(); it != _observers.end(); it++)
(*it)->update(*this);
}

View file

@ -49,53 +49,54 @@ namespace sgpem
ConcreteHistory(const ConcreteHistory&);
virtual ~ConcreteHistory();
virtual void append_new_environment(ConcreteEnvironment* environment);
virtual size_t get_size() const;
virtual const ConcreteEnvironment& get_last_environment() const;
virtual const ConcreteEnvironment& get_environment_at(position index) const throw(std::out_of_range);
virtual void remove(resource_key_t resource_key);
virtual void remove(Process& process);
virtual void remove(Thread& thread);
virtual void remove(Request& request);
virtual void remove(SubRequest& subrequest);
virtual void append_new_environment(ConcreteEnvironment* environment);
virtual size_t get_size() const;
virtual const ConcreteEnvironment& get_last_environment() const;
virtual const ConcreteEnvironment& get_environment_at(position index) const throw(std::out_of_range);
virtual void remove(resource_key_t resource_key);
virtual void remove(Process& process);
virtual void remove(Thread& thread);
virtual void remove(Request& request);
virtual void remove(SubRequest& subrequest);
virtual ResourcePair add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0);
virtual ResourcePair add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0);
virtual DynamicProcess& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0);
virtual DynamicProcess& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0);
virtual DynamicThread& add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time = 0,
prio_t base_priority = 0);
virtual DynamicThread& add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time = 0,
prio_t base_priority = 0);
virtual DynamicRequest& add_request(Thread& owner,
time_t instant);
virtual DynamicRequest& add_request(Thread& owner,
time_t instant);
virtual DynamicSubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration);
virtual DynamicSubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration);
virtual void reset(bool notify = true);
protected:
typedef std::vector<ConcreteEnvironment*> Snapshots;
Snapshots _snapshots;
virtual void reset(bool notify = true);
virtual void notify_change();
private:
// Disable assignment, implement it only if needed
ConcreteHistory& operator=(const ConcreteHistory& op2);
}; //~ class ConcreteHistory
protected:
typedef std::vector<ConcreteEnvironment*> Snapshots;
Snapshots _snapshots;
virtual void notify_change();
private:
// Disable assignment, implement it only if needed
ConcreteHistory& operator=(const ConcreteHistory& op2);
}
; //~ class ConcreteHistory
}//~ namespace sgpem

View file

@ -32,8 +32,8 @@ using namespace sgpem;
using namespace memory;
using Glib::usleep;
ConcreteSimulation::ConcreteSimulation() :
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
ConcreteSimulation::ConcreteSimulation() :
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
{}
void
@ -75,7 +75,7 @@ ConcreteSimulation::stop()
void
ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
{
switch(_state)
switch (_state)
{
case state_running:
return;
@ -88,57 +88,57 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
_state = state_running;
if(get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
if (get_policy() == NULL)
{
stop();
throw NullPolicyException("no policy selected");
}
//******* CONTINUOUS TIME
if (_mode)
{
do
{
try
{
try
{
//step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if(!yet_to_finish) stop();
//sleep
Glib::usleep(_timer_interval*1000);
}
catch(UserInterruptException e)
{
stop();
throw;
}
//check the state
if (_state == state_stopped || _state == state_paused)
return;
//step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if (!yet_to_finish) stop();
//sleep
Glib::usleep(_timer_interval*1000);
}
while(true);
catch (UserInterruptException e)
{
stop();
throw;
}
//check the state
if (_state == state_stopped || _state == state_paused)
return;
}
while (true);
}
//******* STEP by STEP
else
{
try
{
assert(get_policy() != NULL);
//step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if(yet_to_finish)
pause();
else
stop();
}
catch(UserInterruptException e)
{
{
assert(get_policy() != NULL);
//step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if (yet_to_finish)
pause();
else
stop();
throw;
}
}
catch (UserInterruptException e)
{
stop();
throw;
}
}
}
@ -158,8 +158,8 @@ void
ConcreteSimulation::set_policy(CPUPolicy* p)
{
_policy = p;
if(p != NULL)
if (p != NULL)
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
}

View file

@ -42,7 +42,7 @@ namespace sgpem
void set_timer(const unsigned int);
int get_timer() const;
void set_mode(const bool&);
bool get_mode() const;

View file

@ -55,7 +55,7 @@ CPUPoliciesGatekeeper::register_manager(CPUPolicyManager* manager)
ManagerIterator end = _registered.end();
if(find(_registered.begin(), end, manager) == end)
if (find(_registered.begin(), end, manager) == end)
_registered.push_back(manager);
}
@ -67,7 +67,7 @@ CPUPoliciesGatekeeper::unregister_manager(CPUPolicyManager* manager)
ManagerIterator end = _registered.end();
ManagerIterator pos = find(_registered.begin(), end, manager);
if(pos != end)
if (pos != end)
{
deactivate_policies(*pos);
_registered.erase(pos);
@ -81,7 +81,7 @@ CPUPoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
ActiveIterator policy = _active_policies.find(history);
if(policy == _active_policies.end())
if (policy == _active_policies.end())
throw runtime_error("No active policy associated with this "
"history is available.");
@ -96,10 +96,10 @@ CPUPoliciesGatekeeper::activate_policy(History *history, CPUPolicy* policy)
ActiveIterator end = _active_policies.end();
ActiveIterator pos = _active_policies.find(history);
if(pos != end && pos->second != policy)
if (pos != end && pos->second != policy)
_active_policies[history]->deactivate();
if(pos == end || pos->second != policy)
if (pos == end || pos->second != policy)
{
_active_policies[history] = policy;
_active_policies[history]->activate();
@ -119,23 +119,23 @@ CPUPoliciesGatekeeper::deactivate_policies(CPUPolicyManager* manager)
CPUPolicyIterator avail_it = avail_policies.begin();
CPUPolicyIterator avail_end = avail_policies.end();
for(; avail_it != avail_end; ++avail_it)
for (; avail_it != avail_end; ++avail_it)
{
// TODO isn't there a way to write more compact code by using
// library utilities?
ActiveIterator act_it = _active_policies.begin();
while(act_it != _active_policies.end())
{
if(act_it->second == *avail_it)
{
ActiveIterator removable = act_it++;
removable->second->deactivate();
_active_policies.erase(removable);
}
else
act_it++;
}
while (act_it != _active_policies.end())
{
if (act_it->second == *avail_it)
{
ActiveIterator removable = act_it++;
removable->second->deactivate();
_active_policies.erase(removable);
}
else
act_it++;
}
} //~ for(avail_it)
}

View file

@ -38,7 +38,7 @@ CPUPolicyManager::~CPUPolicyManager()
{
// This check is necessary:
//FIXME remove this when get_registered_manager is dropped
if(_registered == this) _registered = NULL;
if (_registered == this) _registered = NULL;
CPUPoliciesGatekeeper::get_instance().unregister_manager(this);
}

View file

@ -32,28 +32,28 @@
using namespace sgpem;
using namespace std;
DynamicProcess::DynamicProcess(StaticProcess* core) :
DynamicSchedulable(), _core(core)
DynamicProcess::DynamicProcess(StaticProcess* core) :
DynamicSchedulable(), _core(core)
{
assert(core != NULL);
}
DynamicProcess::DynamicProcess(const DynamicProcess &other) :
Schedulable(), DynamicSchedulable(other), Process(),
_core(other._core)
Schedulable(), DynamicSchedulable(other), Process(),
_core(other._core)
{
typedef vector<DynamicThread*>::const_iterator ThreadIt;
const vector<DynamicThread*>& other_threads = other._dynamic_threads;
for(ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it)
for (ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it)
new DynamicThread(*(*it), this);
}
DynamicProcess::~DynamicProcess()
{
for_each(_dynamic_threads.begin(), _dynamic_threads.end(),
memory::deletor<DynamicThread>());
for_each(_dynamic_threads.begin(), _dynamic_threads.end(),
memory::deletor<DynamicThread>());
}
std::vector<Thread*>
@ -65,71 +65,71 @@ DynamicProcess::get_threads()
std::vector<const Thread*>
DynamicProcess::get_threads() const
{
return vector<const Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
return vector<const Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
}
Schedulable::state
DynamicProcess::get_state() const
{
int total = _dynamic_threads.size();
int running = 0;
int ready = 0;
int blocked = 0;
int terminated = 0;
int future = 0;
int total = _dynamic_threads.size();
int running = 0;
int ready = 0;
int blocked = 0;
int terminated = 0;
int future = 0;
unsigned int closest = 0;
vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
for(; it != _dynamic_threads.end(); it++)
{
if ((**it).get_state() == state_running) running++;
if ((**it).get_state() == state_ready) ready++;
if ((**it).get_state() == state_blocked) blocked++;
if ((**it).get_state() == state_terminated) terminated++;
if ((**it).get_state() == state_future)
{
unsigned int arrival = (**it).get_arrival_time();
// if this is the first future occurrence, record its arrival;
// else record its arrival if and only if it is smaller then the recorded one
if (future == 0)
closest = arrival;
else
closest = (closest < arrival) ? closest : arrival;
future++;
}
}
unsigned int closest = 0;
assert(total > 0);
assert(running == 1 || running == 0);
assert(running + ready + blocked + terminated + future == total);
vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
for (; it != _dynamic_threads.end(); it++)
{
if ((**it).get_state() == state_running) running++;
if ((**it).get_state() == state_ready) ready++;
if ((**it).get_state() == state_blocked) blocked++;
if ((**it).get_state() == state_terminated) terminated++;
if ((**it).get_state() == state_future)
{
unsigned int arrival = (**it).get_arrival_time();
// if this is the first future occurrence, record its arrival;
// else record its arrival if and only if it is smaller then the recorded one
if (future == 0)
closest = arrival;
else
closest = (closest < arrival) ? closest : arrival;
future++;
}
}
if (running > 0)
return state_running;
if (ready > 0) // running == 0
return state_ready;
if (blocked > 0) // running == 0 && ready == 0
return state_blocked;
// Now check if a "hole" happens: if all threads are terminated
// or blocked the next
// thread to start, e.g. the one with the least arrival_time, has
// start time greater than the current process elapsed time, then
// pass from state_future to state_terminated:
if (closest > get_elapsed_time())
return state_terminated;
if (terminated > 0) // running == 0 && ready == 0 && blocked == 0
return state_terminated;
if (future > 0) // running == 0 && ready == 0 && blocked == 0 && terminated == 0
return state_future;
assert(total > 0);
assert(running == 1 || running == 0);
assert(running + ready + blocked + terminated + future == total);
// I'm not sure if we can get here (maybe if there are no threads?),
// but I don't like this compiler warning: 'control reaches end of non-void function'
if (running > 0)
return state_running;
if (ready > 0) // running == 0
return state_ready;
if (blocked > 0) // running == 0 && ready == 0
return state_blocked;
// Now check if a "hole" happens: if all threads are terminated
// or blocked the next
// thread to start, e.g. the one with the least arrival_time, has
// start time greater than the current process elapsed time, then
// pass from state_future to state_terminated:
if (closest > get_elapsed_time())
return state_terminated;
if (terminated > 0) // running == 0 && ready == 0 && blocked == 0
return state_terminated;
if (future > 0) // running == 0 && ready == 0 && blocked == 0 && terminated == 0
return state_future;
// Since premature optimization is the root of all evil, and the
// following code was very fast but also very wrong, the coder
// will be punished by allowing her to code in C++ just after
// having passed "Algoritmi 3" exam with full marks.
// I'm not sure if we can get here (maybe if there are no threads?),
// but I don't like this compiler warning: 'control reaches end of non-void function'
return state_future;
// Since premature optimization is the root of all evil, and the
// following code was very fast but also very wrong, the coder
// will be punished by allowing her to code in C++ just after
// having passed "Algoritmi 3" exam with full marks.
/*
typedef vector<DynamicThread*>::const_iterator ThreadIt;
@ -164,7 +164,7 @@ DynamicProcess::get_state() const
// TODO Is this OK? Must be tested...
int thread_starts_at;
switch(thread_state)
{
@ -189,8 +189,8 @@ DynamicProcess::get_state() const
}
} //~ "for" iterating over threads
// reused hole checking system
*/
// reused hole checking system
*/
}
@ -204,32 +204,32 @@ DynamicProcess::serialize(SerializeVisitor& translator) const
StaticProcess&
DynamicProcess::get_core()
{
return *_core;
return *_core;
}
const StaticProcess&
DynamicProcess::get_core() const
{
return *_core;
return *_core;
}
std::vector<DynamicThread*>&
DynamicProcess::get_dynamic_threads()
{
return _dynamic_threads;
return _dynamic_threads;
}
unsigned int
DynamicProcess::get_elapsed_time() const
{
unsigned int result = 0;
for(std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++)
{
result += (*it)->get_elapsed_time();
}
for (std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++)
{
result += (*it)->get_elapsed_time();
}
return result;
}
@ -237,13 +237,13 @@ int
DynamicProcess::get_last_acquisition() const
{
int result = -1;
for(std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++)
{
int acq = (*it)->get_last_acquisition();
if(result < acq)
result = acq;
}
for (std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++)
{
int acq = (*it)->get_last_acquisition();
if (result < acq)
result = acq;
}
return result;
}
@ -251,13 +251,13 @@ int
DynamicProcess::get_last_release() const
{
int result = -1;
for(std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++)
{
int acq = (*it)->get_last_release();
if(result < acq)
result = acq;
}
for (std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++)
{
int acq = (*it)->get_last_release();
if (result < acq)
result = acq;
}
return result;
}

View file

@ -45,7 +45,7 @@ namespace sgpem
public:
DynamicProcess(StaticProcess* core);
DynamicProcess(const DynamicProcess &other);
virtual ~DynamicProcess();
virtual ~DynamicProcess();
std::vector<Thread*> get_threads();
std::vector<const Thread*> get_threads() const;
@ -61,8 +61,8 @@ namespace sgpem
virtual StaticProcess& get_core();
virtual const StaticProcess& get_core() const;
// Does also the job of "add_thread" and "remove_thread"
std::vector<DynamicThread*>& get_dynamic_threads();
// Does also the job of "add_thread" and "remove_thread"
std::vector<DynamicThread*>& get_dynamic_threads();
private:
memory::smart_ptr<StaticProcess> _core;

View file

@ -47,38 +47,38 @@ DynamicRequest::DynamicRequest(StaticRequest *core,
}
DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner) :
_static_request(other._static_request), _dynamic_thread(owner)
_static_request(other._static_request), _dynamic_thread(owner)
{
typedef vector<DynamicSubRequest*> SubReqVec;
assert(owner != NULL);
const SubReqVec& other_subs = other._dynamic_subrequests;
// Not sure of this, but the constructor of DynamicSubRequest should take care
// of adding itself to the vector of sub requests. This is only my opinion,
// of adding itself to the vector of sub requests. This is only my opinion,
// but I think this is a complicated way of doing things...
for(SubReqVec::const_iterator it = other_subs.begin(); it != other_subs.end(); ++it)
for (SubReqVec::const_iterator it = other_subs.begin(); it != other_subs.end(); ++it)
new DynamicSubRequest(*(*it), this);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicRequest*>& siblings = owner->get_dynamic_requests();
siblings.push_back(this);
}
DynamicRequest::~DynamicRequest()
{
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(),
memory::deletor<DynamicSubRequest>());
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(),
memory::deletor<DynamicSubRequest>());
}
bool
DynamicRequest::operator==(const Request& op2) const
{
assert(dynamic_cast<const DynamicRequest*>(&op2) != NULL);
assert(dynamic_cast<const DynamicRequest*>(&op2) != NULL);
return _static_request == dynamic_cast<const DynamicRequest&>(op2)._static_request;
}
@ -112,42 +112,42 @@ DynamicRequest::get_instant() const
Request::state
DynamicRequest::get_state() const
{
typedef std::vector<DynamicSubRequest*> SubReqs;
typedef std::vector<DynamicSubRequest*> SubReqs;
state result = state_future;
state result = state_future;
#ifndef NDEBUG
// Only for debug:
bool at_least_once = false;
// Only for debug:
bool at_least_once = false;
#endif // ~NDEBUG
const SubReqs& sreqs = _dynamic_subrequests;
for(SubReqs::const_iterator it = sreqs.begin(); it != sreqs.end(); it++)
{
SubRequest& cur = **it;
const SubReqs& sreqs = _dynamic_subrequests;
for (SubReqs::const_iterator it = sreqs.begin(); it != sreqs.end(); it++)
{
SubRequest& cur = **it;
switch(cur.get_state())
{
case state_allocated:
return state_allocated;
case state_unallocable:
return state_unallocable;
default:
switch (cur.get_state())
{
case state_allocated:
return state_allocated;
case state_unallocable:
return state_unallocable;
default:
#ifndef NDEBUG
// We want to be sure that all subrequests
// have the same state since state_allocable,
// state_terminated and state_future are mutually
// exclusive
if(at_least_once)
assert(result == cur.get_state());
at_least_once = true;
// We want to be sure that all subrequests
// have the same state since state_allocable,
// state_terminated and state_future are mutually
// exclusive
if (at_least_once)
assert(result == cur.get_state());
at_least_once = true;
#endif //~ NDEBUG
result = cur.get_state();
}
}
return result;
result = cur.get_state();
}
}
return result;
}
@ -161,12 +161,12 @@ DynamicRequest::serialize(SerializeVisitor& translator) const
StaticRequest&
DynamicRequest::get_core()
{
return *_static_request;
return *_static_request;
}
const StaticRequest&
DynamicRequest::get_core() const
{
return *_static_request;
return *_static_request;
}

View file

@ -43,11 +43,11 @@ namespace sgpem
public:
DynamicRequest(StaticRequest *core, DynamicThread* owner);
DynamicRequest(const DynamicRequest& other, DynamicThread* owner);
~DynamicRequest();
~DynamicRequest();
virtual bool operator==(const Request& op2) const;
virtual bool operator==(const Request& op2) const;
virtual std::vector<SubRequest*> get_subrequests();
virtual std::vector<SubRequest*> get_subrequests();
DynamicThread& get_thread();
@ -57,12 +57,12 @@ namespace sgpem
void serialize(SerializeVisitor& translator) const;
StaticRequest& get_core();
const StaticRequest& get_core() const;
StaticRequest& get_core();
const StaticRequest& get_core() const;
// Since this method is visible only by the backend,
// return directly a reference that lets us to
// add and remove subrequests at will.
// Since this method is visible only by the backend,
// return directly a reference that lets us to
// add and remove subrequests at will.
std::vector<DynamicSubRequest*>& get_dynamic_subrequests();
private:

View file

@ -36,7 +36,7 @@ DynamicResource::DynamicResource(StaticResource *core) :
bool
DynamicResource::operator==(const Resource& op2) const
{
assert(dynamic_cast<const DynamicResource*>(&op2) != NULL);
assert(dynamic_cast<const DynamicResource*>(&op2) != NULL);
return _static_resource == dynamic_cast<const DynamicResource&>(op2)._static_resource;
}
@ -62,12 +62,12 @@ DynamicResource::serialize(SerializeVisitor& translator) const
StaticResource&
DynamicResource::get_core()
{
return *_static_resource;
return *_static_resource;
}
const StaticResource&
DynamicResource::get_core() const
{
return *_static_resource;
return *_static_resource;
}

View file

@ -39,15 +39,15 @@ namespace sgpem
public:
DynamicResource(StaticResource *core);
virtual bool operator==(const Resource& op2) const;
virtual bool operator==(const Resource& op2) const;
Glib::ustring get_name() const;
unsigned int get_places() const;
void serialize(SerializeVisitor& translator) const;
StaticResource& get_core();
const StaticResource& get_core() const;
StaticResource& get_core();
const StaticResource& get_core() const;
private:
memory::smart_ptr<StaticResource> _static_resource;

View file

@ -27,14 +27,14 @@
using namespace sgpem;
using namespace std;
DynamicSchedulable::DynamicSchedulable()
: _priority_push(0)
DynamicSchedulable::DynamicSchedulable()
: _priority_push(0)
{}
bool
DynamicSchedulable::operator==(const Schedulable& op2) const
{
assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
return &get_core() == &(dynamic_cast<const DynamicSchedulable&>(op2).get_core());
}
@ -62,7 +62,7 @@ DynamicSchedulable::get_total_cpu_time() const
return get_core().get_total_cpu_time();
}
int
int
DynamicSchedulable::set_priority_push(int new_value)
{
int old_priority_push = _priority_push;

View file

@ -30,42 +30,41 @@
using namespace sgpem;
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
DynamicRequest* owner) :
_static_subrequest(core), _owner(owner),
_queue_position(-1), _ran_for(0), _state(Request::state_future)
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
DynamicRequest* owner) :
_static_subrequest(core), _owner(owner),
_queue_position(-1), _ran_for(0), _state(Request::state_future)
{
assert(core != NULL);
assert(owner != NULL);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this);
}
DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other,
DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other,
DynamicRequest* owner) :
_static_subrequest(other._static_subrequest), _owner(owner),
_queue_position(other._queue_position), _ran_for(other._ran_for),
_state(other._state)
_static_subrequest(other._static_subrequest), _owner(owner),
_queue_position(other._queue_position), _ran_for(other._ran_for),
_state(other._state)
{
assert(owner != NULL);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this);
}
DynamicSubRequest::~DynamicSubRequest()
{
}
{}
bool
DynamicSubRequest::operator==(const SubRequest& op2) const
{
assert(dynamic_cast<const DynamicSubRequest*>(&op2) != NULL);
assert(dynamic_cast<const DynamicSubRequest*>(&op2) != NULL);
return _static_subrequest == dynamic_cast<const DynamicSubRequest&>(op2)._static_subrequest;
}
@ -99,42 +98,42 @@ DynamicSubRequest::set_queue_position(int position)
DynamicRequest&
DynamicSubRequest::get_request()
{
return *_owner;
return *_owner;
}
DynamicSubRequest::state
DynamicSubRequest::get_state() const
{
return _state;
return _state;
}
DynamicSubRequest::state
DynamicSubRequest::set_state(state new_state)
{
state temp = _state;
_state = new_state;
return temp;
state temp = _state;
_state = new_state;
return temp;
}
unsigned int
unsigned int
DynamicSubRequest::get_remaining_time() const
{
return _static_subrequest->get_length() - _ran_for;
return _static_subrequest->get_length() - _ran_for;
}
unsigned int
DynamicSubRequest::decrease_remaining_time()
{
assert(_state == Request::state_allocated);
unsigned int temp = get_remaining_time();
if(temp > 0)
_ran_for++;
return temp;
assert(_state == Request::state_allocated);
unsigned int temp = get_remaining_time();
if (temp > 0)
_ran_for++;
return temp;
}
@ -145,15 +144,15 @@ DynamicSubRequest::serialize(SerializeVisitor& translator) const
}
StaticSubRequest&
StaticSubRequest&
DynamicSubRequest::get_core()
{
return *_static_subrequest;
return *_static_subrequest;
}
const StaticSubRequest&
const StaticSubRequest&
DynamicSubRequest::get_core() const
{
return *_static_subrequest;
return *_static_subrequest;
}

View file

@ -34,20 +34,20 @@
namespace sgpem
{
class DynamicSubRequest;
class SerializeVisitor;
class SerializeVisitor;
class Resource;
class StaticSubRequest;
class SG_DLLLOCAL DynamicSubRequest : public SubRequest
{
public:
DynamicSubRequest(StaticSubRequest* core,
DynamicRequest* owner);
public:
DynamicSubRequest(StaticSubRequest* core,
DynamicRequest* owner);
DynamicSubRequest(const DynamicSubRequest& other, DynamicRequest* owner);
virtual ~DynamicSubRequest();
virtual ~DynamicSubRequest();
virtual bool operator==(const SubRequest& op2) const;
virtual bool operator==(const SubRequest& op2) const;
resource_key_t get_resource_key() const;
@ -56,28 +56,28 @@ namespace sgpem
int get_queue_position() const;
void set_queue_position(int position);
virtual DynamicRequest& get_request();
virtual DynamicRequest& get_request();
state get_state() const;
state set_state(state new_state);
unsigned int get_remaining_time() const;
unsigned int decrease_remaining_time();
state get_state() const;
state set_state(state new_state);
unsigned int get_remaining_time() const;
unsigned int decrease_remaining_time();
void serialize(SerializeVisitor& translator) const;
StaticSubRequest& get_core();
const StaticSubRequest& get_core() const;
StaticSubRequest& get_core();
const StaticSubRequest& get_core() const;
private:
// Undefined
DynamicSubRequest(const DynamicSubRequest&);
memory::smart_ptr<StaticSubRequest> _static_subrequest;
DynamicRequest* _owner;
DynamicRequest* _owner;
int _queue_position;
unsigned int _ran_for;
state _state;
unsigned int _ran_for;
state _state;
};
}

View file

@ -34,32 +34,32 @@ using namespace sgpem;
using namespace std;
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
: DynamicSchedulable(), _core(core), _state(state_future), _parent(parent),
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
: DynamicSchedulable(), _core(core), _state(state_future), _parent(parent),
_ran_for(0), _last_acquisition(-1), _last_release(-1)
{
assert(core != NULL);
assert(parent != NULL);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicThread*>& siblings = parent->get_dynamic_threads();
siblings.push_back(this);
assert(core != NULL);
assert(parent != NULL);
// Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes:
std::vector<DynamicThread*>& siblings = parent->get_dynamic_threads();
siblings.push_back(this);
}
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
Schedulable(), DynamicSchedulable(other), Thread(),
_core(other._core), _state(other._state), _parent(parent),
_ran_for(other._ran_for), _last_acquisition(other._last_acquisition),
Schedulable(), DynamicSchedulable(other), Thread(),
_core(other._core), _state(other._state), _parent(parent),
_ran_for(other._ran_for), _last_acquisition(other._last_acquisition),
_last_release(other._last_release)
{
typedef vector<DynamicRequest*>::const_iterator ReqIt;
assert(parent != NULL);
const vector<DynamicRequest*>& other_req = other._dynamic_requests;
for(ReqIt it = other_req.begin(); it != other_req.end(); ++it)
for (ReqIt it = other_req.begin(); it != other_req.end(); ++it)
new DynamicRequest(*(*it), this);
// Leave this line: it helps us with a compiler warning if
@ -70,8 +70,8 @@ DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent)
DynamicThread::~DynamicThread()
{
for_each(_dynamic_requests.begin(), _dynamic_requests.end(),
memory::deletor<DynamicRequest>());
for_each(_dynamic_requests.begin(), _dynamic_requests.end(),
memory::deletor<DynamicRequest>());
}
@ -112,20 +112,20 @@ DynamicThread::serialize(SerializeVisitor& translator) const
StaticThread&
DynamicThread::get_core()
{
return *_core;
return *_core;
}
const StaticThread&
DynamicThread::get_core() const
{
return *_core;
return *_core;
}
std::vector<DynamicRequest*>&
DynamicThread::get_dynamic_requests()
{
return _dynamic_requests;
return _dynamic_requests;
}
@ -138,10 +138,10 @@ DynamicThread::get_elapsed_time() const
void
DynamicThread::decrease_remaining_time()
{
// strict check for us to better debug scheduler
assert(_ran_for < get_total_cpu_time());
if(_ran_for < get_total_cpu_time())
_ran_for++;
// strict check for us to better debug scheduler
assert(_ran_for < get_total_cpu_time());
if (_ran_for < get_total_cpu_time())
_ran_for++;
}
int

View file

@ -72,9 +72,9 @@ namespace sgpem
std::vector<DynamicRequest*>& get_dynamic_requests();
private:
// Undefined
// Undefined
DynamicThread(const DynamicThread &other);
memory::smart_ptr<StaticThread> _core;
state _state;
std::vector<DynamicRequest*> _dynamic_requests;

View file

@ -38,7 +38,7 @@ namespace sgpem
/// \brief An instant of the simulation.
/// An object of the Environment class represents a snapshot of
/// the simulated environment taken in a fixed instant, composed
/// the simulated environment taken in a fixed instant, composed
/// by processes, threads, resources and more.
/// A snapshot for every single entity is accessible from here.
/// All the provided objects and data is constant.
@ -58,11 +58,11 @@ namespace sgpem
class SG_DLLEXPORT Environment
{
public:
typedef SubRequest::resource_key_t resource_key_t;
typedef SubRequest::resource_key_t resource_key_t;
typedef std::vector<Process*> Processes;
typedef std::map<resource_key_t, Resource*> Resources;
typedef std::vector<SubRequest*> SubRequestQueue;
typedef std::vector<Process*> Processes;
typedef std::map<resource_key_t, Resource*> Resources;
typedef std::vector<SubRequest*> SubRequestQueue;
/// \brief Returns an indexed set of snapshots of the processes
/// Returns a standard vector of Process objects describing
@ -72,7 +72,7 @@ namespace sgpem
/// \return a constant set of snapshots of processes
virtual const Processes&
get_processes() const = 0;
get_processes() const = 0;
/// \brief Returns an indexed set of snapshots of the resources
@ -90,7 +90,7 @@ namespace sgpem
/// \return an indexed constant set of snapshot of resources.
virtual const Resources&
get_resources() const = 0;
get_resources() const = 0;
/// \brief Returns a snapshot of the current request queue for a resource.
@ -101,7 +101,7 @@ namespace sgpem
/// \return the current ready requests queue (constant).
virtual const SubRequestQueue&
get_request_queue(resource_key_t resource_key) const = 0;
get_request_queue(resource_key_t resource_key) const = 0;
/// \brief Returns a snapshot of the current scheduler's ready queue.
@ -112,7 +112,7 @@ namespace sgpem
/// \return the current ready queue (constant).
virtual const ReadyQueue&
get_sorted_queue() const = 0;
get_sorted_queue() const = 0;
/// \brief The standard virtual destructor.

View file

@ -96,13 +96,13 @@ GlobalPreferences::get_plugin_dirs()
return _mod_dirs;
}
int
int
GlobalPreferences::get_speed()
{
return _speed;
}
int
int
GlobalPreferences::set_speed(int new_speed)
{
int old_speed = _speed;
@ -123,7 +123,7 @@ void
GlobalPreferences::load_configrc()
{
KeyFile kf;
kf.file_read(get_config_filename());
key_file_read(kf);
}
@ -141,7 +141,7 @@ void
GlobalPreferences::load_configrc(std::istream &is)
{
KeyFile kf;
kf.file_read(is);
key_file_read(kf);
}
@ -157,7 +157,8 @@ GlobalPreferences::key_file_read(KeyFile& kf)
{
int new_speed;
const Glib::ustring* val = kf.search_value(Glib::ustring("speed"));
if(val){
if (val)
{
string_to_int(*val, new_speed);
set_speed(new_speed);
}
@ -165,18 +166,18 @@ GlobalPreferences::key_file_read(KeyFile& kf)
// read modules directories
{
const Glib::ustring* val = kf.search_value(Glib::ustring("modules-dir-number"));
if(val)
if (val)
{
std::istringstream istr(val->c_str());
int n;
istr >> n;
for(int i=1; i<=n; i++)
for (int i = 1; i <= n; i++)
{
std::ostringstream ostr;
ostr << "modules-dir-" << i;
Glib::ustring key(ostr.str());
val = kf.search_value(key);
if(val)
if (val)
{
// add_modules_dir(*val);
_mod_dirs.push_back(*val);
@ -188,18 +189,18 @@ GlobalPreferences::key_file_read(KeyFile& kf)
// read policies directories
{
const Glib::ustring* val = kf.search_value(Glib::ustring("policies-dir-number"));
if(val)
if (val)
{
std::istringstream istr(val->c_str());
int n;
istr >> n;
for(int i=1; i<=n; i++)
for (int i = 1; i <= n; i++)
{
std::ostringstream ostr;
ostr << "policies-dir-" << i;
ostr << "policies-dir-" << i;
Glib::ustring key(ostr.str());
val = kf.search_value(key);
if(val)
if (val)
{
// add_policies_dir(*val);
_pol_dirs.push_back(*val);
@ -227,10 +228,11 @@ GlobalPreferences::key_file_write(KeyFile& kf)
/*
GlobalPreferences::dir_iterator iter=_globalPreferences.modules_dir_begin();
*/
dir_iterator iter=_mod_dirs.begin();
dir_iterator end=_mod_dirs.end();
int n=0;
while(iter!=end){
dir_iterator iter = _mod_dirs.begin();
dir_iterator end = _mod_dirs.end();
int n = 0;
while (iter != end)
{
std::ostringstream ostr;
n++;
ostr << "modules-dir-" << n; // << std::ends;
@ -246,13 +248,14 @@ GlobalPreferences::key_file_write(KeyFile& kf)
}
// add policies directories
{
/*
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin();
*/
dir_iterator iter=_pol_dirs.begin();
dir_iterator end=_pol_dirs.end();
int n=0;
while(iter!=end){
/*
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin();
*/
dir_iterator iter = _pol_dirs.begin();
dir_iterator end = _pol_dirs.end();
int n = 0;
while (iter != end)
{
std::ostringstream ostr;
n++;
ostr << "policies-dir-" << n; // << std::ends;

View file

@ -49,25 +49,25 @@ namespace sgpem
public:
typedef std::vector<Glib::ustring>::const_iterator dir_iterator;
dir_iterator modules_dir_begin() const;
dir_iterator modules_dir_end() const;
dir_iterator policies_dir_begin() const;
dir_iterator policies_dir_end() const;
/**
\return GlobalPreferences configuration filename
*/
const Glib::ustring get_config_filename();
/**
\brief Adds a directory search entry to modules dirs
*/
void add_modules_dir(const Glib::ustring& moddir);
/**
\brief Adds a directory search entry to policies dirs
*/
@ -75,14 +75,14 @@ namespace sgpem
/**
\brief Returns configured Policy directories
\return ::_policy_dirs
*/
std::vector<Glib::ustring>& get_policy_dirs();
/**
\brief Returns configured Plugin directories
\return ::_plugin_dirs
*/
std::vector<Glib::ustring>& get_plugin_dirs();
@ -93,14 +93,14 @@ namespace sgpem
\return _speed
*/
int get_speed();
/**
\brief Returns the simumulation speed and return old speed
\return _speed
*/
int set_speed(int new_speed);
/**
\brief Writes preferences to disk
@ -122,7 +122,7 @@ namespace sgpem
\throw std::io_error
*/
void load_configrc();
void write_configrc(std::ostream &os);
void load_configrc(std::istream &is);
private:
@ -148,7 +148,7 @@ namespace sgpem
-# Via command line arguments
-# By a backend::Plugin::on_init() method called when loading an external DSO. This is perfectly normal and permitted.
*/
int _speed;
};
}

View file

@ -27,11 +27,11 @@ namespace sgpem
{
GlobalPreferencesSerializer::GlobalPreferencesSerializer(GlobalPreferences &gp)
: _globalPreferences(gp)
: _globalPreferences(gp)
{}
void
GlobalPreferencesSerializer::file_read(const Glib::ustring& filename)
{
@ -41,18 +41,18 @@ namespace sgpem
// read modules directories
{
const Glib::ustring* val = search_value(Glib::ustring("modules-dir-number"));
if(val)
if (val)
{
std::istringstream istr(val->c_str());
int n;
istr >> n;
for(int i=1; i<=n; i++)
for (int i = 1; i <= n; i++)
{
std::ostringstream ostr;
ostr << "modules-dir-" << i << std::ends;
Glib::ustring key(ostr.str());
val = search_value(key);
if(val)
if (val)
{
_globalPreferences.add_modules_dir(*val);
}
@ -63,18 +63,18 @@ namespace sgpem
// read policies directories
{
const Glib::ustring* val = search_value(Glib::ustring("policies-dir-number"));
if(val)
if (val)
{
std::istringstream istr(val->c_str());
int n;
istr >> n;
for(int i=1; i<=n; i++)
for (int i = 1; i <= n; i++)
{
std::ostringstream ostr;
ostr << "policies-dir-" << i << std::ends;
Glib::ustring key(ostr.str());
val = search_value(key);
if(val)
if (val)
{
_globalPreferences.add_policies_dir(*val);
}
@ -82,15 +82,16 @@ namespace sgpem
}
}
}
void
GlobalPreferencesSerializer::file_write(const Glib::ustring& filename)
{
// add modules directories
{
GlobalPreferences::dir_iterator iter=_globalPreferences.modules_dir_begin();
int n=0;
while(iter!=_globalPreferences.modules_dir_end()){
GlobalPreferences::dir_iterator iter = _globalPreferences.modules_dir_begin();
int n = 0;
while (iter != _globalPreferences.modules_dir_end())
{
std::ostringstream ostr;
n++;
ostr << "modules-dir-" << n << std::ends;
@ -106,9 +107,10 @@ namespace sgpem
}
// add policies directories
{
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin();
int n=0;
while(iter!=_globalPreferences.policies_dir_end()){
GlobalPreferences::dir_iterator iter = _globalPreferences.policies_dir_begin();
int n = 0;
while (iter != _globalPreferences.policies_dir_end())
{
std::ostringstream ostr;
n++;
ostr << "policies-dir-" << n << std::ends;
@ -122,7 +124,7 @@ namespace sgpem
Glib::ustring value(ostr.str());
insert_key_value(key, value);
}
KeyFile::file_write(filename);
}
}

View file

@ -29,7 +29,7 @@ namespace sgpem
class GlobalPreferencesSerializer;
/** \brief Save and retrieve global preferences formatted as key=value rows.
*
* This class handles files to store and retrieve global preferences

View file

@ -30,40 +30,38 @@ using namespace std;
History::History()
: _notify(true)
{
}
: _notify(true)
{}
History::~History()
{
}
{}
void
History::attach(HistoryObserver& observer)
{
_observers.push_back(&observer);
_observers.push_back(&observer);
}
void
History::detach(const HistoryObserver& observer)
{
_observers.erase(std::find(_observers.begin(),
_observers.end(),
&observer));
_observers.erase(std::find(_observers.begin(),
_observers.end(),
&observer));
}
void
void
History::notify_change()
{
if(!_notify) return;
if (!_notify) return;
for(RegisteredObservers::iterator it =_observers.begin();
it != _observers.end(); it++)
(*it)->update(*this);
for (RegisteredObservers::iterator it = _observers.begin();
it != _observers.end(); it++)
(*it)->update(*this);
}
@ -72,9 +70,9 @@ History::set_notify_enabled(bool enabled)
{
bool old_value = _notify;
_notify = enabled;
// Force notify if we re-enable it
if(old_value == false && _notify == true)
if (old_value == false && _notify == true)
notify_change();
return old_value;

View file

@ -45,64 +45,64 @@ namespace sgpem
*/
class History;
// Forward declarations:
class HistoryObserver;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
// Forward declarations:
class HistoryObserver;
class Resource;
class Process;
class Thread;
class Request;
class SubRequest;
class SG_DLLEXPORT History
{
public:
typedef unsigned int size_t;
typedef unsigned int time_t;
typedef unsigned int position;
typedef int prio_t;
typedef unsigned int size_t;
typedef unsigned int time_t;
typedef unsigned int position;
typedef int prio_t;
typedef Environment::resource_key_t resource_key_t;
typedef const std::pair<resource_key_t, Resource*> ResourcePair;
typedef Environment::resource_key_t resource_key_t;
typedef const std::pair<resource_key_t, Resource*> ResourcePair;
History();
virtual ~History() = 0;
virtual size_t get_size() const = 0;
virtual const Environment& get_last_environment() const = 0;
virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0;
virtual void remove(resource_key_t resource_key) = 0;
virtual void remove(Process& process) = 0;
virtual void remove(Thread& thread) = 0;
virtual void remove(Request& request) = 0;
virtual void remove(SubRequest& subrequest) = 0;
virtual ~History() = 0;
virtual size_t get_size() const = 0;
virtual const Environment& get_last_environment() const = 0;
virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0;
virtual void remove(resource_key_t resource_key) = 0;
virtual void remove(Process& process) = 0;
virtual void remove(Thread& thread) = 0;
virtual void remove(Request& request) = 0;
virtual void remove(SubRequest& subrequest) = 0;
virtual ResourcePair add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0) = 0;
virtual ResourcePair add_resource(const Glib::ustring& name,
bool preemptable = false,
size_t places = 1,
size_t availability = 0) = 0;
virtual Process& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0) = 0;
virtual Process& add_process(const Glib::ustring& name,
time_t arrival_time,
prio_t base_priority = 0) = 0;
virtual Thread& add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time = 0,
prio_t base_priority = 0) = 0;
virtual Thread& add_thread(const Glib::ustring& name,
Process& parent,
time_t cpu_time,
time_t arrival_time = 0,
prio_t base_priority = 0) = 0;
virtual Request& add_request(Thread& owner,
time_t instant) = 0;
virtual Request& add_request(Thread& owner,
time_t instant) = 0;
virtual SubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration) = 0;
virtual SubRequest& add_subrequest(Request& request,
resource_key_t resource_key,
time_t duration) = 0;
virtual void attach(HistoryObserver& observer);
virtual void detach(const HistoryObserver& observer);
virtual void attach(HistoryObserver& observer);
virtual void detach(const HistoryObserver& observer);
/** \brief Enable/disable notifications to registered observers
*
@ -113,17 +113,18 @@ namespace sgpem
* \return The old value
*/
virtual bool set_notify_enabled(bool enabled = true);
protected:
typedef std::vector<HistoryObserver*> RegisteredObservers;
RegisteredObservers _observers;
virtual void notify_change();
protected:
typedef std::vector<HistoryObserver*> RegisteredObservers;
RegisteredObservers _observers;
virtual void notify_change();
private:
bool _notify;
}; //~ class History
}
; //~ class History
}//~ namespace sgpem

View file

@ -25,16 +25,17 @@
namespace sgpem
{
class History;
class History;
class HistoryObserver;
class SG_DLLEXPORT HistoryObserver
{
public:
virtual void update(const History& changed_history) = 0;
virtual ~HistoryObserver();
virtual void update(const History& changed_history) = 0;
virtual ~HistoryObserver();
}; // class HistoryObserver
}
; // class HistoryObserver
}//~ namespace sgpem

View file

@ -27,7 +27,7 @@
using namespace sgpem;
using namespace std;
void
void
HoltGraph::update(const History& changed_history)
{
const Environment& env = changed_history.get_last_environment();
@ -36,33 +36,33 @@ HoltGraph::update(const History& changed_history)
_resources.clear();
_active_threads.clear();
_active_requests.clear();
for(unsigned int pi = 0; pi < processes.size(); ++pi)
for (unsigned int pi = 0; pi < processes.size(); ++pi)
{
vector<Thread*> threads = processes[pi]->get_threads();
for(unsigned int ti = 0; ti < threads.size(); ++ti)
for (unsigned int ti = 0; ti < threads.size(); ++ti)
{
vector<Request*> requests = threads[ti]->get_requests();
for(unsigned int ri = 0; ri < requests.size(); ++ri)
for (unsigned int ri = 0; ri < requests.size(); ++ri)
{
Request& r = *requests[ri];
Request& r = *requests[ri];
if(r.get_state() == Request::state_allocated)
{
_active_requests.push_back(&r);
_active_threads.insert(&r.get_thread());
if (r.get_state() == Request::state_allocated)
{
_active_requests.push_back(&r);
_active_threads.insert(&r.get_thread());
vector<SubRequest*> subrequests = r.get_subrequests();
vector<SubRequest*> subrequests = r.get_subrequests();
for(unsigned int sri = 0; sri < subrequests.size(); ++sri)
{
Environment::resource_key_t key = subrequests[sri]->get_resource_key();
for (unsigned int sri = 0; sri < subrequests.size(); ++sri)
{
Environment::resource_key_t key = subrequests[sri]->get_resource_key();
_resources.insert(env.get_resources().find(key)->second);
}
}
_resources.insert(env.get_resources().find(key)->second);
}
}
}
}
}

View file

@ -43,9 +43,9 @@ namespace sgpem
typedef std::vector<const Resource*> Resources;
typedef std::vector<const Thread*> Threads;
typedef std::vector<const Request*> Requests;
HoltGraph();
virtual void update(const History& changed_history);
Resources get_resources() const;
@ -56,7 +56,8 @@ namespace sgpem
std::set<const Resource*> _resources;
std::set<const Thread*> _active_threads;
Requests _active_requests;
}; // class HistoryObserver
}
; // class HistoryObserver
}//~ namespace sgpem

View file

@ -25,6 +25,5 @@
using namespace sgpem;
InvalidPluginException::InvalidPluginException(const std::string& what) :
std::runtime_error(what)
{
}
std::runtime_error(what)
{}

View file

@ -31,7 +31,8 @@ namespace sgpem
{
public:
InvalidPluginException(const std::string& what);
}; //~ class InvalidPluginException
}
; //~ class InvalidPluginException
} //~ namespace sgpem

View file

@ -32,22 +32,22 @@ namespace sgpem
KeyFile::KeyFile()
{}
KeyFile::elements_iterator
KeyFile::elements_begin() const
{
return _elements.begin();
}
KeyFile::elements_iterator
KeyFile::elements_end() const
{
return _elements.end();
}
void
KeyFile::insert_key_value(const Glib::ustring& key, const Glib::ustring& value)
{
@ -55,62 +55,62 @@ namespace sgpem
_elements.insert(val_pair);
}
const Glib::ustring*
KeyFile::search_value(const Glib::ustring& key)
{
const Glib::ustring* ret = 0;
elements_iterator cur = _elements.find(key);
if(cur != elements_end())
if (cur != elements_end())
{
ret = &((*cur).second);
}
return ret;
}
void
KeyFile::file_read(const Glib::ustring& filename)
{
std::ifstream ifs(filename.c_str());
if(ifs)
if (ifs)
{
file_read(ifs);
} // end - if(ifs)
}
void
KeyFile::file_read(std::istream& is)
KeyFile::file_read(std::istream& is)
{
if(is)
if (is)
{
_elements.clear(); // erase all elements
char buff[KEY_FILE_BUF_LEN]; //
while(is)
while (is)
{
is.getline(buff, (KEY_FILE_BUF_LEN), '\n');
// if not a comment line...
if(*buff!='\0' && *buff!='#')
if (*buff != '\0' && *buff != '#')
{
char* pos = strchr(buff, '=');
if(pos!=0)
if (pos != 0)
{
*pos = '\0';
const Glib::ustring key(buff);
const Glib::ustring value(pos+1);
const Glib::ustring value(pos + 1);
insert_key_value(key, value);
}
} // end - if not a comment line...
} // end - while(ifs))
} // end - if(ifs)
}
void
KeyFile::file_write(const Glib::ustring& filename)
{
std::ofstream ofs(filename.c_str());
if(ofs)
if (ofs)
{
file_write(ofs);
} // end - if(ofs)
@ -119,10 +119,11 @@ namespace sgpem
void
KeyFile::file_write(std::ostream& os)
{
if(os)
if (os)
{
elements_iterator iter;
for(iter = elements_begin(); iter != elements_end(); iter++){
for (iter = elements_begin(); iter != elements_end(); iter++)
{
os << (*iter).first << "=" << (*iter).second << std::endl;
}
} // end - if(ofs)

View file

@ -31,7 +31,7 @@
namespace sgpem
{
class KeyFile;
/** \brief Save and retrieve configuration files formatted as key=value rows.
*
* This class handles files to store and retrieve configuration preferences
@ -57,7 +57,7 @@ namespace sgpem
/** \brief Elements iterator (begin of container) initializer. */
elements_iterator elements_begin() const;
/** \brief Elements iterator (end of container) initializer */
elements_iterator elements_end() const;
@ -67,7 +67,7 @@ namespace sgpem
* \param value The value associated to the key inserted.
*/
void insert_key_value(const Glib::ustring& key, const Glib::ustring& value);
/** \brief Insert a new key/value pair.
*
* \param key The key value to insert.
@ -81,20 +81,20 @@ namespace sgpem
* \param filename The file to read from.
*/
void file_read(const Glib::ustring& filename);
/** \brief Read a stream into this object.
*
* \param is the stream to read from.
*/
void file_read(std::istream& is);
/** \brief Write into a file from this object.
*
* \param filename The file to write to.
*/
void file_write(const Glib::ustring& filename);
/** \brief Write into a stream from this object.
*
* \param os the stream to write to.

View file

@ -25,69 +25,69 @@
using namespace sgpem;
Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
Glib::Module(identifier),
_enabled(false),
_id(identifier),
on_init_ptr(NULL),
on_exit_ptr(NULL),
describe_ptr(NULL),
get_name_ptr(NULL),
get_author_ptr(NULL),
get_version_ptr(NULL)
{
if(!*this) throw InvalidPluginException(Module::get_last_error());
Glib::Module(identifier),
_enabled(false),
_id(identifier),
on_init_ptr(NULL),
on_exit_ptr(NULL),
describe_ptr(NULL),
get_name_ptr(NULL),
get_author_ptr(NULL),
get_version_ptr(NULL)
{
if (!*this) throw InvalidPluginException(Module::get_last_error());
// Type-safeness here is an optional, as always. :-)
std::string prefix = "sgpem__Plugin__";
if(!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) &&
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
get_symbol(prefix + "describe", (void*&) describe_ptr) &&
get_symbol(prefix + "get_name", (void*&) get_name_ptr) &&
get_symbol(prefix + "get_author", (void*&) get_author_ptr) &&
get_symbol(prefix + "get_version", (void*&) get_version_ptr)))
if (!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) &&
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
get_symbol(prefix + "describe", (void*&) describe_ptr) &&
get_symbol(prefix + "get_name", (void*&) get_name_ptr) &&
get_symbol(prefix + "get_author", (void*&) get_author_ptr) &&
get_symbol(prefix + "get_version", (void*&) get_version_ptr)))
throw InvalidPluginException("incomplete/wrong exported interface");
}
void
void
Module::set_enabled(bool enabled)
{
if(_enabled == enabled)
if (_enabled == enabled)
return;
if(enabled)
if (enabled)
on_init_ptr();
else
on_exit_ptr();
_enabled = enabled;
}
Glib::ustring
Glib::ustring
Module::get_name() const
{
return get_name_ptr();
}
Glib::ustring
Glib::ustring
Module::get_author() const
{
return get_author_ptr();
}
Glib::ustring
Glib::ustring
Module::describe() const
{
return describe_ptr();
}
float
float
Module::get_version() const
{
return get_version_ptr();
}
bool
bool
Module::get_enabled() const
{
return _enabled;

View file

@ -31,29 +31,29 @@
namespace sgpem
{
class Module;
class SG_DLLEXPORT Module : public Glib::Module
{
public:
Module(const Glib::ustring& identifier) throw(InvalidPluginException);
void set_enabled(bool enabled = true);
Glib::ustring get_name() const;
Glib::ustring get_author() const;
Glib::ustring describe() const;
float get_version() const;
bool get_enabled() const;
private:
typedef void (*f_void)(void);
typedef Glib::ustring (*f_ustring)(void);
typedef float (*f_float)(void);
bool _enabled;
Glib::ustring _id;
@ -63,8 +63,9 @@ namespace sgpem
f_ustring get_name_ptr;
f_ustring get_author_ptr;
f_float get_version_ptr;
}; //~ class Module
}
; //~ class Module
} //~ namespace sgpem

View file

@ -46,13 +46,13 @@ extern "C"
SG_DLLEXPORT void sgpem__Plugin__on_init();
SG_DLLEXPORT void sgpem__Plugin__on_exit();
SG_DLLEXPORT const char* sgpem__Plugin__describe();
SG_DLLEXPORT const char* sgpem__Plugin__get_name();
SG_DLLEXPORT const char* sgpem__Plugin__describe();
SG_DLLEXPORT const char* sgpem__Plugin__get_name();
SG_DLLEXPORT const char* sgpem__Plugin__get_author();
SG_DLLEXPORT float sgpem__Plugin__get_version();
SG_DLLEXPORT float sgpem__Plugin__get_version();
// To know why SG_DLLEXPORT must go *before* the return
// value, see http://gcc.gnu.org/ml/gcc-help/2005-04/msg00340.html
// To know why SG_DLLEXPORT must go *before* the return
// value, see http://gcc.gnu.org/ml/gcc-help/2005-04/msg00340.html
#ifdef __cplusplus
}

View file

@ -38,53 +38,53 @@ using namespace std;
template class SG_DLLEXPORT Singleton<PluginManager>;
std::vector<Module*>
std::vector<Module*>
PluginManager::get_module_list() const
{
return _modules;
}
void
void
PluginManager::rescan_dirs()
{
{
Module* module = NULL;
for_each(_modules.begin(), _modules.end(),
memory::deletor<Module>());
for_each(_modules.begin(), _modules.end(),
memory::deletor<Module>());
_modules.clear();
GlobalPreferences& prefs = GlobalPreferences::get_instance();
GlobalPreferences::dir_iterator it = prefs.modules_dir_begin();
Glib::PatternSpec shared_obj(Glib::ustring("*.") + G_MODULE_SUFFIX);
while(it != prefs.modules_dir_end())
while (it != prefs.modules_dir_end())
{
Glib::Dir dir(*it);
for(Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it)
for (Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it)
{
// only attempt to load .so files
if(shared_obj.match(*dir_it))
if (shared_obj.match(*dir_it))
{
std::string module_path = Module::build_path(*it, *dir_it);
std::string module_path = Module::build_path(*it, *dir_it);
std::cerr << "Attempting to load module at path " << module_path << std::endl;
try
{
module = new Module(module_path);
std::cerr << "Attempting to load module at path " << module_path << std::endl;
try
{
module = new Module(module_path);
_modules.push_back(module);
std::cerr << "\tSuccess" << std::endl;
}
catch(InvalidPluginException e)
{
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
}
std::cerr << "\tSuccess" << std::endl;
}
catch (InvalidPluginException e)
{
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
}
}
}
it++;
}
}

View file

@ -35,7 +35,7 @@ namespace sgpem
namespace sgpem
{
class PluginManager;
class SG_DLLEXPORT PluginManager : public Singleton<PluginManager>
{
friend class Singleton<PluginManager>;
@ -47,9 +47,10 @@ namespace sgpem
private:
PluginManager();
std::vector<Module*> _modules;
std::vector<Module*> _modules;
}; //~ class PluginManager
}
; //~ class PluginManager
} //~ namespace sgpem

View file

@ -113,7 +113,7 @@ PolicyParameters::get_registered_string_parameters() const
/**
Tries to set the value to the parameter named "name".
\returns TRUE if the parameter named "name" has been previously registered and the value
\returns TRUE if the parameter named "name" has been previously registered and the value
stays in the range permitted by the parameter.
\returns FALSE in the other cases.
*/
@ -135,7 +135,7 @@ PolicyParameters::set_int(ustring name, const int& value)
/**
Tries to set the value to the parameter named "name".
\returns TRUE if the parameter named "name" has been previously registered and the value
\returns TRUE if the parameter named "name" has been previously registered and the value
stays in the range permitted by the parameter.
\returns FALSE in the other cases.
*/

View file

@ -27,48 +27,48 @@ using sgpem::ReadyQueue;
void
ReadyQueue::swap(position a, position b)
throw (std::out_of_range)
throw (std::out_of_range)
{
if(a == b) return;
// Usage of "at()" isn't casual:
// at() checks indexes, "[]" doesn't.
// Once we've done the check once, we
// can assume it's safe to use "[]";
// this for performance reasons.
Thread* temp = _scheds.at(a);
_scheds[a] = _scheds.at(b);
_scheds[b] = temp;
if (a == b) return;
// Usage of "at()" isn't casual:
// at() checks indexes, "[]" doesn't.
// Once we've done the check once, we
// can assume it's safe to use "[]";
// this for performance reasons.
Thread* temp = _scheds.at(a);
_scheds[a] = _scheds.at(b);
_scheds[b] = temp;
}
ReadyQueue::size_t
ReadyQueue::size() const
{
return _scheds.size();
return _scheds.size();
}
sgpem::Thread&
ReadyQueue::get_item_at(position index)
throw (std::out_of_range)
throw (std::out_of_range)
{
// Checks index access
return *_scheds.at(index);
// Checks index access
return *_scheds.at(index);
}
const sgpem::Thread&
ReadyQueue::get_item_at(position index) const
throw (std::out_of_range)
throw (std::out_of_range)
{
// Checks index access
return *_scheds.at(index);
// Checks index access
return *_scheds.at(index);
}
void
ReadyQueue::append(Thread& thread)
{
_scheds.push_back(&thread);
_scheds.push_back(&thread);
}
void

View file

@ -28,25 +28,25 @@
namespace sgpem
{
class ReadyQueue;
class Thread;
class ReadyQueue;
class Thread;
class SG_DLLEXPORT ReadyQueue
{
public:
typedef unsigned int position;
typedef unsigned int size_t;
typedef unsigned int position;
typedef unsigned int size_t;
void swap(position a, position b) throw (std::out_of_range);
size_t size() const;
Thread& get_item_at(position index) throw (std::out_of_range);
const Thread& get_item_at(position index) const throw (std::out_of_range);
void append(Thread& schedulable);
void swap(position a, position b) throw (std::out_of_range);
size_t size() const;
Thread& get_item_at(position index) throw (std::out_of_range);
const Thread& get_item_at(position index) const throw (std::out_of_range);
void append(Thread& schedulable);
void erase_first();
private:
typedef std::vector<Thread*> Threads;
Threads _scheds;
typedef std::vector<Thread*> Threads;
Threads _scheds;
};
}

View file

@ -40,13 +40,13 @@ namespace sgpem
state_allocated = 1 << 1,
state_future = 1 << 2,
state_exhausted = 1 << 3,
state_allocable = 1 << 4
state_allocable = 1 << 4
};
virtual ~Request();
virtual Thread& get_thread() = 0;
virtual bool operator==(const Request& op2) const = 0;
virtual std::vector<SubRequest*> get_subrequests() = 0;

View file

@ -34,7 +34,7 @@ namespace sgpem
public:
virtual ~Resource();
virtual bool operator==(const Resource& op2) const = 0;
virtual bool operator==(const Resource& op2) const = 0;
virtual Glib::ustring get_name() const = 0;
virtual unsigned int get_places() const = 0;

View file

@ -55,7 +55,7 @@ ResourcePoliciesGatekeeper::register_manager(ResourcePolicyManager* manager)
ManagerIterator end = _registered.end();
if(find(_registered.begin(), end, manager) == end)
if (find(_registered.begin(), end, manager) == end)
_registered.push_back(manager);
}
@ -67,7 +67,7 @@ ResourcePoliciesGatekeeper::unregister_manager(ResourcePolicyManager* manager)
ManagerIterator end = _registered.end();
ManagerIterator pos = find(_registered.begin(), end, manager);
if(pos != end)
if (pos != end)
{
deactivate_policies(**pos);
_registered.erase(pos);
@ -81,7 +81,7 @@ ResourcePoliciesGatekeeper::get_current_policy(History* history) throw(runtime_e
PolicyIterator policy = _active_policies.find(history);
if(policy == _active_policies.end())
if (policy == _active_policies.end())
throw runtime_error("No active policy associated with this "
"history is available.");
@ -97,8 +97,7 @@ ResourcePoliciesGatekeeper::activate_policy(History *history, ResourcePolicy* po
}
ResourcePoliciesGatekeeper::ResourcePoliciesGatekeeper()
{
}
{}
void
ResourcePoliciesGatekeeper::deactivate_policies(const ResourcePolicyManager& manager)
@ -107,18 +106,19 @@ ResourcePoliciesGatekeeper::deactivate_policies(const ResourcePolicyManager& man
const vector<ResourcePolicy*>& policies = manager.get_avail_policies();
for(AvailableIt avail_it = policies.begin(); avail_it != policies.end(); ++avail_it)
for (AvailableIt avail_it = policies.begin(); avail_it != policies.end(); ++avail_it)
{
// TODO isn't there a way to write more compact code by using
// library utilities?
for(PolicyIterator it = _active_policies.begin(); it != _active_policies.end();)
for (PolicyIterator it = _active_policies.begin(); it != _active_policies.end();)
{
// FIXME Is this necessary? It just came across my mind the idea that
// FIXME Is this necessary? It just came across my mind the idea that
// incrementing an invalid iterator might be unsafe...
PolicyIterator next = it; ++next;
if(it->second == *avail_it)
_active_policies.erase(it);
PolicyIterator next = it;
++next;
if (it->second == *avail_it)
_active_policies.erase(it);
it = next;
}

View file

@ -51,26 +51,26 @@ namespace sgpem
public:
typedef std::vector<ResourcePolicyManager*> Managers;
const Managers& get_registered() const;
void register_manager(ResourcePolicyManager* manager);
void register_manager(ResourcePolicyManager* manager);
void unregister_manager(ResourcePolicyManager* manager);
void unregister_manager(ResourcePolicyManager* manager);
ResourcePolicy& get_current_policy(History* history) throw(std::runtime_error);
void activate_policy(History* history, ResourcePolicy* policy);
void activate_policy(History* history, ResourcePolicy* policy);
private:
ResourcePoliciesGatekeeper(); //private constructor.
ResourcePoliciesGatekeeper(const ResourcePoliciesGatekeeper&);
ResourcePoliciesGatekeeper& operator=(const ResourcePoliciesGatekeeper&);
void deactivate_policies(const ResourcePolicyManager& manager);
std::vector<ResourcePolicyManager*> _registered;
std::map<History*, ResourcePolicy*> _active_policies;
std::map<History*, ResourcePolicy*> _active_policies;
};
}//~ namespace sgpem

View file

@ -56,8 +56,8 @@ namespace sgpem
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void enforce() throw(UserInterruptException) = 0;
virtual void enforce() throw(UserInterruptException) = 0;
/**
Gets a string description of the policy.

View file

@ -51,7 +51,7 @@ namespace sgpem
virtual ~Schedulable() = 0;
virtual bool operator==(const Schedulable& op2) const = 0;
virtual bool operator==(const Schedulable& op2) const = 0;
virtual Glib::ustring get_name() const = 0;

File diff suppressed because it is too large Load diff

View file

@ -41,7 +41,7 @@ namespace sgpem
namespace sgpem
{
class Scheduler;
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
@ -69,13 +69,13 @@ namespace sgpem
Resets the simulation to the initial state.
*/
void reset_status();
/**
Generates a new ReadyQueue representing the status of the processes
at the simulation instant next to the current one, and extends the History by
one instant with it.
/**
Generates a new ReadyQueue representing the status of the processes
at the simulation instant next to the current one, and extends the History by
one instant with it.
\return false If the simulation has ended, true otherwise
*/
\return false If the simulation has ended, true otherwise
*/
bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException);
/**
@ -84,9 +84,9 @@ namespace sgpem
*/
CPUPolicy* get_policy();
private:
private:
Scheduler(); //private constructor.
ReadyQueue* _ready_queue;
CPUPolicy* _policy;

View file

@ -68,29 +68,29 @@ namespace sgpem
BUG: a resource must be saved with her own associated key.
*/
virtual void from_resource(const Resource& obj) throw(SerializerError) = 0;
/**
\brief Add output to the serializer taking data from resource and key
BUG FIXED: This save a resource with her own associated key.
*/
virtual void from_resource(const Resource& obj, const Glib::ustring& key) throw(SerializerError) = 0;
/**
\brief Add output to the serializer taking data from process
*/
virtual void from_process(const Process& obj) throw(SerializerError) = 0;
/**
\brief Add output to the serializer taking data from thread
*/
virtual void from_thread(const Thread& obj) throw(SerializerError) = 0;
/**
\brief Add output to the serializer taking data from request
*/
virtual void from_request(const Request& obj) throw(SerializerError) = 0;
/**
\brief Add output to the serializer taking data from subrequest
*/

View file

@ -27,7 +27,7 @@ using namespace sgpem;
Serializer::Serializer()
{
SerializersGatekeeper::get_instance().register_serializer(this);
}
}
Serializer::~Serializer()
{}

View file

@ -34,7 +34,7 @@ namespace sgpem
class SG_DLLEXPORT Serializer
{
public:
Serializer();
Serializer();
virtual ~Serializer() = 0;
virtual void save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializerError) = 0;

View file

@ -25,6 +25,5 @@
using namespace sgpem;
SerializerError::SerializerError(const std::string& what) :
std::runtime_error(what)
{
}
std::runtime_error(what)
{}

View file

@ -31,7 +31,8 @@ namespace sgpem
{
public:
SerializerError(const std::string& what);
}; //~ class SerializerError
}
; //~ class SerializerError
} //~ namespace sgpem

View file

@ -52,7 +52,7 @@ SerializersGatekeeper::register_serializer(Serializer* serializer)
SerializerIterator end = _registered.end();
if(find(_registered.begin(), end, serializer) == end)
if (find(_registered.begin(), end, serializer) == end)
_registered.push_back(serializer);
}
@ -64,7 +64,7 @@ SerializersGatekeeper::unregister_serializer(Serializer* serializer)
SerializerIterator end = _registered.end();
SerializerIterator pos = find(_registered.begin(), end, serializer);
if(pos != end)
if (pos != end)
{
_registered.erase(pos);
}

View file

@ -30,8 +30,7 @@ template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
Simulation::~Simulation()
{
}
{}
Simulation&
Simulation::get_instance()

View file

@ -68,9 +68,9 @@ namespace sgpem
state_paused,
state_stopped
};
virtual ~Simulation();
/**
\brief Runs the simulation.
@ -109,7 +109,7 @@ namespace sgpem
\see set_timer()
*/
virtual int get_timer() const = 0;
/**
\brief This methods allows to change the way the simulation progresses.
@ -128,7 +128,7 @@ namespace sgpem
virtual bool get_mode() const = 0;
virtual state get_state() const = 0;
/**
\brief Setup the policy to be used by the system.
*/
@ -140,7 +140,7 @@ namespace sgpem
virtual CPUPolicy* get_policy() = 0;
virtual History& get_history() = 0;
/**
* Small kludge to avoid the need for declaration of ConcreteSimulation
* by the calling code of Simulation::get_instance()

View file

@ -23,7 +23,7 @@ using namespace sgpem;
StaticProcess::StaticProcess(const Glib::ustring& name, const unsigned int& arrival, const int& priority)
: StaticSchedulable(name, priority), _start_time(arrival)
: StaticSchedulable(name, priority), _start_time(arrival)
{}
@ -34,24 +34,24 @@ StaticProcess::~StaticProcess()
unsigned int
StaticProcess::get_arrival_time() const
{
return _start_time;
return _start_time;
}
unsigned int
StaticProcess::get_total_cpu_time() const
{
typedef std::vector<StaticThread*>::const_iterator ThreadIterator;
typedef std::vector<StaticThread*>::const_iterator ThreadIterator;
unsigned int result = 0;
for(ThreadIterator it = _threads.begin(); it != _threads.end(); it++)
result += (*it)->get_total_cpu_time();
return result;
unsigned int result = 0;
for (ThreadIterator it = _threads.begin(); it != _threads.end(); it++)
result += (*it)->get_total_cpu_time();
return result;
}
std::vector<StaticThread*>&
std::vector<StaticThread*>&
StaticProcess::get_threads()
{
return _threads;
return _threads;
}

View file

@ -47,17 +47,17 @@ namespace sgpem
/** \brief Destructor. */
virtual ~StaticProcess();
virtual unsigned int get_total_cpu_time() const;
virtual unsigned int get_arrival_time() const;
virtual unsigned int get_total_cpu_time() const;
virtual unsigned int get_arrival_time() const;
// Does the job also of add_thread() and remove_thread(). :-)
// Since we're touching backend internals, we can do this safely
// (because we know what we're doing, isn't it?)
virtual std::vector<StaticThread*>& get_threads();
// Does the job also of add_thread() and remove_thread(). :-)
// Since we're touching backend internals, we can do this safely
// (because we know what we're doing, isn't it?)
virtual std::vector<StaticThread*>& get_threads();
private:
unsigned int _start_time;
std::vector<StaticThread*> _threads;
unsigned int _start_time;
std::vector<StaticThread*> _threads;
};
}

View file

@ -31,14 +31,14 @@ StaticRequest::StaticRequest(StaticThread* thread,
_thread(thread), _instant(instant)
{
assert(thread != NULL);
_thread->get_requests().push_back(this);
_thread->get_requests().push_back(this);
}
StaticRequest::~StaticRequest()
{
typedef std::vector<StaticRequest*> Requests;
Requests& siblings = _thread->get_requests();
siblings.erase(find(siblings.begin(), siblings.end(), this));
typedef std::vector<StaticRequest*> Requests;
Requests& siblings = _thread->get_requests();
siblings.erase(find(siblings.begin(), siblings.end(), this));
}
unsigned int

View file

@ -68,7 +68,7 @@ namespace sgpem
* user, that allows it to be quickly recognized.
*/
virtual const Glib::ustring& get_name() const;
private:
Glib::ustring _name;
int _priority;

View file

@ -38,7 +38,7 @@ StaticSubRequest::StaticSubRequest(resource_key_t resource_key,
}
StaticSubRequest::~StaticSubRequest()
StaticSubRequest::~StaticSubRequest()
{
// See comment in constructor.

View file

@ -29,23 +29,23 @@ using namespace std;
StaticThread::StaticThread(const Glib::ustring& name,
StaticProcess& process,
unsigned int cpu_time,
unsigned int cpu_time,
unsigned int arrival_time,
int base_priority) :
StaticSchedulable(name, base_priority),
_start_time_delta(arrival_time),
_required_cpu_time(cpu_time),
_start_time_delta(arrival_time),
_required_cpu_time(cpu_time),
_process(&process)
{
process.get_threads().push_back(this);
process.get_threads().push_back(this);
}
StaticThread::~StaticThread()
{
typedef std::vector<StaticThread*> Threads;
Threads& siblings = _process->get_threads();
siblings.erase(find(siblings.begin(), siblings.end(), this));
typedef std::vector<StaticThread*> Threads;
Threads& siblings = _process->get_threads();
siblings.erase(find(siblings.begin(), siblings.end(), this));
}
@ -70,5 +70,5 @@ StaticThread::get_process()
std::vector<StaticRequest*>&
StaticThread::get_requests()
{
return _static_requests;
return _static_requests;
}

View file

@ -42,11 +42,11 @@ namespace sgpem
public:
StaticThread(const Glib::ustring& name,
StaticProcess& process,
unsigned int cpu_time,
unsigned int cpu_time,
unsigned int arrival_time = 0,
int base_priority = 0);
virtual ~StaticThread();
virtual ~StaticThread();
virtual unsigned int get_total_cpu_time() const;
@ -54,11 +54,11 @@ namespace sgpem
virtual StaticProcess& get_process();
// Caller can use directly the vector instead that
// the "remove_request()" and "add_request()" method
// of the design. Since this class is internal to the
// backend anyway, this is okay.
virtual std::vector<StaticRequest*>& get_requests();
// Caller can use directly the vector instead that
// the "remove_request()" and "add_request()" method
// of the design. Since this class is internal to the
// backend anyway, this is okay.
virtual std::vector<StaticRequest*>& get_requests();
private:
StaticThread(const StaticThread&);

View file

@ -29,210 +29,210 @@ using Glib::ustring;
namespace sgpem
{
/* Force template instantiation to allow visibility outside this DSO */
template SG_DLLEXPORT int string_to<int>(const Glib::ustring&);
template SG_DLLEXPORT float string_to<float>(const Glib::ustring&);
/* Force template instantiation to allow visibility outside this DSO */
template SG_DLLEXPORT int string_to<int>(const Glib::ustring&);
template SG_DLLEXPORT float string_to<float>(const Glib::ustring&);
// Specialized further down in this file:
// template SG_DLLEXPORT bool string_to<bool>(const Glib::ustring&);
// Specialized further down in this file:
// template SG_DLLEXPORT bool string_to<bool>(const Glib::ustring&);
/**
\brief A function that converts a Unicode string to an integer value
The string can contain ONLY digits and the "minus" character.
\returns TRUE if the string is well formatted
\returns FALSE otherwise
*/
bool
string_to_int(const ustring& str, int& num)
{
static const ustring allvalid = "0123456789-";
static const ustring digits = "0123456789";
/**
\brief A function that converts a Unicode string to an integer value
// the string can't be empty
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
return false;
The string can contain ONLY digits and the "minus" character.
//checks if the string contains only digits
if (str.find_first_not_of(allvalid) < str.length())
return false;
if (str.substr(1).find_first_not_of(digits) < str.length() - 1)
return false;
num = 0;
int multiplier = 1, val;
int start; //the position of the biggest digit
if (str[0] == '-')
start = 1;
else
start = 0;
for (int pos = str.length() - 1; pos >= start ; pos--)
\returns TRUE if the string is well formatted
\returns FALSE otherwise
*/
bool
string_to_int(const ustring& str, int& num)
{
val = str[pos] - 48; //the INTEGER value of the digit
num += val * multiplier;
multiplier *= 10;
}
//if there is the minus then multiply for -1
if (start == 1)
num *= -1;
return true;
}
static const ustring allvalid = "0123456789-";
static const ustring digits = "0123456789";
template <typename T>
T
string_to(const ustring& str) throw(domain_error)
{
if(tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens"));
// the string can't be empty
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
return false;
istringstream iss(str);
//checks if the string contains only digits
if (str.find_first_not_of(allvalid) < str.length())
return false;
if (str.substr(1).find_first_not_of(digits) < str.length() - 1)
return false;
iss.exceptions(ios_base::failbit | ios_base::badbit);
T value;
try
{
iss >> value;
}
catch(ios_base::failure e)
{
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
iss.exceptions(ios_base::goodbit);
if(iss.peek() != istringstream::traits_type::eof())
throw domain_error(_("incorrect number format"));
return value;
}
template <>
SG_DLLEXPORT bool
string_to<bool>(const Glib::ustring& str) throw(domain_error)
{
if(tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens"));
istringstream iss(str);
iss.exceptions(ios_base::failbit | ios_base::badbit);
bool value;
try
{
iss >> boolalpha >> value;
}
catch(ios_base::failure e)
{
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
iss.exceptions(ios_base::goodbit);
if(iss.peek() != istringstream::traits_type::eof())
throw domain_error(_("incorrect boolean"));
return value;
}
/**
\brief A function that converts an integer value to an Unicode string
*/
void
int_to_string(const int& num, ustring& str)
{
if (num == 0)
{
str = '0';
return;
}
str = "";
int val = num;
bool negative = (val < 0) ? true : false;
if (negative) val *= -1;
while (true)
{
str = char(val % 10 + 48) + str;
if (val > 1 && val / 10 != 0)
val /= 10;
num = 0;
int multiplier = 1, val;
int start; //the position of the biggest digit
if (str[0] == '-')
start = 1;
else
break;
start = 0;
for (int pos = str.length() - 1; pos >= start ; pos--)
{
val = str[pos] - 48; //the INTEGER value of the digit
num += val * multiplier;
multiplier *= 10;
}
//if there is the minus then multiply for -1
if (start == 1)
num *= -1;
return true;
}
if (negative)
str = '-' + str;
}
void
float_to_string(const float& f, Glib::ustring& str)
{
stringstream ss;
ss << f;
char p[20];
ss.getline(p, 20);
str = p;
}
template <typename T>
T
string_to(const ustring& str) throw(domain_error)
{
if (tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens"));
void
string_to_float(const Glib::ustring& str, float& f)
{
stringstream ss;
ss << str;
ss >> f;
}
istringstream iss(str);
iss.exceptions(ios_base::failbit | ios_base::badbit);
T value;
try
{
iss >> value;
}
catch (ios_base::failure e)
{
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
iss.exceptions(ios_base::goodbit);
if (iss.peek() != istringstream::traits_type::eof())
throw domain_error(_("incorrect number format"));
return value;
}
template <>
SG_DLLEXPORT bool
string_to<bool>(const Glib::ustring& str) throw(domain_error)
{
if (tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens"));
istringstream iss(str);
iss.exceptions(ios_base::failbit | ios_base::badbit);
bool value;
try
{
iss >> boolalpha >> value;
}
catch (ios_base::failure e)
{
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
iss.exceptions(ios_base::goodbit);
if (iss.peek() != istringstream::traits_type::eof())
throw domain_error(_("incorrect boolean"));
return value;
}
/**
\brief A function that converts an integer value to an Unicode string
*/
void
int_to_string(const int& num, ustring& str)
{
if (num == 0)
{
str = '0';
return;
}
str = "";
int val = num;
bool negative = (val < 0) ? true : false;
if (negative) val *= -1;
while (true)
{
str = char(val % 10 + 48) + str;
if (val > 1 && val / 10 != 0)
val /= 10;
else
break;
}
if (negative)
str = '-' + str;
}
void
float_to_string(const float& f, Glib::ustring& str)
{
stringstream ss;
ss << f;
char p[20];
ss.getline(p, 20);
str = p;
}
void
string_to_float(const Glib::ustring& str, float& f)
{
stringstream ss;
ss << str;
ss >> f;
}
// helper function for tokenize()
static void
add_token(Tokens& tokens, const ustring& token)
{
if(token.size() > 0)
tokens.push_back(token);
}
Tokens
tokenize(const ustring& str)
{
istringstream iss(str);
Tokens tokens;
while(iss)
static void
add_token(Tokens& tokens, const ustring& token)
{
ustring token;
iss >> token;
ustring::size_type index;
// for the SET command, parse the assigment symbol as
// a separate token
do
{
index = token.find('=');
if(index != ustring::npos)
{
add_token(tokens, token.substr(0, index));
add_token(tokens, "=");
// the second argument can safely be out of range
token = token.substr(index + 1, token.size());
}
}
while(index != ustring::npos);
add_token(tokens, token);
if (token.size() > 0)
tokens.push_back(token);
}
return tokens;
}
Tokens
tokenize(const ustring& str)
{
istringstream iss(str);
Tokens tokens;
while (iss)
{
ustring token;
iss >> token;
ustring::size_type index;
// for the SET command, parse the assigment symbol as
// a separate token
do
{
index = token.find('=');
if (index != ustring::npos)
{
add_token(tokens, token.substr(0, index));
add_token(tokens, "=");
// the second argument can safely be out of range
token = token.substr(index + 1, token.size());
}
}
while (index != ustring::npos);
add_token(tokens, token);
}
return tokens;
}
}

View file

@ -31,7 +31,7 @@
namespace sgpem
{
typedef std::vector<Glib::ustring> Tokens;
/**\brief This function tries to convert a string into an integer value.
The string can contain only digits and the minus character (for negative numbers).

View file

@ -34,24 +34,24 @@ namespace sgpem
class SG_DLLEXPORT SubRequest
{
public:
typedef int resource_key_t;
typedef Request::state state;
typedef int resource_key_t;
typedef Request::state state;
virtual ~SubRequest();
virtual bool operator==(const SubRequest& op2) const = 0;
virtual bool operator==(const SubRequest& op2) const = 0;
virtual resource_key_t get_resource_key() const = 0;
virtual unsigned int get_length() const = 0;
virtual unsigned int get_length() const = 0;
virtual int get_queue_position() const = 0;
virtual state get_state() const = 0;
virtual state get_state() const = 0;
virtual unsigned int get_remaining_time() const = 0;
virtual unsigned int get_remaining_time() const = 0;
virtual Request& get_request() = 0;
virtual Request& get_request() = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};

View file

@ -38,7 +38,7 @@ namespace sgpem
public:
virtual ~Thread();
virtual Process& get_process() = 0;
virtual Process& get_process() = 0;
virtual std::vector<Request*> get_requests() = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};