- Pretty-indenting code

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@674 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-06-29 08:44:30 +00:00
parent 7aecc910ba
commit 6b27a8461b
94 changed files with 3073 additions and 3066 deletions

View file

@ -29,63 +29,63 @@ using namespace sgpem;
using std::vector;
DynamicProcess::DynamicProcess(StaticProcess* core) :
DynamicSchedulable(*core)
{
}
DynamicSchedulable(*core)
{}
DynamicProcess::DynamicProcess(const DynamicProcess &other) :
Schedulable(), DynamicSchedulable(other), Process()
Schedulable(), DynamicSchedulable(other), Process()
{
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)
_dynamic_threads.push_back(new DynamicThread(*(*it)));
}
std::vector<Thread*>
std::vector<Thread*>
DynamicProcess::get_threads()
{
return vector<Thread*>(_dynamic_threads.begin(), _dynamic_threads.end());
}
Schedulable::state
Schedulable::state
DynamicProcess::get_state() const
{
typedef vector<DynamicThread*>::const_iterator ThreadIt;
static const int uninitialized = -1;
assert(_dynamic_threads.size() > 0);
state result = state_future;
int next_thread_starts_at = uninitialized;
for(ThreadIt it = _dynamic_threads.begin(); it != _dynamic_threads.end(); ++it)
{
state thread_state = (*it)->get_state();
// This is the logic behind the code:
// If there is at least one running thread, the result is
// If there is at least one running thread, the result is
// running. If not, it may be either blocked, ready, future or terminated.
// We have these cases (a state takes precedence over some other one):
// (a) if a thread is running, return immediately state_running
// (b) if a thread is ready, puts unconditionally result as state_ready,
// (b) if a thread is ready, puts unconditionally result as state_ready,
// and continue iterating (to see if there's a running thread)
// (c) if a thread is blocked, and result is not state_ready, result
// (c) if a thread is blocked, and result is not state_ready, result
// becomes state_blocked, and continue iterating (to see if there are
// ready or running threads)
// (d) if a thread is future, and result is not state_ready or
// (d) if a thread is future, and result is not state_ready or
// state_blocked, put result as state_future, and remember
// when the next thread will start (d1) (see at the end of this
// method for the rationale (d2)). Then continue iterating.
// (e) else (if all threads are state_terminated) put result as
// (e) else (if all threads are state_terminated) put result as
// state_terminated.
// TODO Is this OK? Must be tested...
switch(thread_state) {
switch(thread_state)
{
case state_running: // (a)
return state_running;
case state_ready: // (b)
@ -98,9 +98,9 @@ DynamicProcess::get_state() const
result = state_future;
int thread_starts_at = (*it)->get_arrival_time();
if(next_thread_starts_at == uninitialized) // (d1)
next_thread_starts_at = thread_starts_at;
next_thread_starts_at = thread_starts_at;
else
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
next_thread_starts_at = std::min(thread_starts_at, next_thread_starts_at);
continue;
default: // (e)
result = state_terminated;
@ -108,7 +108,7 @@ DynamicProcess::get_state() const
} //~ "for" iterating over threads
// Now check if a "hole" happens: if result == state_future, but the next
// Now check if a "hole" happens: if result == state_future, but 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:
@ -121,13 +121,13 @@ DynamicProcess::get_state() const
return result;
}
void
void
DynamicProcess::remove_thread(Thread* thread)
{
assert(thread != NULL);
vector<DynamicThread*>::iterator it;
it = std::find(_dynamic_threads.begin(), _dynamic_threads.end(), thread);
if(it != _dynamic_threads.end())
@ -137,7 +137,7 @@ DynamicProcess::remove_thread(Thread* thread)
// (which is?)
delete *it;
}
}
void
@ -148,9 +148,9 @@ DynamicProcess::add_thread(DynamicThread* thread)
_dynamic_threads.push_back(thread);
}
void
void
DynamicProcess::serialize(SerializeVisitor& translator) const
{
//FIXME write this code. I'm predictable, I know
}

View file

@ -41,20 +41,20 @@ namespace sgpem
public:
DynamicProcess(StaticProcess* core);
DynamicProcess(const DynamicProcess &other);
std::vector<Thread*> get_threads();
state get_state() const;
void remove_thread(Thread* thread);
void add_thread(DynamicThread* thread);
void serialize(SerializeVisitor& translator) const;
private:
std::vector<DynamicThread*> _dynamic_threads;
};
}
#endif

View file

@ -28,41 +28,41 @@
using namespace sgpem;
using std::vector;
DynamicRequest::DynamicRequest(StaticRequest *core,
DynamicRequest::DynamicRequest(StaticRequest *core,
DynamicThread* owner) :
_static_request(core), _dynamic_thread(owner),
_state(state_ready)
_static_request(core), _dynamic_thread(owner),
_state(state_ready)
{
assert(core != NULL);
assert(owner != NULL);
}
vector<SubRequest*>
vector<SubRequest*>
DynamicRequest::get_subrequests()
{
return vector<SubRequest*>(_dynamic_subrequests.begin(), _dynamic_subrequests.end());
}
DynamicThread&
DynamicThread&
DynamicRequest::get_thread()
{
return *_dynamic_thread;
}
unsigned int
unsigned int
DynamicRequest::get_instant() const
{
return _static_request->get_instant();
}
Request::state
Request::state
DynamicRequest::get_current_state() const
{
return _state;
}
void
void
DynamicRequest::add_subrequest(DynamicSubRequest* subreq)
{
assert(subreq != NULL);
@ -70,23 +70,23 @@ DynamicRequest::add_subrequest(DynamicSubRequest* subreq)
_dynamic_subrequests.push_back(subreq);
}
void
void
DynamicRequest::remove_subrequest(SubRequest* subreq)
{
assert(subreq != NULL);
vector<DynamicSubRequest*>::iterator it;
it = std::find(_dynamic_subrequests.begin(), _dynamic_subrequests.end(), subreq);
if(it != _dynamic_subrequests.end())
{
_dynamic_subrequests.erase(it);
delete *it;
_dynamic_subrequests.erase(it);
delete *it;
}
}
void
void
DynamicRequest::serialize(SerializeVisitor& translator) const
{
// Let a drunk monkey write this code ;P

View file

@ -37,7 +37,7 @@ namespace sgpem
class DynamicThread;
class SubRequest;
class DynamicSubRequest;
class DynamicRequest : public Request
{
public:
@ -62,7 +62,7 @@ namespace sgpem
state _state;
std::vector<DynamicSubRequest*> _dynamic_subrequests;
};
}
#endif

View file

@ -26,23 +26,22 @@
using namespace sgpem;
DynamicResource::DynamicResource(StaticResource *core) :
_static_resource(core)
{
}
_static_resource(core)
{}
Glib::ustring
Glib::ustring
DynamicResource::get_name() const
{
return _static_resource->get_name();
}
unsigned int
unsigned int
DynamicResource::get_places() const
{
return _static_resource->get_places();
}
void
void
DynamicResource::serialize(SerializeVisitor& translator) const
{
// Let a drunk monkey write this code ;P

View file

@ -33,12 +33,12 @@ namespace sgpem
class DynamicResource;
class SerializeVisitor;
class StaticResource;
class DynamicResource : public Resource
{
public:
DynamicResource(StaticResource *core);
Glib::ustring get_name() const;
unsigned int get_places() const;
@ -47,7 +47,7 @@ namespace sgpem
private:
memory::smart_ptr<StaticResource> _static_resource;
};
}
#endif

View file

@ -26,11 +26,10 @@ using namespace sgpem;
using namespace std;
DynamicSchedulable::DynamicSchedulable(StaticSchedulable& obj) :
_time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1),
_last_release(-1), _priority_push(0), _last(-1),
_my_state(state_future)
{
}
_time_left(obj.get_total_cpu_time()), _ref(&obj), _last_acquisition(-1),
_last_release(-1), _priority_push(0), _last(-1),
_my_state(state_future)
{}
bool
DynamicSchedulable::operator==(const DynamicSchedulable& dx) const
@ -38,37 +37,37 @@ DynamicSchedulable::operator==(const DynamicSchedulable& dx) const
return _ref == dx._ref;
}
Glib::ustring
Glib::ustring
DynamicSchedulable::get_name() const
{
return _ref->get_name();
}
unsigned int
unsigned int
DynamicSchedulable::get_arrival_time() const
{
return _ref->get_arrival_time();
}
int
int
DynamicSchedulable::get_base_priority() const
{
return _ref->get_priority();
}
unsigned int
unsigned int
DynamicSchedulable::get_total_cpu_time() const
{
return _ref->get_total_cpu_time();
}
int
int
DynamicSchedulable::get_priority_push() const
{
return _priority_push;
}
void
void
DynamicSchedulable::set_priority_push(int new_value)
{
_priority_push = new_value;
@ -80,37 +79,37 @@ DynamicSchedulable::get_current_priority() const
return get_base_priority() + get_priority_push();
}
unsigned int
unsigned int
DynamicSchedulable::get_remaining_time() const
{
return _time_left;
}
void
void
DynamicSchedulable::decrease_remaining_time()
{
--_time_left;
}
int
int
DynamicSchedulable::get_last_acquisition() const
{
return _last_acquisition;
}
void
void
DynamicSchedulable::set_last_acquisition(int instant)
{
_last_acquisition = instant;
}
int
int
DynamicSchedulable::get_last_release() const
{
return _last_release;
}
void
void
DynamicSchedulable::set_last_release(int instant)
{
_last_release = instant;

View file

@ -46,7 +46,7 @@ namespace sgpem
/** \brief Object constructor */
DynamicSchedulable(StaticSchedulable& obj);
//DynamicSchedulable(const DynamicSchedulable& obj); //copy constructor
//DynamicSchedulable(const DynamicSchedulable& obj); //copy constructor
/** \brief Verify if two instances represents the same situation
*
@ -85,11 +85,11 @@ namespace sgpem
void set_last_release(int instant);
/*
/*
FIXME
all following methods are deprecated, drop them
*/
/** \brief Returns the remaining CPU time */
int get_cpu_time_left() const;
@ -112,9 +112,8 @@ namespace sgpem
void set_state(state s);
void serialize(SerializeVisitor& translator) const
{
}
{}
/** \brief Returns a pointer to the schedulable object
*
* This function returns a pointer to the actual schedable object
@ -131,7 +130,7 @@ namespace sgpem
int _last_release;
int _priority_push;
//FIXME deprecated stuff used by deprecated methods
//FIXME deprecated stuff used by deprecated methods
int _last;
state _my_state;
};

View file

@ -26,46 +26,46 @@
using namespace sgpem;
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
DynamicResource* resource) :
_static_subrequest(core), _dynamic_resource(resource),
_queue_position(-1)
_static_subrequest(core), _dynamic_resource(resource),
_queue_position(-1)
{
assert(core != NULL);
assert(resource != NULL);
}
DynamicResource&
DynamicResource&
DynamicSubRequest::get_resource()
{
return *_dynamic_resource;
}
unsigned int
unsigned int
DynamicSubRequest::get_places() const
{
return _static_subrequest->get_places();
}
unsigned int
unsigned int
DynamicSubRequest::get_length() const
{
return _static_subrequest->get_length();
}
int
int
DynamicSubRequest::get_queue_position() const
{
return _queue_position;
}
void
void
DynamicSubRequest::set_queue_position(int position)
{
_queue_position = position;
}
void
void
DynamicSubRequest::serialize(SerializeVisitor& translator) const
{
//blah blah blah TODO

View file

@ -34,13 +34,13 @@ namespace sgpem
class SerializeVisitor;
class Resource;
class StaticSubRequest;
class DynamicSubRequest : public SubRequest
{
public:
DynamicSubRequest(StaticSubRequest* core, DynamicResource* resource);
DynamicResource& get_resource();
DynamicResource& get_resource();
unsigned int get_places() const;
@ -48,7 +48,7 @@ namespace sgpem
int get_queue_position() const;
void set_queue_position(int position);
void serialize(SerializeVisitor& translator) const;
private:
@ -56,7 +56,7 @@ namespace sgpem
DynamicResource* _dynamic_resource;
int _queue_position;
};
}
#endif

View file

@ -29,18 +29,17 @@ using namespace sgpem;
using std::vector;
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent) :
DynamicSchedulable(*core), _state(state_future), _parent(parent)
{
}
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent) :
DynamicSchedulable(*core), _state(state_future), _parent(parent)
{}
DynamicThread::DynamicThread(const DynamicThread &other) :
Schedulable(), DynamicSchedulable(other), Thread()
Schedulable(), DynamicSchedulable(other), Thread()
{
typedef vector<DynamicRequest*>::const_iterator ReqIt;
const vector<DynamicRequest*>& other_req = other._dynamic_requests;
_state = other._state;
_parent = other._parent;
@ -48,19 +47,19 @@ DynamicThread::DynamicThread(const DynamicThread &other) :
_dynamic_requests.push_back(new DynamicRequest(*(*it)));
}
DynamicProcess&
DynamicProcess&
DynamicThread::get_process()
{
return *_parent;
}
Schedulable::state
Schedulable::state
DynamicThread::get_state() const
{
return _state;
}
Schedulable::state
Schedulable::state
DynamicThread::set_state(state new_state)
{
state old_state = _state;
@ -69,19 +68,19 @@ DynamicThread::set_state(state new_state)
return old_state;
}
vector<Request*>
vector<Request*>
DynamicThread::get_requests()
{
return vector<Request*>(_dynamic_requests.begin(), _dynamic_requests.end());
}
void
void
DynamicThread::remove_request(Request* request)
{
assert(request != NULL);
vector<DynamicRequest*>::iterator it;
it = std::find(_dynamic_requests.begin(), _dynamic_requests.end(), request);
if(it != _dynamic_requests.end())
@ -89,10 +88,10 @@ DynamicThread::remove_request(Request* request)
_dynamic_requests.erase(it);
delete *it;
}
}
void
void
DynamicThread::add_request(DynamicRequest* request)
{
assert(request != NULL);

View file

@ -45,9 +45,9 @@ namespace sgpem
public:
DynamicThread(StaticThread* core, DynamicProcess* parent);
DynamicThread(const DynamicThread &other);
DynamicProcess& get_process();
state get_state() const;
state set_state(state new_state);
@ -55,17 +55,17 @@ namespace sgpem
std::vector<Request*> get_requests();
void remove_request(Request* request);
void add_request(DynamicRequest* request);
void serialize(SerializeVisitor& translator) const;
private:
state _state;
std::vector<DynamicRequest*> _dynamic_requests;
DynamicProcess* _parent;
};
}
#endif

View file

@ -36,41 +36,41 @@ GlobalPreferences::GlobalPreferences()
GlobalPreferences::dir_iterator
GlobalPreferences::policies_dir_begin() const
{
return _pol_dirs.begin();
return _pol_dirs.begin();
}
GlobalPreferences::dir_iterator
GlobalPreferences::policies_dir_end() const
{
return _pol_dirs.end();
return _pol_dirs.end();
}
GlobalPreferences::dir_iterator
GlobalPreferences::modules_dir_begin() const
{
return _mod_dirs.begin();
return _mod_dirs.begin();
}
GlobalPreferences::dir_iterator
GlobalPreferences::modules_dir_end() const
{
return _mod_dirs.end();
return _mod_dirs.end();
}
void
void
GlobalPreferences::add_modules_dir(const Glib::ustring& moddir)
{
_mod_dirs.insert(_mod_dirs.begin(), moddir);
_mod_dirs.insert(_mod_dirs.begin(), moddir);
}
void
void
GlobalPreferences::add_policies_dir(const Glib::ustring& poldir)
{
_pol_dirs.insert(_pol_dirs.begin(), poldir);
_pol_dirs.insert(_pol_dirs.begin(), poldir);
}

View file

@ -29,37 +29,39 @@
// Do not include complete template definition here:
#include "singleton.hh"
namespace sgpem {
class GlobalPreferences;
namespace sgpem
{
class GlobalPreferences;
}
#include "config.h"
namespace sgpem {
namespace sgpem
{
class SG_DLLEXPORT GlobalPreferences : public Singleton<GlobalPreferences>
{
friend class Singleton<GlobalPreferences>;
public:
typedef std::vector<Glib::ustring>::const_iterator dir_iterator;
typedef std::vector<Glib::ustring>::const_iterator dir_iterator;
dir_iterator modules_dir_begin() const;
dir_iterator modules_dir_end() const;
dir_iterator modules_dir_begin() const;
dir_iterator modules_dir_end() const;
dir_iterator policies_dir_begin() const;
dir_iterator policies_dir_end() const;
dir_iterator policies_dir_begin() const;
dir_iterator policies_dir_end() const;
void add_modules_dir(const Glib::ustring& moddir);
void add_policies_dir(const Glib::ustring& poldir);
void add_modules_dir(const Glib::ustring& moddir);
void add_policies_dir(const Glib::ustring& poldir);
private:
GlobalPreferences();
GlobalPreferences(const GlobalPreferences&);
GlobalPreferences& operator=(const GlobalPreferences&);
std::vector<Glib::ustring> _mod_dirs;
std::vector<Glib::ustring> _pol_dirs;
};
private:
GlobalPreferences();
GlobalPreferences(const GlobalPreferences&);
GlobalPreferences& operator=(const GlobalPreferences&);
std::vector<Glib::ustring> _mod_dirs;
std::vector<Glib::ustring> _pol_dirs;
};
}
#endif

View file

@ -38,13 +38,14 @@ template class SG_DLLEXPORT smart_ptr<SchedulableQueue>;
template class SG_DLLEXPORT smart_ptr<DynamicSchedulable>;
/**
The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS
of the simulation which must begin at instant -1 and live for 1 instant.
The constructor sets _total_time_elapsed to -1: this permits to insert the INITIAL STATUS
of the simulation which must begin at instant -1 and live for 1 instant.
*/
History::History() //private constructor.
:_total_time_elapsed(-1)
History::History() //private constructor.
:
_total_time_elapsed(-1)
{}
/**
Returns a pointer to a copy of the DynamicSchedulable object relative to this instant.
@ -54,38 +55,38 @@ History::History() //private constructor.
smart_ptr<DynamicSchedulable>
History::get_scheduled_at(int time) const
{
if (time > _total_time_elapsed || time < 0) //out of range
if (time > _total_time_elapsed || time < 0) //out of range
return smart_ptr<DynamicSchedulable>(NULL);
//look for a runing entity
smart_ptr<SchedulableQueue> p = get_simulation_status_at(time);
for (uint i = 0; i < p->size(); i++)
if (p->get_item_at(i)->get_state() == DynamicSchedulable::state_running)
return smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(p->get_item_at(i))));
if (p->get_item_at(i)->get_state() == DynamicSchedulable::state_running)
return smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(p->get_item_at(i))));
return smart_ptr<DynamicSchedulable>(NULL);
}
/**
Returns a pointer to a copy of the SimulationStatus object relative to this instant or NULL
if time is out of range.
if time is out of range.
*/
smart_ptr<SchedulableQueue>
History::get_simulation_status_at(int time) const
History::get_simulation_status_at(int time) const
{
if (time > _total_time_elapsed || time < 0) //out of range
return smart_ptr<SchedulableQueue>(NULL);
int trascorso = -1;
for(vector<Slice>::const_iterator i=_slices.begin(); i < _slices.end(); i++)
if (time <= trascorso + i->get_duration()) //FOUND!!
return smart_ptr<SchedulableQueue>(new SchedulableQueue(*i->get_simulation_status()));
else //Go on...
trascorso += i->get_duration();
if (time > _total_time_elapsed || time < 0) //out of range
return smart_ptr<SchedulableQueue>(NULL);
int trascorso = -1;
for(vector<Slice>::const_iterator i = _slices.begin(); i < _slices.end(); i++)
if (time <= trascorso + i->get_duration()) //FOUND!!
return smart_ptr<SchedulableQueue>(new SchedulableQueue(*i->get_simulation_status()));
else //Go on...
trascorso += i->get_duration();
//never reached if all slices are CONTIGUOUS (ans THIS shoul be!!)!!!
return smart_ptr<SchedulableQueue>(NULL);
return smart_ptr<SchedulableQueue>(NULL);
}
int
@ -108,42 +109,42 @@ History::enqueue_slice(const SchedulableQueue& status)
notify();
return;
}
//check the last slice
Slice& last = _slices[_slices.size()-1];
if (last.get_simulation_status()->has_same_objects(status)) //increments the duration by ONE unit
if (last.get_simulation_status()->has_same_objects(status)) //increments the duration by ONE unit
{
last.set_duration(last.get_duration()+1);
last.set_duration(last.get_duration() + 1);
}
else //insert a new slice CONTIGUOUS to the last one
{
_slices.push_back(Slice(last.get_started_at() + last.get_duration(), 1, status));
}
_total_time_elapsed++; //one instant is passed...
else //insert a new slice CONTIGUOUS to the last one
{
_slices.push_back(Slice(last.get_started_at() + last.get_duration(), 1, status));
}
_total_time_elapsed++; //one instant is passed...
notify();
}
/**
Removes all the informations about the simulation following the specified instant.
Ex. truncate_at(0); removes all scheduled slices
Ex. truncate_at(-1); removes all scheduled slices and the initial status
Removes all the informations about the simulation following the specified instant.
Ex. truncate_at(0); removes all scheduled slices
Ex. truncate_at(-1); removes all scheduled slices and the initial status
*/
void
History::truncate_at(int instant)
{
vector<Slice>::iterator i = _slices.begin();
//reach the instant
while (i != _slices.end())
if (i->get_started_at() < instant)
i++;
else
{
//replaces the current vector with the "trimmed" one.
_slices = vector<Slice>(_slices.begin(),i);
_total_time_elapsed = instant;
break;
}
notify();
vector<Slice>::iterator i = _slices.begin();
//reach the instant
while (i != _slices.end())
if (i->get_started_at() < instant)
i++;
else
{
//replaces the current vector with the "trimmed" one.
_slices = vector<Slice>(_slices.begin(), i);
_total_time_elapsed = instant;
break;
}
notify();
}

View file

@ -38,65 +38,65 @@
namespace sgpem
{
/** \brief Manages the history of the simulation
Manages the history of the simulation from the instant 0 to the current time,
i.e. permits to know the state of each schedulable object inside this time interval.
In particoular it's possible to know which entity was running at a precise moment.
In a future iteration it will be possible to revert the entire simulation to a state
present in the history ("undo operation")
/** \brief Manages the history of the simulation
Manages the history of the simulation from the instant 0 to the current time,
i.e. permits to know the state of each schedulable object inside this time interval.
In particoular it's possible to know which entity was running at a precise moment.
In a future iteration it will be possible to revert the entire simulation to a state
present in the history ("undo operation")
*/
class History;
class SG_DLLEXPORT History : public Singleton<History>, public ObservedSubject
class SG_DLLEXPORT History : public Singleton<History>, public ObservedSubject
{
friend class Singleton<History>;
public:
/**
Gets the \ref Schedulable object running at the specified time.
\param time The inquired time instant.
\return The Schedulable object running at the given time.
*/
virtual memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const;
/**
Gets the \ref Schedulable object running at the specified time.
\param time The inquired time instant.
\return The Schedulable object running at the given time.
*/
virtual memory::smart_ptr<sgpem::DynamicSchedulable> get_scheduled_at(int time) const;
/**
Gets the status of simulation at the specified time.
\param time The inquired time instant.
\return The list of Schedulable status objects at the specified time.
*/
virtual memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
/**
Gets the status of simulation at the specified time.
\param time The inquired time instant.
\return The list of Schedulable status objects at the specified time.
*/
virtual memory::smart_ptr<sgpem::SchedulableQueue> get_simulation_status_at(int time) const;
/**
Gets the current time.
\return The current history time.
*/
virtual int get_current_time() const;
/**
Gets the current time.
\return The current history time.
*/
virtual int get_current_time() const;
/**
Sets the status of simulation at the current time.
\param status The list of \ref Schedulable status objects at the current time.
*/
virtual void enqueue_slice(const sgpem::SchedulableQueue& status);
/**
Sets the status of simulation at the current time.
\param status The list of \ref Schedulable status objects at the current time.
*/
virtual void enqueue_slice(const sgpem::SchedulableQueue& status);
/**
Remove all data in History following the specified time.
\param instant Desired cutting time.
*/
virtual void truncate_at(int instant);
/**
Remove all data in History following the specified time.
\param instant Desired cutting time.
*/
virtual void truncate_at(int instant);
protected:
History(); //private constructor.
History(const History&);
History& operator=(const History&);
History(); //private constructor.
History(const History&);
History& operator=(const History&);
private:
int _total_time_elapsed;
std::vector<sgpem::Slice> _slices;
int _total_time_elapsed;
std::vector<sgpem::Slice> _slices;
};
}//~ namespace sgpem
#endif //HISTORY_H

View file

@ -23,25 +23,24 @@ using namespace std;
using namespace sgpem;
ObservedSubject::~ObservedSubject()
{
}
ObservedSubject::~ObservedSubject()
{}
/**
Calls update() in each Observer
*/
void
void
ObservedSubject::notify()
{
for(vector<Observer*>::iterator i = _attached.begin(); i < _attached.end(); i++)
(*i)->update();
(*i)->update();
}
/**
Attachs an Observer to this ObservedSubject.
*/
void
void
ObservedSubject::attach(Observer* o)
{
_attached.push_back(o);
@ -51,14 +50,14 @@ ObservedSubject::attach(Observer* o)
Detachs the observer from this ObservedSubject.
*/
bool
bool
ObservedSubject::detach(Observer* o)
{
vector<Observer*>::iterator i = find(_attached.begin(), _attached.end(), o);
if (i == _attached.end())
return false;
_attached.erase(i); // FOUND and POPPED
_attached.erase(i); // FOUND and POPPED
return true;
}

View file

@ -35,8 +35,8 @@ namespace sgpem
/** \brief Represents an observed entity.
Abstract class which represents an observed entity. It calls Update() in all Observer objects
which are attached to it. See the "Observer Pattern" for more informations.
Abstract class which represents an observed entity. It calls Update() in all Observer objects
which are attached to it. See the "Observer Pattern" for more informations.
*/
class SG_DLLEXPORT ObservedSubject
{
@ -44,23 +44,23 @@ namespace sgpem
virtual ~ObservedSubject() = 0;
/**
This method calls Update() on each attached Observer. It should be called when the internal state
of the ObservedSubject is changed and Observers have to be updated.
This method calls Update() on each attached Observer. It should be called when the internal state
of the ObservedSubject is changed and Observers have to be updated.
*/
void notify();
/**
\brief Adds an Observer object to the internal list.
\brief Adds an Observer object to the internal list.
*/
void attach(sgpem::Observer*);
/**
\brief Removes an Observer object from the internal list.
\brief Removes an Observer object from the internal list.
\returns TRUE if the Observer object has been previously attached (is found in the list);
\returns FALSE otherwise.
\returns TRUE if the Observer object has been previously attached (is found in the list);
\returns FALSE otherwise.
*/
bool detach(sgpem::Observer*);

View file

@ -25,40 +25,41 @@
#include <glibmm/ustring.h>
/** \file plugin.hh
/** \file plugin.hh
* All loadable modules that want to act as plugins
* for SGPEMv2 should implement this interface. */
namespace sgpem
namespace sgpem
{
/** \brief The interface a specific plugin should implement
*
* Only the header file containing this interface
* should be provided by the backend library. Every plugin
* will then implement its set of static functions.
* Thus every plugin will export these very symbols
* outside its DSO.
*/
class SG_DLLEXPORT Plugin
{
/** \brief Called when a plugin is loaded and enabled
*
* Sets up the plugin's initial state and
* performs needed actions before its usage can start.
*/
static void on_init();
/** \brief The interface a specific plugin should implement
*
* Only the header file containing this interface
* should be provided by the backend library. Every plugin
* will then implement its set of static functions.
* Thus every plugin will export these very symbols
* outside its DSO.
*/
class SG_DLLEXPORT Plugin
{
/** \brief Called when a plugin is loaded and enabled
*
* Sets up the plugin's initial state and
* performs needed actions before its usage can start.
*/
static void on_init();
static void on_exit();
static Glib::ustring describe();
static Glib::ustring get_name();
static Glib::ustring get_author();
static float get_version();
static void on_exit();
static Glib::ustring describe();
static Glib::ustring get_name();
static Glib::ustring get_author();
static float get_version();
private:
SG_DLLLOCAL Plugin();
}; //~ class Plugin
private:
SG_DLLLOCAL Plugin();
}
; //~ class Plugin
} //~ namespace sgpem
#endif
#endif

View file

@ -36,7 +36,7 @@ using std::find;
using std::runtime_error;
using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
// Explicit template instantiation to allow to export symbols from the DSO.
template class SG_DLLEXPORT Singleton<PoliciesGatekeeper>;
typedef vector<PolicyManager*>::iterator ManagerIterator;
@ -52,7 +52,7 @@ void
PoliciesGatekeeper::register_manager(PolicyManager* manager)
{
assert(manager != NULL);
ManagerIterator end = _registered.end();
if(find(_registered.begin(), end, manager) == end)
@ -63,7 +63,7 @@ void
PoliciesGatekeeper::unregister_manager(PolicyManager* manager)
{
assert(manager != NULL);
ManagerIterator end = _registered.end();
ManagerIterator pos = find(_registered.begin(), end, manager);
@ -80,11 +80,11 @@ PoliciesGatekeeper::get_current_policy(History* history) throw(runtime_error)
assert(history != NULL);
ActiveIterator policy = _active_policies.find(history);
if(policy == _active_policies.end())
throw runtime_error("No active policy associated with this "
"history is available.");
return policy->second;
}
@ -107,31 +107,30 @@ PoliciesGatekeeper::activate_policy(History *history, Policy* policy)
}
PoliciesGatekeeper::PoliciesGatekeeper()
{
}
{}
void
void
PoliciesGatekeeper::deactivate_policies(PolicyManager* manager)
{
typedef vector<Policy*>::iterator PolicyIterator;
vector<Policy*> avail_policies = manager->get_avail_policies();
PolicyIterator avail_it = avail_policies.begin();
PolicyIterator avail_end = avail_policies.end();
for(; avail_it != avail_end; ++avail_it)
{
// TODO isn't there a way to write more compact code by using
// library utilities?
// TODO isn't there a way to write more compact code by using
// library utilities?
ActiveIterator act_it = _active_policies.begin();
for(; act_it != _active_policies.end(); ++act_it)
{
if(act_it->second == *avail_it)
{
act_it->second->deactivate();
_active_policies.erase(act_it);
act_it->second->deactivate();
_active_policies.erase(act_it);
}
}
}

View file

@ -40,7 +40,7 @@ namespace sgpem
{
class PoliciesGatekeeper;
/** \brief FIXME document me
/** \brief FIXME document me
*/
@ -50,28 +50,28 @@ namespace sgpem
friend class Singleton<PoliciesGatekeeper>;
public:
std::vector<PolicyManager*> get_registered() const;
std::vector<PolicyManager*> get_registered() const;
void register_manager(PolicyManager* manager);
void register_manager(PolicyManager* manager);
void unregister_manager(PolicyManager* manager);
void unregister_manager(PolicyManager* manager);
Policy* get_current_policy(History* history) throw(std::runtime_error);
Policy* get_current_policy(History* history) throw(std::runtime_error);
void activate_policy(History* history, Policy* policy);
void activate_policy(History* history, Policy* policy);
private:
PoliciesGatekeeper(); //private constructor.
PoliciesGatekeeper(); //private constructor.
PoliciesGatekeeper(const PoliciesGatekeeper&);
PoliciesGatekeeper& operator=(const PoliciesGatekeeper&);
// Deactivates active policies managed by the specified manager.
void deactivate_policies(PolicyManager* manager);
std::vector<PolicyManager*> _registered;
std::map<History*, Policy*> _active_policies;
void deactivate_policies(PolicyManager* manager);
std::vector<PolicyManager*> _registered;
std::map<History*, Policy*> _active_policies;
};
}//~ namespace sgpem
#endif //POLICIES_GATEKEEPER_HH

View file

@ -24,18 +24,17 @@ using namespace sgpem;
using namespace memory;
Policy::~Policy()
{
}
{}
int
Policy::get_id() const
{
return _id;
return _id;
}
PolicyParameters&
Policy::get_parameters()
{
return _parameters;
return _parameters;
}

View file

@ -33,106 +33,106 @@
namespace sgpem
{
enum policy_sorts_type
{
policy_sorts_threads,
policy_sorts_processes
};
enum policy_sorts_type
{
policy_sorts_threads,
policy_sorts_processes
};
class Policy;
/** \brief
It's a Strategy wich stay for a scheduling algorithm.
It implements the related scheduling policy.
Its goal is, usually, to keep a list of Schedulable objects
mantained in a SchedulableQueue.
*/
class SG_DLLEXPORT Policy
{
public:
virtual ~Policy();
/**
Initialize the inner components of the policy.
class Policy;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void configure() throw(UserInterruptException) = 0;
/** \brief
It's a Strategy wich stay for a scheduling algorithm.
It implements the related scheduling policy.
Its goal is, usually, to keep a list of Schedulable objects
mantained in a SchedulableQueue.
*/
class SG_DLLEXPORT Policy
{
public:
/**
Sort the \ref SchedulableQueue object that contain all the Schedulable objects
(Processes, Threads) still active managed by the scheduler.
virtual ~Policy();
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void sort_queue() const throw(UserInterruptException) = 0;
/**
Initialize the inner components of the policy.
/**
Gets the unique identifier (id) of this Policy.
\return The Policy id.
*/
int get_id() const;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void configure() throw(UserInterruptException) = 0;
/**
Gets a string description of the policy.
/**
Sort the \ref SchedulableQueue object that contain all the Schedulable objects
(Processes, Threads) still active managed by the scheduler.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return String description of the policy.
*/
virtual Glib::ustring get_description() const = 0;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
*/
virtual void sort_queue() const throw(UserInterruptException) = 0;
virtual Glib::ustring get_name() const = 0;
/**
Gets the unique identifier (id) of this Policy.
\return The Policy id.
*/
int get_id() const;
/**
Tell if this policy is preemptible.
/**
Gets a string description of the policy.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return True if this policy is preemptible.
*/
virtual bool is_pre_emptive() const throw(UserInterruptException) = 0;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return String description of the policy.
*/
virtual Glib::ustring get_description() const = 0;
/**
Gets the time quantum for the policy.
virtual Glib::ustring get_name() const = 0;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return Time quantum for the policy.
*/
virtual int get_time_slice() const throw(UserInterruptException) = 0;
/**
Tell if this policy is preemptible.
/**
Tell what kind of entities are scheduled by this policy.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return True if this policy is preemptible.
*/
virtual bool is_pre_emptive() const throw(UserInterruptException) = 0;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return A SortsType value identifying the desired type for the objects
composing the queue passed to the sort_queue method.
*/
virtual policy_sorts_type wants() const throw(UserInterruptException) = 0;
/**
Gets the time quantum for the policy.
virtual void activate() = 0;
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return Time quantum for the policy.
*/
virtual int get_time_slice() const throw(UserInterruptException) = 0;
virtual void deactivate() = 0;
/**
Gets the parameters related with this policy.
/**
Tell what kind of entities are scheduled by this policy.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return The policy parameters.
*/
PolicyParameters& get_parameters();
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return A SortsType value identifying the desired type for the objects
composing the queue passed to the sort_queue method.
*/
virtual policy_sorts_type wants() const throw(UserInterruptException) = 0;
virtual void activate() = 0;
virtual void deactivate() = 0;
/**
Gets the parameters related with this policy.
Because it's a pure virtual method, must be re-implemented
in concrete derived classes.
\return The policy parameters.
*/
PolicyParameters& get_parameters();
protected:
PolicyParameters _parameters;
int _id;
};
protected:
PolicyParameters _parameters;
int _id;
};
}//~ namespace sgpem

View file

@ -29,7 +29,7 @@ PolicyManager::PolicyManager()
{
//FIXME remove this when get_registered_manager is dropped
_registered = this;
PoliciesGatekeeper::get_instance().register_manager(this);
}
@ -39,11 +39,11 @@ PolicyManager::~PolicyManager()
// This check is necessary:
//FIXME remove this when get_registered_manager is dropped
if(_registered == this) _registered = NULL;
PoliciesGatekeeper::get_instance().unregister_manager(this);
}
PolicyManager&
PolicyManager&
PolicyManager::get_registered_manager()
{
return *_registered;

View file

@ -28,60 +28,60 @@
namespace sgpem
{
class PolicyManager;
class PolicyManager;
/**
PolicyManager is the Abstract Factory for \ref Policy objects.
*/
class SG_DLLEXPORT PolicyManager
{
public:
/** \brief PolicyManager constructor
*
* Saves ``this'' pointer into the _registered attribute, so it can access
* it when requested. This is done so that concrete subclasses can be defined
* even if they are found in external dynamic modules not known at compile time.
*
* For the moment, just an instance of PolicyManager can be saved. This will
* be expanded in next milestones.
*/
PolicyManager();
class SG_DLLEXPORT PolicyManager
{
public:
/** \brief PolicyManager constructor
*
* Saves ``this'' pointer into the _registered attribute, so it can access
* it when requested. This is done so that concrete subclasses can be defined
* even if they are found in external dynamic modules not known at compile time.
*
* For the moment, just an instance of PolicyManager can be saved. This will
* be expanded in next milestones.
*/
PolicyManager();
virtual ~PolicyManager() = 0;
virtual ~PolicyManager() = 0;
/**
Gets THE policy (the only today) used.
Next versions will implement some other kind.
\return A reference to the policy.
FIXME deprecated
*/
//virtual Policy& get_policy() = 0;
/**
Gets THE policy (the only today) used.
Next versions will implement some other kind.
\return A reference to the policy.
FIXME deprecated
*/
//virtual Policy& get_policy() = 0;
/**
Init (or reset if yet initialized) the manager.
FIXME deprecated
*/
virtual void init() = 0;
/**
Init (or reset if yet initialized) the manager.
FIXME deprecated
*/
virtual void init() = 0;
virtual std::vector<Policy*> get_avail_policies() = 0;
virtual std::vector<Policy*> get_avail_policies() = 0;
/** \brief Get the registered manager instance
* FIXME deprecated
*
* \return The registered policy manager instance.
*/
static PolicyManager& get_registered_manager();
/** \brief Get the registered manager instance
* FIXME deprecated
*
* \return The registered policy manager instance.
*/
static PolicyManager& get_registered_manager();
protected:
virtual void collect_policies() = 0;
std::vector<Policy*> _policies;
protected:
virtual void collect_policies() = 0;
std::vector<Policy*> _policies;
private:
/** A pointer to the registered instance */
static PolicyManager* _registered;
};
private:
/** A pointer to the registered instance */
static PolicyManager* _registered;
};
} //~ namespace sgpem
#endif

View file

@ -24,198 +24,198 @@ using namespace sgpem;
using Glib::ustring;
/**
Register a new parameter of type integer.
If there is a parameter with the same name and type it will be overwritten.
Register a new parameter of type integer.
If there is a parameter with the same name and type it will be overwritten.
*/
void
PolicyParameters::register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value)
void
PolicyParameters::register_int(Glib::ustring name, const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value)
{
//there is a parameter with the same name!!
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
if (i != int_map.end())
int_map.erase(i);
map<ustring, Parameter<int> >::value_type v(name, Parameter<int>(name, default_value, lower_bound, upper_bound, required, default_value));
int_map.insert(v);
//there is a parameter with the same name!!
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
if (i != int_map.end())
int_map.erase(i);
map<ustring, Parameter<int> >::value_type v(name, Parameter<int>(name, default_value, lower_bound, upper_bound, required, default_value));
int_map.insert(v);
}
/**
Register a new parameter of type float.
If there is a parameter with the same name and type it will be overwritten.
Register a new parameter of type float.
If there is a parameter with the same name and type it will be overwritten.
*/
void
PolicyParameters::register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value)
void
PolicyParameters::register_float(Glib::ustring name, const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value)
{
//there is a parameter with the same name!!
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
if (i != float_map.end())
float_map.erase(i);
map<ustring, Parameter<float> >::value_type v(name, Parameter<float>(name, default_value, lower_bound, upper_bound, required, default_value));
float_map.insert(v);
//there is a parameter with the same name!!
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
if (i != float_map.end())
float_map.erase(i);
map<ustring, Parameter<float> >::value_type v(name, Parameter<float>(name, default_value, lower_bound, upper_bound, required, default_value));
float_map.insert(v);
}
/**
Register a new parameter of type string.
If there is a parameter with the same name and type it will be overwritten.
Register a new parameter of type string.
If there is a parameter with the same name and type it will be overwritten.
*/
void
void
PolicyParameters::register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value)
{
//there is a parameter with the same name!!
map<ustring, Parameter<Glib::ustring> >::iterator i = string_map.find(name);
if (i != string_map.end())
string_map.erase(i);
map<ustring, Parameter<Glib::ustring> >::value_type v(name, Parameter<Glib::ustring>(name, default_value, "", "", required, default_value));
string_map.insert(v);
//there is a parameter with the same name!!
map<ustring, Parameter<Glib::ustring> >::iterator i = string_map.find(name);
if (i != string_map.end())
string_map.erase(i);
map<ustring, Parameter<Glib::ustring> >::value_type v(name, Parameter<Glib::ustring>(name, default_value, "", "", required, default_value));
string_map.insert(v);
}
/**
Deletes all registred parameters.
Deletes all registred parameters.
*/
void
PolicyParameters::clear()
{
int_map.clear();
float_map.clear();
string_map.clear();
int_map.clear();
float_map.clear();
string_map.clear();
}
/**
Retruns a copy of the map containing all registered integer parameters.
Retruns a copy of the map containing all registered integer parameters.
*/
map<ustring, PolicyParameters::Parameter<int> >
PolicyParameters::get_registered_int_parameters() const
{
return int_map;
return int_map;
}
/**
Retruns a copy of the map containing all registered float parameters.
Retruns a copy of the map containing all registered float parameters.
*/
map<ustring, PolicyParameters::Parameter<float> >
PolicyParameters::get_registered_float_parameters() const
PolicyParameters::get_registered_float_parameters() const
{
return float_map;
return float_map;
}
/**
Retruns a copy of the map containing all registered string parameters.
Retruns a copy of the map containing all registered string parameters.
*/
map<ustring, PolicyParameters::Parameter<ustring> >
PolicyParameters::get_registered_string_parameters() const
{
return string_map;
return string_map;
}
/**
Tries to set the value to the parameter named "name".
\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.
Tries to set the value to the parameter named "name".
\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.
*/
bool
PolicyParameters::set_int(ustring name, const int& value)
{
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
if (i == int_map.end())
//the parameter doesn't exist!!
return false;
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
return false;
i->second.set_value(value);
return true;
map<ustring, Parameter<int> >::iterator i = int_map.find(name);
if (i == int_map.end())
//the parameter doesn't exist!!
return false;
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
return false;
i->second.set_value(value);
return true;
}
/**
Tries to set the value to the parameter named "name".
\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.
Tries to set the value to the parameter named "name".
\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.
*/
bool
PolicyParameters::set_float(ustring name, const float& value)
{
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
if (i == float_map.end())
//the parameter doesn't exist!!
return false;
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
return false;
i->second.set_value(value);
return true;
map<ustring, Parameter<float> >::iterator i = float_map.find(name);
if (i == float_map.end())
//the parameter doesn't exist!!
return false;
if (value < i->second.get_lower_bound() || value > i->second.get_upper_bound())
return false;
i->second.set_value(value);
return true;
}
/**
Tries to set the value to the parameter named "name". For the type "string" there are
no upper/lower bound limitations.
\returns TRUE if the parameter named "name" has been previously registered.
\returns FALSE in the other case.
Tries to set the value to the parameter named "name". For the type "string" there are
no upper/lower bound limitations.
\returns TRUE if the parameter named "name" has been previously registered.
\returns FALSE in the other case.
*/
bool
PolicyParameters::set_string(ustring name, const ustring& value)
{
map<ustring, Parameter<ustring> >::iterator i = string_map.find(name);
if (i == string_map.end())
//the parameter doesn't exist!!
return false;
i->second.set_value(value);
return true;
map<ustring, Parameter<ustring> >::iterator i = string_map.find(name);
if (i == string_map.end())
//the parameter doesn't exist!!
return false;
i->second.set_value(value);
return true;
}
/**
Looks for a parameter of integer type named "name".
\returns The value of the parameter
\throws A PolicyParametersException if the parameter has not been found.
Looks for a parameter of integer type named "name".
\returns The value of the parameter
\throws A PolicyParametersException if the parameter has not been found.
*/
int
PolicyParameters::get_int(ustring name) const
{
map<ustring, Parameter<int> >::const_iterator i = int_map.find(name);
if (i == int_map.end())
throw PolicyParametersException("Unregistred parameter");
else
return i->second.get_value();
map<ustring, Parameter<int> >::const_iterator i = int_map.find(name);
if (i == int_map.end())
throw PolicyParametersException("Unregistred parameter");
else
return i->second.get_value();
}
/**
Looks for a parameter of float type named "name".
\returns The value of the parameter
\throws A PolicyParametersException if the parameter has not been found.
Looks for a parameter of float type named "name".
\returns The value of the parameter
\throws A PolicyParametersException if the parameter has not been found.
*/
float
PolicyParameters::get_float(ustring name) const
{
map<ustring, Parameter<float> >::const_iterator i = float_map.find(name);
if (i == float_map.end())
throw PolicyParametersException("Unregistred parameter");
else
return i->second.get_value();
map<ustring, Parameter<float> >::const_iterator i = float_map.find(name);
if (i == float_map.end())
throw PolicyParametersException("Unregistred parameter");
else
return i->second.get_value();
}
/**
Looks for a parameter of string type named "name".
\returns The value of the parameter
\throws A PolicyParametersException if the parameter has not been found.
Looks for a parameter of string type named "name".
\returns The value of the parameter
\throws A PolicyParametersException if the parameter has not been found.
*/
ustring
PolicyParameters::get_string(ustring name) const
{
map<ustring, Parameter<ustring> >::const_iterator i = string_map.find(name);
if (i == string_map.end())
throw PolicyParametersException("Unregistred parameter");
else
return i->second.get_value();
map<ustring, Parameter<ustring> >::const_iterator i = string_map.find(name);
if (i == string_map.end())
throw PolicyParametersException("Unregistred parameter");
else
return i->second.get_value();
}

View file

@ -30,221 +30,220 @@
namespace sgpem
{
class PolicyParametersException : public std::runtime_error
{
public:
PolicyParametersException(char* msg): std::runtime_error(msg) {}
};
class PolicyParameters;
class PolicyParametersException : public std::runtime_error
{
public:
PolicyParametersException(char* msg): std::runtime_error(msg) {}};
class PolicyParameters;
/** \brief Represents all configurable parameters of a single scheduling policy.
Represents all configurable parameters of a single scheduling policy. Is is used by the user
interface: it serves to know which parameters the user will be asked for.
Each Policy object owns only one instance of this class.
Represents all configurable parameters of a single scheduling policy. Is is used by the user
interface: it serves to know which parameters the user will be asked for.
Each Policy object owns only one instance of this class.
*/
class SG_DLLEXPORT PolicyParameters
{
public:
template<typename T>
class Parameter;
class SG_DLLEXPORT PolicyParameters
{
public:
template<typename T>
class Parameter;
//#######################################
//########## methods to CREATE PARAMETERS
//#######################################
//#######################################
//########## methods to CREATE PARAMETERS
//#######################################
/**\brief Registers an INTEGER parameter.
/**\brief Registers an INTEGER parameter.
This method adds an INTEGER parameter to the list of parameters represented by this class.
This method adds an INTEGER parameter to the list of parameters represented by this class.
\warning If a parameter named \e name already exists it will be replaced by this one.
\param name The name of the parameter. This string will be used to refer to this parameter
in the methods set_int(...), get_int(...) and get_registered_int_parameters(...).
\param lower_bound The lower limitation of the value which can be set with set_int(...).
\param upper_bound The upper limitation of the value which can be set with set_int(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0).
*/
void register_int(Glib::ustring name,const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0);
\warning If a parameter named \e name already exists it will be replaced by this one.
\param name The name of the parameter. This string will be used to refer to this parameter
in the methods set_int(...), get_int(...) and get_registered_int_parameters(...).
\param lower_bound The lower limitation of the value which can be set with set_int(...).
\param upper_bound The upper limitation of the value which can be set with set_int(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0).
*/
void register_int(Glib::ustring name, const int& lower_bound, const int& upper_bound, const bool& required, const int& default_value = 0);
/**\brief Registers a FLOAT parameter.
/**\brief Registers a FLOAT parameter.
This method adds a FLOAT parameter to the list of parameters represented by this class.
This method adds a FLOAT parameter to the list of parameters represented by this class.
\warning If a parameter named \e name already exists it will be replaced by this one.
\param name The name of the parameter. This string will be used to refer to this parameter
in the methods set_float(...), get_float(...) and get_registered_float_parameters(...).
\param lower_bound The lower limitation of the value which can be set with set_int(...).
\param upper_bound The upper limitation of the value which can be set with set_int(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0.0f).
*/
void register_float(Glib::ustring name,const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f);
\warning If a parameter named \e name already exists it will be replaced by this one.
\param name The name of the parameter. This string will be used to refer to this parameter
in the methods set_float(...), get_float(...) and get_registered_float_parameters(...).
\param lower_bound The lower limitation of the value which can be set with set_int(...).
\param upper_bound The upper limitation of the value which can be set with set_int(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0.0f).
*/
void register_float(Glib::ustring name, const float& lower_bound, const float& upper_bound, const bool& required, const float& default_value = 0.0f);
/**\brief Registers a STRING parameter.
/**\brief Registers a STRING parameter.
This method adds a STRING parameter to the list of parameters represented by this class.
Note that there are no limitations to the value thath this parameter can assume.
This method adds a STRING parameter to the list of parameters represented by this class.
Note that there are no limitations to the value thath this parameter can assume.
\warning If a parameter named \e name already exists it will be replaced by this one.
\param name The name of the parameter. This string will be used to refer to this parameter
in the methods set_string(...), get_string(...) and get_registered_string_parameters(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to the empty string).
*/
void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = "");
\warning If a parameter named \e name already exists it will be replaced by this one.
\param name The name of the parameter. This string will be used to refer to this parameter
in the methods set_string(...), get_string(...) and get_registered_string_parameters(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to the empty string).
*/
void register_string(Glib::ustring name, const bool& required, const Glib::ustring& default_value = "");
/**\brief Deletes all registered parameters.
*/
void clear();
/**\brief Deletes all registered parameters.
*/
void clear();
//#############################################
//###### methods to RETRIEVE CREATED PARAMETERS
//#############################################
//#############################################
//###### methods to RETRIEVE CREATED PARAMETERS
//#############################################
/** \brief Permits to retrieve all registered INTEGER parameters
\returns a map of INTEGER parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<int> > get_registered_int_parameters() const;
/** \brief Permits to retrieve all registered INTEGER parameters
\returns a map of INTEGER parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<int> > get_registered_int_parameters() const;
/** \brief Permits to retrieve all registered FLOAT parameters
\returns a map of FLOAT parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<float> > get_registered_float_parameters() const;
/** \brief Permits to retrieve all registered FLOAT parameters
\returns a map of FLOAT parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<float> > get_registered_float_parameters() const;
/** \brief Permits to retrieve all registered STRING parameters
\returns a map of STRING parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<Glib::ustring> > get_registered_string_parameters() const;
/** \brief Permits to retrieve all registered STRING parameters
\returns a map of STRING parameters identfied by their name
*/
std::map<Glib::ustring, Parameter<Glib::ustring> > get_registered_string_parameters() const;
//#############################################
//###### methods to SET the VALUE of PARAMETERS
//#############################################
//#############################################
//###### methods to SET the VALUE of PARAMETERS
//#############################################
/** \brief Sets the value of a registred INTEGER parameter
/** \brief Sets the value of a registred INTEGER parameter
Permits to change the value of a parameter identified by "name"
Permits to change the value of a parameter identified by "name"
\returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_int(Glib::ustring name, const int& value);
\returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_int(Glib::ustring name, const int& value);
/** \brief Sets the value of a registred FLOAT parameter
/** \brief Sets the value of a registred FLOAT parameter
Permits to change the value of a parameter identified by "name"
Permits to change the value of a parameter identified by "name"
\returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_float(Glib::ustring name, const float& value);
\returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_float(Glib::ustring name, const float& value);
/** \brief Sets the value of a registred STRING parameter
/** \brief Sets the value of a registred STRING parameter
Permits to change the value of a parameter identified by "name"
Permits to change the value of a parameter identified by "name"
\returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_string(Glib::ustring name, const Glib::ustring& value);
\returns TRUE if the specified "name" maps to a registered parameter and if "value" doesn't
exceed the bounds proper to that parameter
\returns FALSE if the parameter named "name" is not found or if "value" exceeds the bounds
*/
bool set_string(Glib::ustring name, const Glib::ustring& value);
//#############################################
//###### methods to GET the VALUE of PARAMETERS
//#############################################
//#############################################
//###### methods to GET the VALUE of PARAMETERS
//#############################################
/** \brief Returns the value of an INTEGER parameter
\returns the INTEGER value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
int get_int(Glib::ustring name) const;
/** \brief Returns the value of an INTEGER parameter
\returns the INTEGER value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
int get_int(Glib::ustring name) const;
/** \brief Returns the value of an FLOAT parameter
\returns the FLOAT value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
float get_float(Glib::ustring name) const;
/** \brief Returns the value of an FLOAT parameter
\returns the FLOAT value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
float get_float(Glib::ustring name) const;
/** \brief Returns the value of an STRING parameter
\returns the STRING value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
Glib::ustring get_string(Glib::ustring name) const;
/** \brief Returns the value of an STRING parameter
\returns the STRING value of the parameter named \e name
\throws PolicyParametersException if the parameter named \e name has not been registered
*/
Glib::ustring get_string(Glib::ustring name) const;
private:
std::map<Glib::ustring, Parameter<int> > int_map;
std::map<Glib::ustring, Parameter<float> > float_map;
std::map<Glib::ustring, Parameter<Glib::ustring> > string_map;
};
private:
std::map<Glib::ustring, Parameter<int> > int_map;
std::map<Glib::ustring, Parameter<float> > float_map;
std::map<Glib::ustring, Parameter<Glib::ustring> > string_map;
};
/** \brief This class represents a sigle parameter of type \c T
/** \brief This class represents a sigle parameter of type \c T
This class is useful only to store informations about each parameter. No checks
on the values entered are done.
*/
template<typename T>
class PolicyParameters::Parameter
{
public:
This class is useful only to store informations about each parameter. No checks
on the values entered are done.
*/
template<typename T>
class PolicyParameters::Parameter
{
public:
/** \brief Constructs the parameter
\param name The name of the parameter. This string will be used to refer to this parameter, thus it MUST
be uniqe (one string identifies \b only ONE parameter)
\param value The initial value of this parameter
\param lower_bound The lower limitation of the value which can be set with set_int(...).
\param upper_bound The upper limitation of the value which can be set with set_int(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0).
*/
Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value = 0);
/** \brief Constructs the parameter
\param name The name of the parameter. This string will be used to refer to this parameter, thus it MUST
be uniqe (one string identifies \b only ONE parameter)
\param value The initial value of this parameter
\param lower_bound The lower limitation of the value which can be set with set_int(...).
\param upper_bound The upper limitation of the value which can be set with set_int(...).
\param required Denotes if this parameter is required by the policy.
\param default_value The initial value of this parameter. (If not specified it's set to 0).
*/
Parameter(Glib::ustring name, const T& value, const T& lower_bound, const T& upper_bound, const bool& required, const T& default_value = 0);
/** \returns The name of the parameter (its UNIQUE key)
*/
Glib::ustring get_name() const;
/** \returns The name of the parameter (its UNIQUE key)
*/
Glib::ustring get_name() const;
/** \returns The lower bound
*/
T get_lower_bound() const;
/** \returns The lower bound
*/
T get_lower_bound() const;
/** \returns The upper bound
*/
T get_upper_bound() const;
/** \returns The upper bound
*/
T get_upper_bound() const;
/** \returns TRUE if this parameter is required
*/
bool is_required() const;
/** \returns TRUE if this parameter is required
*/
bool is_required() const;
/** \returns Its default value
*/
T get_default() const;
/** \returns Its default value
*/
T get_default() const;
/** \returns Its actual value
*/
T get_value() const;
/** \returns Its actual value
*/
T get_value() const;
/** \brief Changes the value of the parameter.
\warning NO CHECK is done whether the value repects its bounds!!
*/
void set_value(const T&);
/** \brief Changes the value of the parameter.
\warning NO CHECK is done whether the value repects its bounds!!
*/
void set_value(const T&);
private:
Glib::ustring _name;
T _value;
T _lower_bound;
T _upper_bound;
bool _is_required;
T _default;
};
private:
Glib::ustring _name;
T _value;
T _lower_bound;
T _upper_bound;
bool _is_required;
T _default;
};
}//~ namespace sgpem

View file

@ -23,6 +23,5 @@
using namespace sgpem;
Process::~Process()
{
}
{}

View file

@ -33,7 +33,7 @@ namespace sgpem
class Thread;
class SerializeVisitor;
class SG_DLLEXPORT Process : public virtual Schedulable
class SG_DLLEXPORT Process : public virtual Schedulable
{
public:
virtual ~Process();
@ -41,7 +41,7 @@ namespace sgpem
virtual std::vector<Thread*> get_threads() = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
#endif

View file

@ -23,6 +23,5 @@
using namespace sgpem;
Request::~Request()
{
}
{}

View file

@ -29,7 +29,7 @@ namespace sgpem
class Request;
class SerializeVisitor;
class SubRequest;
class SG_DLLEXPORT Request
{
public:
@ -38,16 +38,16 @@ namespace sgpem
state_ready,
state_allocated
};
virtual ~Request();
virtual std::vector<SubRequest*> get_subrequests() = 0;
virtual unsigned int get_instant() const = 0;
virtual state get_current_state() const = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
#endif

View file

@ -23,6 +23,5 @@
using namespace sgpem;
Resource::~Resource()
{
}
{}

View file

@ -28,18 +28,18 @@ namespace sgpem
{
class Resource;
class SerializeVisitor;
class SG_DLLEXPORT Resource
{
public:
virtual ~Resource();
virtual Glib::ustring get_name() const = 0;
virtual unsigned int get_places() const = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
#endif

View file

@ -23,6 +23,5 @@
using namespace sgpem;
Schedulable::~Schedulable()
{
}
{}

View file

@ -41,15 +41,15 @@ namespace sgpem
*/
enum state
{
state_running = 1<<0,
state_ready = 1<<1,
state_blocked = 1<<2,
state_future = 1<<3,
state_terminated = 1<<4
state_running = 1 << 0,
state_ready = 1 << 1,
state_blocked = 1 << 2,
state_future = 1 << 3,
state_terminated = 1 << 4
};
virtual ~Schedulable() = 0;
virtual Glib::ustring get_name() const = 0;
virtual unsigned int get_arrival_time() const = 0;

View file

@ -27,128 +27,127 @@ using namespace std;
using namespace memory;
SchedulableQueue::SchedulableQueue()
{
}
{}
DynamicSchedulable*
SchedulableQueue::top()
{
if (_list.size() == 0)
return NULL;
return &_list.front();
if (_list.size() == 0)
return NULL;
return &_list.front();
}
DynamicSchedulable*
SchedulableQueue::bottom()
{
if (_list.size() == 0)
return NULL;
return &_list.back();
if (_list.size() == 0)
return NULL;
return &_list.back();
}
/**
Returns a pointer to the element at position "where". If the queue is empty or "where" is
out of rangethe NULL pointer will be returned.
DON'T call delete on the returned pointer! Its destruction is managed by the queue.
Returns a pointer to the element at position "where". If the queue is empty or "where" is
out of rangethe NULL pointer will be returned.
DON'T call delete on the returned pointer! Its destruction is managed by the queue.
*/
DynamicSchedulable*
SchedulableQueue::get_item_at(const uint& where)
{
if (_list.size() == 0 || where >= _list.size())
return NULL;
if (_list.size() == 0 || where >= _list.size())
return NULL;
list<DynamicSchedulable>::iterator i = _list.begin();
for (uint f=0; f < where; f++)
i++;
return &(*i);
list<DynamicSchedulable>::iterator i = _list.begin();
for (uint f = 0; f < where; f++)
i++;
return &(*i);
}
const DynamicSchedulable*
SchedulableQueue::get_item_at(const uint& where) const
{
if (_list.size() == 0 || where >= _list.size())
return NULL;
if (_list.size() == 0 || where >= _list.size())
return NULL;
list<DynamicSchedulable>::const_iterator i = _list.begin();
for (uint f=0; f < where; f++)
i++;
return &(*i);
list<DynamicSchedulable>::const_iterator i = _list.begin();
for (uint f = 0; f < where; f++)
i++;
return &(*i);
}
/**
Returns the number of elements inserted into the queue.
Returns the number of elements inserted into the queue.
*/
uint
SchedulableQueue::size() const
{
return _list.size();
return _list.size();
}
void
SchedulableQueue::add_at_top(const DynamicSchedulable& ss)
{
_list.push_front(ss);
_list.push_front(ss);
}
void
SchedulableQueue::add_at_bottom(const DynamicSchedulable& ss)
{
_list.push_back(ss);
_list.push_back(ss);
}
smart_ptr<DynamicSchedulable>
SchedulableQueue::remove(const uint& position)
{
if (_list.size() == 0 || position >= _list.size())
return smart_ptr<DynamicSchedulable>(NULL);
if (_list.size() == 0 || position >= _list.size())
return smart_ptr<DynamicSchedulable>(NULL);
//creates a copy of the first element
smart_ptr<DynamicSchedulable> sm = new DynamicSchedulable(*top());
//pops the first element
_list.pop_front();
//returns the copy
return sm;
//creates a copy of the first element
smart_ptr<DynamicSchedulable> sm = new DynamicSchedulable(*top());
//pops the first element
_list.pop_front();
//returns the copy
return sm;
}
/**
*/
bool
SchedulableQueue::insert_at(const uint& which, const uint& where)
{
//out of range
if (which >= _list.size() || where >= _list.size())
return false;
//nothing to do
if (where == which)
return true;
//out of range
if (which >= _list.size() || where >= _list.size())
return false;
//nothing to do
if (where == which)
return true;
list<DynamicSchedulable>::iterator i_where = _list.begin();
list<DynamicSchedulable>::iterator i_which = _list.begin();
for (uint f=0; f < where; f++)
i_where++;
for (uint f=0; f < which; f++)
i_which++;
list<DynamicSchedulable>::iterator i_where = _list.begin();
list<DynamicSchedulable>::iterator i_which = _list.begin();
for (uint f = 0; f < where; f++)
i_where++;
for (uint f = 0; f < which; f++)
i_which++;
//save and pop WHICH
DynamicSchedulable temp = *i_which;
_list.erase(i_which);
//save and pop WHICH
DynamicSchedulable temp = *i_which;
_list.erase(i_which);
//insert WHICH before WHERE
_list.insert(i_where, temp);
//insert WHICH before WHERE
_list.insert(i_where, temp);
return true;
return true;
}
/**
Removes all elements
Removes all elements
*/
void
SchedulableQueue::clear()
{
_list.clear();
_list.clear();
}
@ -158,7 +157,7 @@ SchedulableQueue::clear()
bool
SchedulableQueue::operator==(const SchedulableQueue& dx) const
{
return _list == dx._list;
return _list == dx._list;
}
@ -168,49 +167,49 @@ SchedulableQueue::operator==(const SchedulableQueue& dx) const
bool
SchedulableQueue::has_same_objects(const SchedulableQueue& dx) const
{
if (_list.size() != dx._list.size())
return false;
if (_list.size() != dx._list.size())
return false;
//check if dx has ALL and ONLY the elements holded by _list with no order importance
for(list<DynamicSchedulable>::const_iterator f=_list.begin(); f != _list.end(); f++)
if (find(dx._list.begin(), dx._list.end(), *f) == dx._list.end()) //element NOT found!!
return false;
for(list<DynamicSchedulable>::const_iterator f = _list.begin(); f != _list.end(); f++)
if (find(dx._list.begin(), dx._list.end(), *f) == dx._list.end()) //element NOT found!!
return false;
return true;
return true;
}
void
SchedulableQueue::swap(unsigned int positionA, unsigned int positionB) throw()
{
if (positionA == positionB || positionA >= _list.size() || positionB >= _list.size())
return;
if (positionA == positionB || positionA >= _list.size() || positionB >= _list.size())
return;
unsigned int min, max;
if (positionA < positionB)
{
min = positionA;
max = positionB;
}
else
{
min = positionB;
max = positionA;
}
unsigned int min, max;
if (positionA < positionB)
{
min = positionA;
max = positionB;
}
else
{
min = positionB;
max = positionA;
}
list<DynamicSchedulable>::iterator i1 = _list.begin();
list<DynamicSchedulable>::iterator i2 = _list.begin();
list<DynamicSchedulable>::iterator i1 = _list.begin();
list<DynamicSchedulable>::iterator i2 = _list.begin();
//reach the first element;
for (uint f=0; f < min; f++)
i1++;
DynamicSchedulable temp = *i1;
//reach the first element;
for (uint f = 0; f < min; f++)
i1++;
DynamicSchedulable temp = *i1;
//reach the second element;
i2 = i1;
for (uint f=min; f < max; f++)
i2++;
//reach the second element;
i2 = i1;
for (uint f = min; f < max; f++)
i2++;
*i1 = *i2;
*i2 = temp;
*i1 = *i2;
*i2 = temp;
}

View file

@ -63,13 +63,13 @@ namespace sgpem
void add_at_bottom(const DynamicSchedulable&);
/** \brief Removes */
/**
Removes an element from the list. Returns a smart pointer a copy of it or to NULL if
"position" is out of range.
Ex. remove(0); removes the top of the list
Ex. remove(size()-1) removes the bottom of the list
*/
/**
Removes an element from the list. Returns a smart pointer a copy of it or to NULL if
"position" is out of range.
Ex. remove(0); removes the top of the list
Ex. remove(size()-1) removes the bottom of the list
*/
memory::smart_ptr<sgpem::DynamicSchedulable> remove(const unsigned int& position);
bool insert_at(const unsigned int&, const unsigned int&);
@ -92,7 +92,7 @@ namespace sgpem
* \param positionA The position of the first element to swap
* \param positionB The position of the second element to swap
*/
void swap(unsigned int positionA, unsigned int positionB) throw();
void swap(unsigned int positionA, unsigned int positionB) throw();
private:
std::list<DynamicSchedulable> _list;

View file

@ -37,29 +37,29 @@ template class SG_DLLEXPORT Singleton<Scheduler>;
//private constructor. The parameter is discarded
Scheduler::Scheduler()
: _policy_manager(PolicyManager::get_registered_manager())
: _policy_manager(PolicyManager::get_registered_manager())
{
_policy_manager.init();
}
SchedulableQueue*
SchedulableQueue*
Scheduler::get_ready_queue()
{
// FIXME return the correct queue accordingly to the value returned by Policy::wants()
return &_ready_queue;
return &_ready_queue;
}
/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica
attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica
e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione
/** \note E' fondamentale che questo metodo memorizzi localmente qualora la politica
attuale sia a prerilascio o meno, e la durata del quanto di tempo, in quanto la politica
e' libera di variare questi parametri a piacere durante l'esecuzione della simulazione
*/
void
Scheduler::reset_status()
{
_ready_queue.clear();
History::get_instance().truncate_at(0);
// restore the policy
_ready_queue.clear();
History::get_instance().truncate_at(0);
// restore the policy
}
/* void
@ -80,134 +80,134 @@ Scheduler::get_policy()
void
Scheduler::step_forward() throw(UserInterruptException)
{
try
try
{
Policy& policy = get_policy();
History& h = History::get_instance();
//******************
//check for arrivals and prepare the queue
//******************
smart_ptr<SchedulableQueue> initial = h.get_simulation_status_at(h.get_current_time());
if (!initial)
{
Policy& policy = get_policy();
History& h = History::get_instance();
//******************
//check for arrivals and prepare the queue
//******************
smart_ptr<SchedulableQueue> initial = h.get_simulation_status_at(h.get_current_time());
if (!initial)
{
cout << _("\nNo initial state inserted!!\n");
return;
}
_ready_queue.clear();
//adds running schedulable
smart_ptr<DynamicSchedulable> running_ptr = h.get_scheduled_at(h.get_current_time());
if (running_ptr)
_ready_queue.add_at_top(*running_ptr);
//adds the READY ones
for(uint rea=0; rea < initial->size(); rea++)
if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready)
_ready_queue.add_at_bottom(*initial->get_item_at(rea));
//adds each new ready schedulable and sorts the queue
for(uint i=0; i < initial->size(); i++)
if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
{
//cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.remove(0);
//adds the NEW one
_ready_queue.add_at_bottom(*initial->get_item_at(i));
_ready_queue.get_item_at(_ready_queue.size()-1)->set_state(DynamicSchedulable::state_ready);
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
// Sort the queue
policy.sort_queue();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.add_at_top(*running_ptr);
}
//****************
// Check for termination
//****************
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
{
//there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED
for(uint i=0; i < _ready_queue.size(); i++)
if (*_ready_queue.get_item_at(i) == *running_ptr)
{
_ready_queue.add_at_bottom(*_ready_queue.get_item_at(i));
_ready_queue.remove(i);
_ready_queue.get_item_at(_ready_queue.size()-1)->set_state(DynamicSchedulable::state_terminated);
break;
}
//cout << "\nTERMINATO!!";
running_ptr = NULL;
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
policy.sort_queue();
}
//*****************
// Check for time slice
//*****************
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
policy.sort_queue();
//******************
// Create the final list of schedulable
//******************
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready
|| _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running))
{
//the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
_ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running);
_ready_queue.get_item_at(0)->give_cpu_time(1);
}
//all the others are ready
for (uint i = 1; i < _ready_queue.size(); i++)
if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running)
_ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready);
//append blocked, future, and terminated schedulables
for (uint i = 0; i < initial->size(); i++)
if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
_ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n";
/* for (uint i = 0; i < _ready_queue.size(); i++)
cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name()
<<"_" << _ready_queue.get_item_at(i)->get_state();
*/
h.enqueue_slice(_ready_queue);
}
catch( UserInterruptException e )
{
_policy_manager.init();
throw;
//TODO Do we need to perform some cleanup operation here?
// Do we need to update something?
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
// maybe it's that??? oh, damn.
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
// Tell:
// - the user that the policy sucks
// - SimulationController that everything stopped
cout << _("\nNo initial state inserted!!\n");
return;
}
_ready_queue.clear();
//adds running schedulable
smart_ptr<DynamicSchedulable> running_ptr = h.get_scheduled_at(h.get_current_time());
if (running_ptr)
_ready_queue.add_at_top(*running_ptr);
//adds the READY ones
for(uint rea = 0; rea < initial->size(); rea++)
if (initial->get_item_at(rea)->get_state() == DynamicSchedulable::state_ready)
_ready_queue.add_at_bottom(*initial->get_item_at(rea));
//adds each new ready schedulable and sorts the queue
for(uint i = 0; i < initial->size(); i++)
if (initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
&& (int)initial->get_item_at(i)->get_schedulable()->get_arrival_time() == h.get_current_time())
{
//cout << "\nnuovo running: " << initial->get_item_at(i)->get_schedulable()->get_name();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.remove(0);
//adds the NEW one
_ready_queue.add_at_bottom(*initial->get_item_at(i));
_ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_ready);
initial->get_item_at(i)->set_state(DynamicSchedulable::state_ready);
// Sort the queue
policy.sort_queue();
//restore the old running schedulable
if (policy.is_pre_emptive() == false && running_ptr)
_ready_queue.add_at_top(*running_ptr);
}
//****************
// Check for termination
//****************
if (running_ptr && running_ptr->get_cpu_time_left() == 0)
{
//there is a running schedulable and it's terminated. Append at the bottom with the state TERMINATED
for(uint i = 0; i < _ready_queue.size(); i++)
if (*_ready_queue.get_item_at(i) == *running_ptr)
{
_ready_queue.add_at_bottom(*_ready_queue.get_item_at(i));
_ready_queue.remove(i);
_ready_queue.get_item_at(_ready_queue.size() - 1)->set_state(DynamicSchedulable::state_terminated);
break;
}
//cout << "\nTERMINATO!!";
running_ptr = NULL;
//IF _ready_queue.size() == 0 sort_queue(...) is called but has no effect!!
policy.sort_queue();
}
//*****************
// Check for time slice
//*****************
if (policy.get_time_slice() != numeric_limits<int>::max()) //time-slice
policy.sort_queue();
//******************
// Create the final list of schedulable
//******************
if (_ready_queue.size() != 0 && (_ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_ready
|| _ready_queue.get_item_at(0)->get_state() == DynamicSchedulable::state_running))
{
//the first ready element IS the running one (if != *running_ptr then there is a CONTEXT SWICH)
_ready_queue.get_item_at(0)->set_state(DynamicSchedulable::state_running);
_ready_queue.get_item_at(0)->give_cpu_time(1);
}
//all the others are ready
for (uint i = 1; i < _ready_queue.size(); i++)
if (_ready_queue.get_item_at(i)->get_state() == DynamicSchedulable::state_running)
_ready_queue.get_item_at(i)->set_state(DynamicSchedulable::state_ready);
//append blocked, future, and terminated schedulables
for (uint i = 0; i < initial->size(); i++)
if(initial->get_item_at(i)->get_state() == DynamicSchedulable::state_blocked
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_future
|| initial->get_item_at(i)->get_state() == DynamicSchedulable::state_terminated)
_ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n";
/* for (uint i = 0; i < _ready_queue.size(); i++)
cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name()
<<"_" << _ready_queue.get_item_at(i)->get_state();
*/
h.enqueue_slice(_ready_queue);
}
catch( UserInterruptException e )
{
_policy_manager.init();
throw;
//TODO Do we need to perform some cleanup operation here?
// Do we need to update something?
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
// maybe it's that??? oh, damn.
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
// Tell:
// - the user that the policy sucks
// - SimulationController that everything stopped
}
}

View file

@ -44,15 +44,15 @@ namespace sgpem
{
class Scheduler;
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
Class Scheduler manages the schedulable entities which are ready to run,
ordering them in a queue; it also checks that the current scheduling policy
is well-defined and does not disrupt the application inner mechanism.
It is also responsible for the creation and the destruction of some of
the DynamicSchedulable objects (for further details about this, check
class DynamicSchedulable).
/** \brief Manages the DynamicSchedulable objects, implementing a given policy.
Class Scheduler manages the schedulable entities which are ready to run,
ordering them in a queue; it also checks that the current scheduling policy
is well-defined and does not disrupt the application inner mechanism.
It is also responsible for the creation and the destruction of some of
the DynamicSchedulable objects (for further details about this, check
class DynamicSchedulable).
*/
class SG_DLLEXPORT Scheduler : public Singleton<Scheduler>
@ -65,34 +65,34 @@ namespace sgpem
\return a pointer to the queue containing all the ready
schedulable objects (for the policy to sort it).
*/
SchedulableQueue* get_ready_queue();
SchedulableQueue* get_ready_queue();
/**
Resets the simulation to the initial state.
*/
void reset_status();
void reset_status();
/**
Generates a new SchedulableQueue representing the status of the processes
at the simulation instant next to the current one, and extends the History by
one instant with it.
*/
void step_forward() throw(UserInterruptException);
void step_forward() throw(UserInterruptException);
/**
Sets the policy that will be used to generate the simulation at the next instant.
\param policy the policy that will be used to generate the simulation at the next instant.
*/
/* DISABLED until we don't have PolicyManager::set_policy()
void set_policy(Policy* policy);
void set_policy(Policy* policy);
*/
/**
Returns the policy that will be used to generate the simulation at the next instant.
\return the policy that will be used to generate the simulation at the next instant.
*/
Policy& get_policy();
Policy& get_policy();
private:
Scheduler(); //private constructor.
SchedulableQueue _ready_queue;
PolicyManager& _policy_manager;
Scheduler(); //private constructor.
SchedulableQueue _ready_queue;
PolicyManager& _policy_manager;
};
}//~ namespace sgpem

View file

@ -24,9 +24,8 @@ using namespace std;
Slice::Slice(const int& start, const int& duration, const SchedulableQueue& status)
: _ref(status), _started_at(start), _duration(duration)
{
}
: _ref(status), _started_at(start), _duration(duration)
{}
const SchedulableQueue*
Slice::get_simulation_status() const
@ -46,7 +45,7 @@ Slice::get_duration() const
return _duration;
}
void
void
Slice::set_duration(const int& i)
{
_duration = i;

View file

@ -30,52 +30,52 @@ namespace sgpem
class Slice;
/** \brief Represents a slice of time during which some characteristic of the state of the simulation are constant
Represents a slice of time during which some characteristic of the state of the simulation are constant.
It holds a \ref SimulationStatus object which can be accessed through getSimulationStatus()
*/
class SG_DLLEXPORT Slice
{
public:
/**
Constructor for Slice.
\param start The Slice's starting time.
\param duration Time length of Slice.
\param status Photoshot of all \ref Schedulable during this Slice.
*/
Slice(const int& start, const int& duration, const SchedulableQueue& status);
/**
Constructor for Slice.
\param start The Slice's starting time.
\param duration Time length of Slice.
\param status Photoshot of all \ref Schedulable during this Slice.
*/
Slice(const int& start, const int& duration, const SchedulableQueue& status);
/**
Gets a constant reference to the \ref SchedulableQueue object for this Slice.
\return The reference (constant) to the SchedulableQueue object for this Slice.
*/
const SchedulableQueue* get_simulation_status() const;
/**
Gets a constant reference to the \ref SchedulableQueue object for this Slice.
\return The reference (constant) to the SchedulableQueue object for this Slice.
*/
const SchedulableQueue* get_simulation_status() const;
/**
Gets starting time of this Slice.
\return The starting time.
*/
int get_started_at() const;
/**
Gets starting time of this Slice.
\return The starting time.
*/
int get_started_at() const;
/**
Gets duration of this Slice.
\return The duration time.
*/
int get_duration() const;
/**
Gets duration of this Slice.
\return The duration time.
*/
int get_duration() const;
/**
Sets duration of this Slice.
\param duration The desired duration time.
*/
void set_duration(const int& duration);
/**
Sets duration of this Slice.
\param duration The desired duration time.
*/
void set_duration(const int& duration);
private:
SchedulableQueue _ref;
int _started_at;
int _duration;
SchedulableQueue _ref;
int _started_at;
int _duration;
};
} //~ namespace sgpem

View file

@ -23,15 +23,13 @@ using namespace sgpem;
StaticProcess::StaticProcess(const Glib::ustring& name, const unsigned int& arrival, const unsigned int& total, const int& priority)
: StaticSchedulable(name, arrival, total, priority)
{
}
: StaticSchedulable(name, arrival, total, priority)
{}
StaticProcess::~StaticProcess()
{
}
{}
Glib::ustring
Glib::ustring
StaticProcess::get_type() const
{
return "StaticProcess";

View file

@ -32,10 +32,10 @@ namespace sgpem
class StaticProcess;
/** \brief Represents a program in execution.
It IS a Schedulable object.
*/
class SG_DLLEXPORT StaticProcess : public StaticSchedulable
class SG_DLLEXPORT StaticProcess : public StaticSchedulable
{
public:
/** \brief Creates a new object with the given parameters. */
@ -43,11 +43,11 @@ namespace sgpem
/** \brief Destructor. */
~StaticProcess();
/** \brief Returns a string describing the type of the object. */
Glib::ustring get_type() const;
Glib::ustring get_type() const;
private:
};
}
#endif

View file

@ -23,20 +23,20 @@
using namespace sgpem;
StaticRequest::StaticRequest(StaticThread* thread,
StaticRequest::StaticRequest(StaticThread* thread,
unsigned int instant) :
_thread(thread), _instant(instant)
_thread(thread), _instant(instant)
{
assert(thread != NULL);
}
unsigned int
unsigned int
StaticRequest::get_instant() const
{
return _instant;
}
StaticThread&
StaticThread&
StaticRequest::get_thread()
{
return *_thread;

View file

@ -29,22 +29,22 @@ namespace sgpem
class StaticRequest;
class SerializeVisitor;
class StaticThread;
class StaticRequest
{
public:
StaticRequest(StaticThread* thread, unsigned int instant);
unsigned int get_instant() const;
StaticThread& get_thread();
private:
StaticRequest(const StaticRequest&);
StaticThread* _thread;
unsigned int _instant;
};
}
#endif

View file

@ -22,19 +22,18 @@
using namespace sgpem;
StaticResource::StaticResource(const Glib::ustring& name,
StaticResource::StaticResource(const Glib::ustring& name,
unsigned int places) :
_name(name), _places(places)
{
}
Glib::ustring
_name(name), _places(places)
{}
Glib::ustring
StaticResource::get_name() const
{
return _name;
}
unsigned int
unsigned int
StaticResource::get_places() const
{
return _places;

View file

@ -28,12 +28,12 @@ namespace sgpem
{
class StaticResource;
class SerializeVisitor;
class StaticResource
{
public:
StaticResource(const Glib::ustring& name, unsigned int places = 1);
Glib::ustring get_name() const;
unsigned int get_places() const;
@ -43,7 +43,7 @@ namespace sgpem
Glib::ustring _name;
unsigned int _places;
};
}
#endif

View file

@ -23,16 +23,14 @@
using namespace sgpem;
StaticSchedulable::StaticSchedulable(const Glib::ustring& name,
const unsigned int& arrival,
const unsigned int& total,
const int& priority) :
_name(name), _arrival_time(arrival), _total_time(total), _priority(priority)
{
}
const unsigned int& arrival,
const unsigned int& total,
const int& priority) :
_name(name), _arrival_time(arrival), _total_time(total), _priority(priority)
{}
StaticSchedulable::~StaticSchedulable()
{
}
{}
unsigned int
StaticSchedulable::get_arrival_time() const
@ -40,7 +38,7 @@ StaticSchedulable::get_arrival_time() const
return _arrival_time;
}
void
void
StaticSchedulable::set_arrival_time(unsigned int new_time)
{
_arrival_time = new_time;
@ -59,7 +57,7 @@ StaticSchedulable::get_priority() const
return _priority;
}
void
void
StaticSchedulable::set_priority(int new_priority)
{
_priority = new_priority;

View file

@ -43,7 +43,7 @@ namespace sgpem
public:
/** \brief Create a new object with the given parameters */
StaticSchedulable(const Glib::ustring& name, const unsigned int& arrival,
const unsigned int& total, const int& priority);
const unsigned int& total, const int& priority);
virtual ~StaticSchedulable();
/** \brief Returns the arrival time for this process

View file

@ -24,35 +24,35 @@
using namespace sgpem;
StaticSubRequest::StaticSubRequest(StaticRequest* req,
StaticResource* resource,
unsigned int length,
StaticSubRequest::StaticSubRequest(StaticRequest* req,
StaticResource* resource,
unsigned int length,
unsigned int places) :
_static_request(req), _static_resource(resource),
_length(length), _places(places)
{
_static_request(req), _static_resource(resource),
_length(length), _places(places)
{
assert(req != NULL && resource != NULL);
}
StaticResource&
StaticResource&
StaticSubRequest::get_static_resource()
{
return *_static_resource;
}
StaticRequest&
StaticRequest&
StaticSubRequest::get_static_request()
{
return *_static_request;
}
unsigned int
unsigned int
StaticSubRequest::get_places() const
{
return _places;
}
unsigned int
unsigned int
StaticSubRequest::get_length() const
{
return _length;

View file

@ -28,16 +28,16 @@ namespace sgpem
class StaticSubRequest;
class StaticRequest;
class StaticResource;
class StaticSubRequest
{
public:
StaticSubRequest(StaticRequest* req,
StaticResource* resource,
unsigned int length,
StaticSubRequest(StaticRequest* req,
StaticResource* resource,
unsigned int length,
unsigned int places = 1);
StaticResource& get_static_resource();
StaticResource& get_static_resource();
StaticRequest& get_static_request();
@ -53,7 +53,7 @@ namespace sgpem
unsigned int _length;
unsigned int _places;
};
}
#endif

View file

@ -30,37 +30,36 @@ StaticThread::StaticThread(const Glib::ustring& name,
StaticProcess& process,
unsigned int arrival_time,
int base_priority) :
StaticSchedulable(name, arrival_time, 0, base_priority),
_start_time_delta(arrival_time), _required_cpu_time(0),
_process(&process)
{
}
StaticSchedulable(name, arrival_time, 0, base_priority),
_start_time_delta(arrival_time), _required_cpu_time(0),
_process(&process)
{}
unsigned int
unsigned int
StaticThread::get_total_cpu_time() const
{
return _required_cpu_time;
}
unsigned int
unsigned int
StaticThread::get_arrival_time() const
{
return _start_time_delta;
}
StaticProcess&
StaticProcess&
StaticThread::get_process()
{
return *_process;
}
void
void
StaticThread::remove_request(StaticRequest* request)
{
assert(request != NULL);
vector<StaticRequest*>::iterator it;
it = std::find(_static_requests.begin(), _static_requests.end(), request);
if(it != _static_requests.end())
@ -70,7 +69,7 @@ StaticThread::remove_request(StaticRequest* request)
}
}
void
void
StaticThread::add_request(StaticRequest* request)
{
assert(request != NULL);

View file

@ -34,13 +34,13 @@ namespace sgpem
class StaticProcess;
class StaticRequest;
class SG_DLLEXPORT StaticThread : public StaticSchedulable
class SG_DLLEXPORT StaticThread : public StaticSchedulable
{
public:
StaticThread(const Glib::ustring& name,
StaticProcess& process,
unsigned int arrival_time = 0,
int base_priority = 0);
unsigned int arrival_time = 0,
int base_priority = 0);
unsigned int get_total_cpu_time() const;
@ -51,16 +51,16 @@ namespace sgpem
void remove_request(StaticRequest* request);
void add_request(StaticRequest* request);
private:
StaticThread(const StaticThread&);
unsigned int _start_time_delta;
unsigned int _required_cpu_time;
StaticProcess* _process;
std::vector<StaticRequest*> _static_requests;
};
}
#endif

View file

@ -24,91 +24,91 @@ using namespace std;
using 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
\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
bool
string_to_int(const ustring& str, int& num)
{
static const ustring allvalid = "0123456789-";
static const ustring digits = "0123456789";
// the string can't be empty
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
return false;
static const ustring allvalid = "0123456789-";
static const ustring digits = "0123456789";
//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--)
{
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;
// the string can't be empty
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
return false;
//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--)
{
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;
}
/**
\brief A function that converts an integer value to an Unicode string
\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;
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
void
float_to_string(const float& f, Glib::ustring& str)
{
stringstream ss;
ss << f;
char p[20];
ss.getline(p,20);
str = p;
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;
stringstream ss;
ss << str;
ss >> f;
}

View file

@ -26,38 +26,38 @@
#include <iostream>
#include "glibmm/ustring.h"
/**\brief This function tries to convert a string into an integer value.
/**\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).
The string can contain only digits and the minus character (for negative numbers).
\returns TRUE if ths string represent a valid integer number
\returns FALSE otherwise
*/
bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&);
\returns TRUE if ths string represent a valid integer number
\returns FALSE otherwise
*/
bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&);
/**\brief This function converts an integer value into a string.
/**\brief This function converts an integer value into a string.
There is no return value because this function always succeeds.
*/
void SG_DLLEXPORT int_to_string(const int&, Glib::ustring&);
There is no return value because this function always succeeds.
*/
void SG_DLLEXPORT int_to_string(const int&, Glib::ustring&);
/**\brief This function converts a float value into a string.
/**\brief This function converts a float value into a string.
There is no return value because this function always succeeds.
*/
void SG_DLLEXPORT float_to_string(const float&, Glib::ustring&);
There is no return value because this function always succeeds.
*/
void SG_DLLEXPORT float_to_string(const float&, Glib::ustring&);
/**\brief This function tries to convert a string into a float value.
/**\brief This function tries to convert a string into a float value.
The string can contain only digits, the minus, plus and dot (-+.) characters. If not,
the value 0 is assigned.
The string can contain only digits, the minus, plus and dot (-+.) characters. If not,
the value 0 is assigned.
There is no return value because this function always succeeds, even if the string is badly formed.
*/
void SG_DLLEXPORT string_to_float(const Glib::ustring&, float&);
There is no return value because this function always succeeds, even if the string is badly formed.
*/
void SG_DLLEXPORT string_to_float(const Glib::ustring&, float&);
#endif

View file

@ -23,6 +23,5 @@
using namespace sgpem;
SubRequest::~SubRequest()
{
}
{}

View file

@ -28,23 +28,23 @@ namespace sgpem
class SubRequest;
class SerializeVisitor;
class Resource;
class SG_DLLEXPORT SubRequest
{
public:
virtual ~SubRequest();
virtual Resource& get_resource() = 0;
virtual Resource& get_resource() = 0;
virtual unsigned int get_places() const = 0;
virtual unsigned int get_length() const = 0;
virtual int get_queue_position() const = 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
#endif

View file

@ -23,6 +23,5 @@
using namespace sgpem;
Thread::~Thread()
{
}
{}

View file

@ -32,17 +32,17 @@ namespace sgpem
class Request;
class Process;
class SerializeVisitor;
class SG_DLLEXPORT Thread : public virtual Schedulable
class SG_DLLEXPORT Thread : public virtual Schedulable
{
public:
virtual ~Thread();
virtual Process& get_process() = 0;
virtual std::vector<Request*> get_requests() = 0;
virtual void serialize(SerializeVisitor& translator) const= 0;
virtual void serialize(SerializeVisitor& translator) const = 0;
};
}
#endif

View file

@ -19,14 +19,14 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// Warning! This exception will be thrown across different libraries.
// It could be necessary to do dynamic type-checking when
// It could be necessary to do dynamic type-checking when
// catching it (with typeinfo).
#include "user_interrupt_exception.hh"
using namespace sgpem;
UserInterruptException::UserInterruptException(const char* msg)
: std::runtime_error(msg)
UserInterruptException::UserInterruptException(const char* msg)
: std::runtime_error(msg)
{}
UserInterruptException::~UserInterruptException() throw() {}
UserInterruptException::~UserInterruptException() throw() {}

View file

@ -19,7 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// Warning! This exception will be thrown across different libraries.
// It could be necessary to do dynamic type-checking when
// It could be necessary to do dynamic type-checking when
// catching it (with typeinfo).
#ifndef USER_INTERRUPT_EXCEPTION
@ -29,17 +29,18 @@
#include <stdexcept>
namespace sgpem {
class UserInterruptException;
namespace sgpem
{
class UserInterruptException;
class SG_DLLEXPORT UserInterruptException : public std::runtime_error
{
public:
UserInterruptException(const char* msg = "");
virtual ~UserInterruptException() throw ();
class SG_DLLEXPORT UserInterruptException : public std::runtime_error
{
public:
UserInterruptException(const char* msg = "");
virtual ~UserInterruptException() throw ();
private:
};
private:
};
} //~ namespace sgpem
#endif