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

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

View File

@ -31,7 +31,7 @@ PythonCPUPolicyManager* _policy_manager = NULL;
void void
sgpem__Plugin__on_init() sgpem__Plugin__on_init()
{ {
if(_policy_manager == NULL) if (_policy_manager == NULL)
_policy_manager = new sgpem::PythonCPUPolicyManager(); _policy_manager = new sgpem::PythonCPUPolicyManager();
} }

View File

@ -39,7 +39,7 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr); PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
Py_DECREF(pLoadmeStr); Py_DECREF(pLoadmeStr);
if(pUserCPUPolicyModule == NULL) if (pUserCPUPolicyModule == NULL)
throw MalformedPolicyException(get_exception_information().c_str()); throw MalformedPolicyException(get_exception_information().c_str());
// Dictionary with defined ``symbols'' for .pyc file // Dictionary with defined ``symbols'' for .pyc file
@ -69,7 +69,7 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
Py_DECREF(pScriptAdapterModule); Py_DECREF(pScriptAdapterModule);
if(_adapter == NULL) if (_adapter == NULL)
throw MalformedPolicyException(get_exception_information().c_str()); throw MalformedPolicyException(get_exception_information().c_str());
// And now, who's your daddy, huh? // And now, who's your daddy, huh?
@ -78,12 +78,12 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
PythonCPUPolicy::~PythonCPUPolicy() PythonCPUPolicy::~PythonCPUPolicy()
{ {
if(_adapter) Py_DECREF(_adapter); if (_adapter) Py_DECREF(_adapter);
// We keep this alive until dtor time, because // We keep this alive until dtor time, because
// the user may have defined some static global-space // the user may have defined some static global-space
// variables and they make use of them. // variables and they make use of them.
if(_upolicy_dict) Py_DECREF(_upolicy_dict); if (_upolicy_dict) Py_DECREF(_upolicy_dict);
} }
void void
@ -122,7 +122,7 @@ PythonCPUPolicy::sort_queue() const throw(UserInterruptException)
PyObject* retval = PyObject_CallMethod(_adapter, "async_sort_queue", NULL); PyObject* retval = PyObject_CallMethod(_adapter, "async_sort_queue", NULL);
// Do minimal debugging // Do minimal debugging
if(!retval) PyErr_Print(); if (!retval) PyErr_Print();
else Py_DECREF(retval); else Py_DECREF(retval);
wait_unlock(); wait_unlock();
@ -165,7 +165,7 @@ PythonCPUPolicy::get_time_slice() const throw(UserInterruptException)
PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL); PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL);
// Do minimal debugging // Do minimal debugging
if(!retval) PyErr_Print(); if (!retval) PyErr_Print();
else Py_DECREF(retval); else Py_DECREF(retval);
wait_unlock(); wait_unlock();
@ -199,7 +199,7 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
still_locked = PyObject_IsTrue(retval); still_locked = PyObject_IsTrue(retval);
Py_DECREF(retval); Py_DECREF(retval);
if(i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */ if (i++ > 12) /* waits for WAIT_FOR * 12 microseconds == 3 secs */
{ {
PyThreadState_Clear(_save); PyThreadState_Clear(_save);
// As the API documentation says, the caller of PyEval_RestoreThread // As the API documentation says, the caller of PyEval_RestoreThread
@ -212,7 +212,7 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
"taking too long to terminate.")); "taking too long to terminate."));
} }
} }
while(still_locked); while (still_locked);
// What we should really do here: // What we should really do here:
/* do { /* do {
@ -234,7 +234,7 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
string string
PythonCPUPolicy::get_exception_information() PythonCPUPolicy::get_exception_information()
{ {
if(PyErr_Occurred() == NULL) if (PyErr_Occurred() == NULL)
return _("no error"); return _("no error");
PyObject* pType = NULL; PyObject* pType = NULL;
@ -245,7 +245,7 @@ PythonCPUPolicy::get_exception_information()
string msg; string msg;
if(pValue != NULL) if (pValue != NULL)
{ {
PyObject* pValueStr = PyObject_Str(pValue); PyObject* pValueStr = PyObject_Str(pValue);
@ -256,9 +256,9 @@ PythonCPUPolicy::get_exception_information()
else else
msg = string(_("no available information for this error")); msg = string(_("no available information for this error"));
if(pType != NULL) Py_DECREF(pType); if (pType != NULL) Py_DECREF(pType);
if(pValue != NULL) Py_DECREF(pValue); if (pValue != NULL) Py_DECREF(pValue);
if(pTraceback != NULL) Py_DECREF(pTraceback); if (pTraceback != NULL) Py_DECREF(pTraceback);
return msg; return msg;
} }

View File

@ -74,7 +74,7 @@ PythonCPUPolicyManager::~PythonCPUPolicyManager()
void void
PythonCPUPolicyManager::init() PythonCPUPolicyManager::init()
{ {
if(_initialized) if (_initialized)
// No-op // No-op
return; return;
@ -114,19 +114,19 @@ PythonCPUPolicyManager::collect_policies()
GlobalPreferences::dir_iterator dir_it = prefs.policies_dir_begin(); GlobalPreferences::dir_iterator dir_it = prefs.policies_dir_begin();
GlobalPreferences::dir_iterator dir_end = prefs.policies_dir_end(); GlobalPreferences::dir_iterator dir_end = prefs.policies_dir_end();
for(; dir_it != dir_end; ++dir_it) for (; dir_it != dir_end; ++dir_it)
{ {
Glib::Dir dir(dir_it->c_str()); Glib::Dir dir(dir_it->c_str());
cout << "Opening directory " << *dir_it << " looking for python policies..." << endl; cout << "Opening directory " << *dir_it << " looking for python policies..." << endl;
for(Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it) for (Glib::DirIterator file_it = dir.begin(); file_it != dir.end(); ++file_it)
{ {
cout << "\tChecking if " << *file_it << " is a valid Python script... "; cout << "\tChecking if " << *file_it << " is a valid Python script... ";
Glib::PatternSpec dot_py("*.py"); Glib::PatternSpec dot_py("*.py");
if(dot_py.match(*file_it)) if (dot_py.match(*file_it))
{ {
cout << "yes" << endl; cout << "yes" << endl;
@ -139,7 +139,7 @@ PythonCPUPolicyManager::collect_policies()
_policies.push_back(pypolicy); _policies.push_back(pypolicy);
} }
catch(MalformedPolicyException e) catch (MalformedPolicyException e)
{ {
std::cerr << "POLICY LOAD ERROR: " << e.what() << endl; std::cerr << "POLICY LOAD ERROR: " << e.what() << endl;
} }

View File

@ -46,8 +46,8 @@ static CPUPolicy*
find_pol_by_name(const vector<CPUPolicy*>& pols, const Glib::ustring& name) find_pol_by_name(const vector<CPUPolicy*>& pols, const Glib::ustring& name)
{ {
vector<CPUPolicy*>::const_iterator it = pols.begin(); vector<CPUPolicy*>::const_iterator it = pols.begin();
for( ; it != pols.end(); it++) for ( ; it != pols.end(); it++)
if((*it)->get_name() == name) if ((*it)->get_name() == name)
return *it; return *it;
return NULL; return NULL;
} }
@ -58,7 +58,7 @@ main(int argc, char** argv)
{ {
int successes = 0; int successes = 0;
if(argc != 2) if (argc != 2)
{ {
std::cout << "[EE] Usage:\n\t" << argv[0] << std::cout << "[EE] Usage:\n\t" << argv[0] <<
" path/to/uninstalled/test/policies" << std::endl; " path/to/uninstalled/test/policies" << std::endl;
@ -81,7 +81,7 @@ main(int argc, char** argv)
// Print out avail policies // Print out avail policies
cout << "These are the policies I found:" << endl; cout << "These are the policies I found:" << endl;
vector<CPUPolicy*>::const_iterator it = policies.begin(); vector<CPUPolicy*>::const_iterator it = policies.begin();
for(; it != policies.end(); it++) for (; it != policies.end(); it++)
cout << "\t * " << (*it)->get_name() << endl; cout << "\t * " << (*it)->get_name() << endl;
try try
@ -94,7 +94,7 @@ main(int argc, char** argv)
pgk.activate_policy(&his, pol); pgk.activate_policy(&his, pol);
pol->configure(); pol->configure();
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
cout << "configure: Caught UserInterruptException" << endl; cout << "configure: Caught UserInterruptException" << endl;
successes++; successes++;
@ -108,7 +108,7 @@ main(int argc, char** argv)
pgk.activate_policy(&his, pol); pgk.activate_policy(&his, pol);
pol->is_pre_emptive(); pol->is_pre_emptive();
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
cout << "is_preemptive: Caught UserInterruptException" << endl; cout << "is_preemptive: Caught UserInterruptException" << endl;
successes++; successes++;
@ -122,7 +122,7 @@ main(int argc, char** argv)
pgk.activate_policy(&his, pol); pgk.activate_policy(&his, pol);
pol->get_time_slice(); pol->get_time_slice();
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
cout << "get_time_slice: Caught UserInterruptException" << endl; cout << "get_time_slice: Caught UserInterruptException" << endl;
successes++; successes++;
@ -137,7 +137,7 @@ main(int argc, char** argv)
pgk.activate_policy(&his, pol); pgk.activate_policy(&his, pol);
pol->sort_queue(); pol->sort_queue();
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
cout << "sort_queue: Caught UserInterruptException" << endl; cout << "sort_queue: Caught UserInterruptException" << endl;
successes++; successes++;

View File

@ -30,7 +30,7 @@ sgpem::XMLSerializer* _serializer = NULL;
void void
sgpem__Plugin__on_init() sgpem__Plugin__on_init()
{ {
if(_serializer == NULL) if (_serializer == NULL)
_serializer = new sgpem::XMLSerializer(); _serializer = new sgpem::XMLSerializer();
} }

View File

@ -96,32 +96,32 @@ main(int argc, char** argv)
os2 << ends; // null terminated string os2 << ends; // null terminated string
cout << "dump hist(t2) in print format into os2" << endl; cout << "dump hist(t2) in print format into os2" << endl;
cout << "Comparing dump of hist(t1) and hist(t2): " << (os1.str()==os2.str()?"equals":"not equals") << endl; cout << "Comparing dump of hist(t1) and hist(t2): " << (os1.str() == os2.str() ? "equals" : "not equals") << endl;
ConcreteHistory hist2; ConcreteHistory hist2;
xmlser.restore_snapshot(outfile, hist2); xmlser.restore_snapshot(outfile, hist2);
cout << "create ConcreteHistory hist" << endl; cout << "create ConcreteHistory hist" << endl;
cout << "read XML data from file " << outfile << " and put into hist2(t3)"<< endl; cout << "read XML data from file " << outfile << " and put into hist2(t3)" << endl;
dumpEnvironment(hist2.get_last_environment(), os3); dumpEnvironment(hist2.get_last_environment(), os3);
os3 << ends; // null terminated string os3 << ends; // null terminated string
cout << "dump hist2(t3) in print format into os3" << endl; cout << "dump hist2(t3) in print format into os3" << endl;
cout << "Comparing dump of hist(t1) and hist2(t3): " << (os1.str()==os3.str()?"equals":"not equals") << endl; cout << "Comparing dump of hist(t1) and hist2(t3): " << (os1.str() == os3.str() ? "equals" : "not equals") << endl;
xmlser.restore_snapshot(outfile, hist); xmlser.restore_snapshot(outfile, hist);
cout << "read XML data from file " << outfile << " and put into hist(t4)"<< endl; cout << "read XML data from file " << outfile << " and put into hist(t4)" << endl;
dumpEnvironment(hist.get_last_environment(), os4); dumpEnvironment(hist.get_last_environment(), os4);
os4 << ends; // null terminated string os4 << ends; // null terminated string
cout << "dump hist(t3) in print format into os4" << endl; cout << "dump hist(t3) in print format into os4" << endl;
cout << "Comparing dump of hist(t1) and hist(t4): " << (os1.str()==os4.str()?"equals":"not equals") << endl; cout << "Comparing dump of hist(t1) and hist(t4): " << (os1.str() == os4.str() ? "equals" : "not equals") << endl;
int ret = 1; int ret = 1;
if(os1.str()!=os2.str() if (os1.str() != os2.str()
&& os1.str()==os3.str() && os1.str() == os3.str()
&& os1.str()==os4.str()) && os1.str() == os4.str())
{ {
cout << "test successful" << endl; cout << "test successful" << endl;
ret = 0; ret = 0;
@ -201,13 +201,13 @@ void addSomethingHistory(History &hist)
// print entire environment into the passed ostream // print entire environment into the passed ostream
void dumpEnvironment(const Environment& env, ostream &os) void dumpEnvironment(const Environment& env, ostream &os)
{ {
os << "dump environment start " <<endl; os << "dump environment start " << endl;
const Environment::Resources& rvect = env.get_resources(); const Environment::Resources& rvect = env.get_resources();
typedef Environment::Resources::const_iterator res_iterator; typedef Environment::Resources::const_iterator res_iterator;
res_iterator riter = rvect.begin(); res_iterator riter = rvect.begin();
while(riter!=rvect.end()) while (riter != rvect.end())
{ {
Resource* r = (*riter).second; Resource* r = (*riter).second;
os << " resource name: " << r->get_name() os << " resource name: " << r->get_name()
@ -221,7 +221,7 @@ void dumpEnvironment(const Environment& env, ostream &os)
proc_iterator iter = pvect.begin(); proc_iterator iter = pvect.begin();
proc_iterator end = pvect.end(); proc_iterator end = pvect.end();
while(iter!=end) while (iter != end)
{ {
Process* p = (*iter); Process* p = (*iter);
os << " process name: " << p->get_name() os << " process name: " << p->get_name()
@ -234,7 +234,7 @@ void dumpEnvironment(const Environment& env, ostream &os)
const Threads& tvect = p->get_threads(); const Threads& tvect = p->get_threads();
thr_iterator iter1 = tvect.begin(); thr_iterator iter1 = tvect.begin();
thr_iterator end1 = tvect.end(); thr_iterator end1 = tvect.end();
while(iter1!=end1) while (iter1 != end1)
{ {
Thread* t = (*iter1); Thread* t = (*iter1);
@ -247,7 +247,7 @@ void dumpEnvironment(const Environment& env, ostream &os)
const Requests& rvect = t->get_requests(); const Requests& rvect = t->get_requests();
req_iterator iter2 = rvect.begin(); req_iterator iter2 = rvect.begin();
req_iterator end2 = rvect.end(); req_iterator end2 = rvect.end();
while(iter2!=end2) while (iter2 != end2)
{ {
Request* r = (*iter2); Request* r = (*iter2);
@ -258,14 +258,15 @@ void dumpEnvironment(const Environment& env, ostream &os)
const SubRequests& srvect = r->get_subrequests(); const SubRequests& srvect = r->get_subrequests();
subreq_iterator iter3 = srvect.begin(); subreq_iterator iter3 = srvect.begin();
subreq_iterator end3 = srvect.end(); subreq_iterator end3 = srvect.end();
while(iter3!=end3) while (iter3 != end3)
{ {
SubRequest* sr = (*iter3); SubRequest* sr = (*iter3);
os << " sub request: " /* << " resource_key: " << sr->get_resource_key() */; os << " sub request: " /* << " resource_key: " << sr->get_resource_key() */;
Environment::Resources::const_iterator pos = env.get_resources().find(sr->get_resource_key()); Environment::Resources::const_iterator pos = env.get_resources().find(sr->get_resource_key());
if (pos != env.get_resources().end()) { if (pos != env.get_resources().end())
{
os << " name: " << pos->second->get_name(); os << " name: " << pos->second->get_name();
} }

View File

@ -31,12 +31,10 @@
using namespace sgpem; using namespace sgpem;
XMLSerializer::~XMLSerializer() XMLSerializer::~XMLSerializer()
{ {}
}
XMLSerializer::XMLSerializer() XMLSerializer::XMLSerializer()
{ {}
}
@ -48,10 +46,11 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
xmlDocPtr doc; xmlDocPtr doc;
doc = xmlNewDoc((const xmlChar *)"1.0"); doc = xmlNewDoc((const xmlChar *)"1.0");
if(doc!=NULL){ if (doc != NULL)
{
fill_doc(doc, hist); fill_doc(doc, hist);
int nwritten = xmlSaveFormatFile (filename.c_str(), doc, 1); int nwritten = xmlSaveFormatFile (filename.c_str(), doc, 1);
if(nwritten<0) if (nwritten < 0)
{ {
throw SerializerError("Error writing xml doc to output stream."); throw SerializerError("Error writing xml doc to output stream.");
} }
@ -80,7 +79,8 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
* build an XML tree from a the file; * build an XML tree from a the file;
*/ */
doc = xmlParseFile(filename.c_str()); doc = xmlParseFile(filename.c_str());
if (doc == NULL) { if (doc == NULL)
{
xmlCleanupParser(); xmlCleanupParser();
throw SerializerError("Parsing Error: doc is invalid."); throw SerializerError("Parsing Error: doc is invalid.");
} }
@ -101,7 +101,7 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
/* /*
* the library has been compiled without some of the old interfaces * the library has been compiled without some of the old interfaces
*/ */
#error Compilation of LIBXML with SAX1 support must be enabled #error Compilation of LIBXML with SAX1 support must be enabled
#endif /* LIBXML_SAX1_ENABLED */ #endif /* LIBXML_SAX1_ENABLED */
} }
@ -204,7 +204,7 @@ void XMLSerializer::clear_history(History& hist)
typedef std::vector<Process*>::const_iterator proc_iterator; typedef std::vector<Process*>::const_iterator proc_iterator;
proc_iterator iter = pvect.begin(); proc_iterator iter = pvect.begin();
while(iter!=pvect.end()) while (iter != pvect.end())
{ {
hist.remove(*(*iter)); hist.remove(*(*iter));
iter = pvect.begin(); iter = pvect.begin();
@ -214,7 +214,7 @@ void XMLSerializer::clear_history(History& hist)
typedef Environment::Resources::const_iterator res_iterator; typedef Environment::Resources::const_iterator res_iterator;
res_iterator riter = rvect.begin(); res_iterator riter = rvect.begin();
while(riter!=rvect.end()) while (riter != rvect.end())
{ {
hist.remove((*riter).first); hist.remove((*riter).first);
riter = rvect.begin(); riter = rvect.begin();
@ -229,7 +229,8 @@ void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(Se
*/ */
xmlNodePtr root; xmlNodePtr root;
root = xmlDocGetRootElement(doc); root = xmlDocGetRootElement(doc);
if (root == NULL) { if (root == NULL)
{
xmlFreeDoc(doc); xmlFreeDoc(doc);
xmlCleanupParser(); xmlCleanupParser();
throw SerializerError("Reading Error: xml doc is empty."); throw SerializerError("Reading Error: xml doc is empty.");
@ -237,14 +238,14 @@ void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(Se
xmlNodePtr cur; xmlNodePtr cur;
cur = root->children; cur = root->children;
while(cur!=NULL) while (cur != NULL)
{ {
Glib::ustring name((const char *)cur->name); Glib::ustring name((const char *)cur->name);
if(name=="resources") if (name == "resources")
{ {
read_resources(cur, fact); read_resources(cur, fact);
} }
if(name=="schedulables") if (name == "schedulables")
{ {
read_schedulables(cur, fact); read_schedulables(cur, fact);
} }
@ -254,15 +255,17 @@ void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(Se
XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop) XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
{ {
if(prop==NULL) if (prop == NULL)
return NULL; return NULL;
XMLSerializerFactory::Parameters* par=new XMLSerializerFactory::Parameters(); XMLSerializerFactory::Parameters* par = new XMLSerializerFactory::Parameters();
while (prop != NULL) { while (prop != NULL)
if(prop->children && xmlNodeIsText(prop->children)){ {
if (prop->children && xmlNodeIsText(prop->children))
{
xmlChar *key = xmlNodeGetContent (prop->children); xmlChar *key = xmlNodeGetContent (prop->children);
// xmlChar *key = xmlNodeListGetString(doc, prop->children, 1); // xmlChar *key = xmlNodeListGetString(doc, prop->children, 1);
if(key!=NULL) if (key != NULL)
{ {
std::pair<Glib::ustring, Glib::ustring> key_value(Glib::ustring((const char *)prop->name), Glib::ustring((const char *)key)); std::pair<Glib::ustring, Glib::ustring> key_value(Glib::ustring((const char *)prop->name), Glib::ustring((const char *)key));
par->insert(key_value); par->insert(key_value);
@ -278,14 +281,14 @@ void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFacto
{ {
xmlNodePtr cur; xmlNodePtr cur;
cur = resources_node->children; cur = resources_node->children;
while(cur!=NULL) while (cur != NULL)
{ {
Glib::ustring node_name((const char *)cur->name); Glib::ustring node_name((const char *)cur->name);
if(node_name=="resource") if (node_name == "resource")
{ {
xmlAttrPtr prop = cur->properties; xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop); XMLSerializerFactory::Parameters* par = read_properties(prop);
if(par!=NULL) if (par != NULL)
{ {
fact.factory_method(Glib::ustring("Resource"), *par); fact.factory_method(Glib::ustring("Resource"), *par);
} }
@ -297,19 +300,19 @@ void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFacto
} }
void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact) void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact)
{ {
if(schedulables_node==NULL) if (schedulables_node == NULL)
return; return;
xmlNodePtr cur; xmlNodePtr cur;
cur = schedulables_node->children; cur = schedulables_node->children;
while(cur!=NULL) while (cur != NULL)
{ {
Glib::ustring node_name((const char *)cur->name); Glib::ustring node_name((const char *)cur->name);
if(node_name=="process") if (node_name == "process")
{ {
xmlAttrPtr prop = cur->properties; xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop); XMLSerializerFactory::Parameters* par = read_properties(prop);
if(par!=NULL) if (par != NULL)
{ {
fact.factory_method(Glib::ustring("Process"), *par); fact.factory_method(Glib::ustring("Process"), *par);
} }
@ -323,19 +326,19 @@ void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerialize
void XMLSerializer::read_threads(xmlNodePtr threads_node, XMLSerializerFactory& fact) void XMLSerializer::read_threads(xmlNodePtr threads_node, XMLSerializerFactory& fact)
{ {
if(threads_node==NULL) if (threads_node == NULL)
return; return;
xmlNodePtr cur; xmlNodePtr cur;
cur = threads_node->children; cur = threads_node->children;
while(cur!=NULL) while (cur != NULL)
{ {
Glib::ustring node_name((const char *)cur->name); Glib::ustring node_name((const char *)cur->name);
if(node_name=="thread") if (node_name == "thread")
{ {
xmlAttrPtr prop = cur->properties; xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop); XMLSerializerFactory::Parameters* par = read_properties(prop);
if(par!=NULL) if (par != NULL)
{ {
fact.factory_method(Glib::ustring("Thread"), *par); fact.factory_method(Glib::ustring("Thread"), *par);
} }
@ -349,21 +352,21 @@ void XMLSerializer::read_threads(xmlNodePtr threads_node, XMLSerializerFactory&
void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory& fact) void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory& fact)
{ {
if(requests_node==NULL) if (requests_node == NULL)
{ {
return; return;
} }
xmlNodePtr cur; xmlNodePtr cur;
cur = requests_node->children; cur = requests_node->children;
while(cur!=NULL) while (cur != NULL)
{ {
Glib::ustring node_name((const char *)cur->name); Glib::ustring node_name((const char *)cur->name);
if(node_name=="request") if (node_name == "request")
{ {
xmlAttrPtr prop = cur->properties; xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop); XMLSerializerFactory::Parameters* par = read_properties(prop);
if(par!=NULL) if (par != NULL)
{ {
fact.factory_method(Glib::ustring("Request"), *par); fact.factory_method(Glib::ustring("Request"), *par);
} }
@ -377,21 +380,21 @@ void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory
void XMLSerializer::read_subrequests(xmlNodePtr subrequest_node, XMLSerializerFactory& fact) void XMLSerializer::read_subrequests(xmlNodePtr subrequest_node, XMLSerializerFactory& fact)
{ {
if(subrequest_node==NULL) if (subrequest_node == NULL)
{ {
return; return;
} }
xmlNodePtr cur; xmlNodePtr cur;
cur = subrequest_node; cur = subrequest_node;
while(cur!=NULL) while (cur != NULL)
{ {
Glib::ustring node_name((const char *)cur->name); Glib::ustring node_name((const char *)cur->name);
if(node_name=="subrequest") if (node_name == "subrequest")
{ {
xmlAttrPtr prop = cur->properties; xmlAttrPtr prop = cur->properties;
XMLSerializerFactory::Parameters* par=read_properties(prop); XMLSerializerFactory::Parameters* par = read_properties(prop);
if(par!=NULL) if (par != NULL)
{ {
fact.factory_method(Glib::ustring("SubRequest"), *par); fact.factory_method(Glib::ustring("SubRequest"), *par);
} }

View File

@ -36,12 +36,10 @@ using namespace std;
XMLSerializerFactory::XMLSerializerFactory(History& hist) XMLSerializerFactory::XMLSerializerFactory(History& hist)
: _hist(&hist) : _hist(&hist)
{ {}
}
XMLSerializerFactory::~XMLSerializerFactory() XMLSerializerFactory::~XMLSerializerFactory()
{ {}
}
History* XMLSerializerFactory::get_history() History* XMLSerializerFactory::get_history()
{ {
@ -51,23 +49,23 @@ History* XMLSerializerFactory::get_history()
void void
XMLSerializerFactory::factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializerError) XMLSerializerFactory::factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializerError)
{ {
if(class_name == "Resource") if (class_name == "Resource")
{ {
create_resource(parameters); create_resource(parameters);
} }
else if(class_name == "Process") else if (class_name == "Process")
{ {
create_process(parameters); create_process(parameters);
} }
else if(class_name == "Thread") else if (class_name == "Thread")
{ {
create_thread(parameters); create_thread(parameters);
} }
else if(class_name == "Request") else if (class_name == "Request")
{ {
create_request(parameters); create_request(parameters);
} }
else if(class_name == "SubRequest") else if (class_name == "SubRequest")
{ {
create_subrequest(parameters); create_subrequest(parameters);
} }
@ -85,23 +83,25 @@ XMLSerializerFactory::create_resource(Parameters& parameters)
Glib::ustring name; Glib::ustring name;
Glib::ustring key("0"); Glib::ustring key("0");
int arrival_time=0; int arrival_time = 0;
int how_many=1; int how_many = 1;
bool preemptable=false; bool preemptable = false;
int old_key; int old_key;
Parameters::iterator pos; Parameters::iterator pos;
// read "name" property // read "name" property
pos = parameters.find(Glib::ustring("name")); pos = parameters.find(Glib::ustring("name"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
name = pos->second; name = pos->second;
} }
// read "key" property // read "key" property
pos = parameters.find(Glib::ustring("id")); pos = parameters.find(Glib::ustring("id"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
Glib::ustring id = key = pos->second; Glib::ustring id = key = pos->second;
if(id.length()>6 && id.substr(0,6)==Glib::ustring("reskey")) if (id.length() > 6 && id.substr(0, 6) == Glib::ustring("reskey"))
{ {
key = id.substr(6); key = id.substr(6);
string_to_int(key, old_key); string_to_int(key, old_key);
@ -110,19 +110,22 @@ XMLSerializerFactory::create_resource(Parameters& parameters)
// read "preemptable" property // read "preemptable" property
pos = parameters.find(Glib::ustring("preemptable")); pos = parameters.find(Glib::ustring("preemptable"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
preemptable = (pos->second == "true"); preemptable = (pos->second == "true");
} }
// read "arrival-time" property // read "arrival-time" property
pos = parameters.find(Glib::ustring("arrival-time")); pos = parameters.find(Glib::ustring("arrival-time"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, arrival_time); string_to_int(pos->second, arrival_time);
} }
// read "how-many" property // read "how-many" property
pos = parameters.find(Glib::ustring("how-many")); pos = parameters.find(Glib::ustring("how-many"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, how_many); string_to_int(pos->second, how_many);
} }
@ -142,25 +145,28 @@ XMLSerializerFactory::create_process(Parameters& parameters)
{ {
Glib::ustring name; Glib::ustring name;
int arrival_time=0; int arrival_time = 0;
int priority=1; int priority = 1;
Parameters::iterator pos; Parameters::iterator pos;
// read "name" property // read "name" property
pos = parameters.find(Glib::ustring("name")); pos = parameters.find(Glib::ustring("name"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
name = pos->second; name = pos->second;
} }
// read "arrival-time" property // read "arrival-time" property
pos = parameters.find(Glib::ustring("arrival-time")); pos = parameters.find(Glib::ustring("arrival-time"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, arrival_time); string_to_int(pos->second, arrival_time);
} }
// read "priority" property // read "priority" property
pos = parameters.find(Glib::ustring("priority")); pos = parameters.find(Glib::ustring("priority"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, priority); string_to_int(pos->second, priority);
} }
@ -178,32 +184,36 @@ XMLSerializerFactory::create_thread(Parameters& parameters)
{ {
Glib::ustring name; Glib::ustring name;
int arrival_time=0; int arrival_time = 0;
int lasts_for=0; int lasts_for = 0;
int priority=1; int priority = 1;
Parameters::iterator pos; Parameters::iterator pos;
// read "name" property // read "name" property
pos = parameters.find(Glib::ustring("name")); pos = parameters.find(Glib::ustring("name"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
name = pos->second; name = pos->second;
} }
// read "arrival-time" property // read "arrival-time" property
pos = parameters.find(Glib::ustring("arrival-delta")); pos = parameters.find(Glib::ustring("arrival-delta"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, arrival_time); string_to_int(pos->second, arrival_time);
} }
// read "priority" property // read "priority" property
pos = parameters.find(Glib::ustring("priority")); pos = parameters.find(Glib::ustring("priority"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, priority); string_to_int(pos->second, priority);
} }
// read "priority" property // read "priority" property
pos = parameters.find(Glib::ustring("lasts-for")); pos = parameters.find(Glib::ustring("lasts-for"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, lasts_for); string_to_int(pos->second, lasts_for);
} }
@ -218,12 +228,13 @@ XMLSerializerFactory::create_request(Parameters& parameters)
// if(_hist!=NULL) // if(_hist!=NULL)
{ {
int arrival_time=0; int arrival_time = 0;
Parameters::iterator pos; Parameters::iterator pos;
// read "arrival-time" property // read "arrival-time" property
pos = parameters.find(Glib::ustring("arrival-time")); pos = parameters.find(Glib::ustring("arrival-time"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, arrival_time); string_to_int(pos->second, arrival_time);
} }
@ -238,8 +249,8 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
// if(_hist!=NULL) // if(_hist!=NULL)
{ {
int old_key=0; int old_key = 0;
int lasts_for=0; int lasts_for = 0;
//int places=1; //int places=1;
Parameters::iterator pos; Parameters::iterator pos;
resource_key_t new_key = 0; resource_key_t new_key = 0;
@ -247,12 +258,14 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
// read "arrival-time" property // read "arrival-time" property
pos = parameters.find(Glib::ustring("resource")); pos = parameters.find(Glib::ustring("resource"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, old_key); string_to_int(pos->second, old_key);
TempMap::iterator temp_pos; TempMap::iterator temp_pos;
temp_pos = _temp_map.find((resource_key_t)old_key); temp_pos = _temp_map.find((resource_key_t)old_key);
if (temp_pos != _temp_map.end()) { if (temp_pos != _temp_map.end())
{
//take key of resource in _hist //take key of resource in _hist
new_key = temp_pos->second; new_key = temp_pos->second;
} }
@ -266,7 +279,8 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
// read "priority" property // read "priority" property
pos = parameters.find(Glib::ustring("lasts-for")); pos = parameters.find(Glib::ustring("lasts-for"));
if (pos != parameters.end()) { if (pos != parameters.end())
{
string_to_int(pos->second, lasts_for); string_to_int(pos->second, lasts_for);
} }

View File

@ -37,12 +37,10 @@ using namespace sgpem;
XMLVisitor::XMLVisitor(xmlNodePtr current) XMLVisitor::XMLVisitor(xmlNodePtr current)
: _current(current) : _current(current)
{ {}
}
XMLVisitor::~XMLVisitor() XMLVisitor::~XMLVisitor()
{ {}
}
void XMLVisitor::from_resource(const Resource& obj) throw(SerializerError) void XMLVisitor::from_resource(const Resource& obj) throw(SerializerError)
{ {
@ -100,7 +98,7 @@ void XMLVisitor::from_resource(const Resource& obj, const Glib::ustring& key) th
void XMLVisitor::from_history(xmlNodePtr parent, const History& hist) throw(SerializerError) void XMLVisitor::from_history(xmlNodePtr parent, const History& hist) throw(SerializerError)
{ {
if(parent!=NULL) if (parent != NULL)
{ {
from_environment(parent, hist.get_last_environment()); from_environment(parent, hist.get_last_environment());
} }
@ -113,7 +111,7 @@ void XMLVisitor::from_history(xmlNodePtr parent, const History& hist) throw(Seri
void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) throw(SerializerError) void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) throw(SerializerError)
{ {
if(parent==NULL) if (parent == NULL)
{ {
throw SerializerError(_("Error trying to add data to empty XML node.")); throw SerializerError(_("Error trying to add data to empty XML node."));
} }
@ -127,7 +125,7 @@ void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) thr
res_iterator iter = rvect.begin(); res_iterator iter = rvect.begin();
res_iterator end = rvect.end(); res_iterator end = rvect.end();
while(iter!=end) while (iter != end)
{ {
//XMLVisitor xvisit(resources_node); //XMLVisitor xvisit(resources_node);
Glib::ustring key; Glib::ustring key;
@ -147,7 +145,7 @@ void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) thr
proc_iterator iter = pvect.begin(); proc_iterator iter = pvect.begin();
proc_iterator end = pvect.end(); proc_iterator end = pvect.end();
while(iter!=end) while (iter != end)
{ {
// XMLVisitor xvisit(schedulables_node); // XMLVisitor xvisit(schedulables_node);
// xvisit.from_process(*(*iter)); // xvisit.from_process(*(*iter));
@ -160,7 +158,7 @@ void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) thr
void XMLVisitor::from_resource(xmlNodePtr parent, const Resource& obj, const Glib::ustring& key) throw(SerializerError) void XMLVisitor::from_resource(xmlNodePtr parent, const Resource& obj, const Glib::ustring& key) throw(SerializerError)
{ {
if(parent!=NULL) if (parent != NULL)
{ {
Glib::ustring id = "reskey" + key; Glib::ustring id = "reskey" + key;
Glib::ustring strPreemptible("false"); // fixed?? Glib::ustring strPreemptible("false"); // fixed??
@ -184,7 +182,7 @@ void XMLVisitor::from_resource(xmlNodePtr parent, const Resource& obj, const Gli
void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj) throw(SerializerError) void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj) throw(SerializerError)
{ {
if(parent!=NULL) if (parent != NULL)
{ {
Glib::ustring strPriority; Glib::ustring strPriority;
Glib::ustring strArrivalTime; Glib::ustring strArrivalTime;
@ -205,7 +203,7 @@ void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj) throw(Seria
const Threads& tvect = ((Process&)obj).get_threads(); const Threads& tvect = ((Process&)obj).get_threads();
thr_iterator iter = tvect.begin(); thr_iterator iter = tvect.begin();
thr_iterator end = tvect.end(); thr_iterator end = tvect.end();
while(iter!=end) while (iter != end)
{ {
const Thread* t = *iter; const Thread* t = *iter;
@ -222,7 +220,7 @@ void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj) throw(Seria
void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(SerializerError) void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(SerializerError)
{ {
if(parent!=NULL) if (parent != NULL)
{ {
Glib::ustring strPriority; Glib::ustring strPriority;
@ -246,7 +244,7 @@ void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(Seriali
const Requests& rvect = ((Thread&)obj).get_requests(); const Requests& rvect = ((Thread&)obj).get_requests();
req_iterator iter = rvect.begin(); req_iterator iter = rvect.begin();
req_iterator end = rvect.end(); req_iterator end = rvect.end();
while(iter!=end) while (iter != end)
{ {
const Request* r = *iter; const Request* r = *iter;
@ -263,7 +261,7 @@ void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(Seriali
void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(SerializerError) void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(SerializerError)
{ {
if(parent!=NULL) if (parent != NULL)
{ {
Glib::ustring strArrivalTime; Glib::ustring strArrivalTime;
@ -280,7 +278,7 @@ void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(Seria
const SubRequests& srvect = ((Request&)obj).get_subrequests(); const SubRequests& srvect = ((Request&)obj).get_subrequests();
subreq_iterator iter = srvect.begin(); subreq_iterator iter = srvect.begin();
subreq_iterator end = srvect.end(); subreq_iterator end = srvect.end();
while(iter!=end) while (iter != end)
{ {
const SubRequest* sr = *iter; const SubRequest* sr = *iter;
from_subrequest(request_node, *(*iter)); from_subrequest(request_node, *(*iter));
@ -296,7 +294,7 @@ void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(Seria
void XMLVisitor::from_subrequest(xmlNodePtr parent, const SubRequest& obj) throw(SerializerError) void XMLVisitor::from_subrequest(xmlNodePtr parent, const SubRequest& obj) throw(SerializerError)
{ {
if(parent!=NULL) if (parent != NULL)
{ {
Glib::ustring strResource; Glib::ustring strResource;

View File

@ -50,7 +50,7 @@ ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
// Update resource pointers in a way you won't like :-) // Update resource pointers in a way you won't like :-)
{ {
for(Resources::iterator it = _resources.begin(); it != _resources.end(); it++) for (Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
it->second = new DynamicResource(dynamic_cast<const DynamicResource&>(*it->second)); it->second = new DynamicResource(dynamic_cast<const DynamicResource&>(*it->second));
} }
@ -59,7 +59,7 @@ ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
{ {
const Processes& ce_proc = ce._processes; const Processes& ce_proc = ce._processes;
insert_iterator<Processes> dest(_processes, _processes.begin()); insert_iterator<Processes> dest(_processes, _processes.begin());
for(Processes::const_iterator orig = ce_proc.begin(); orig != ce_proc.end(); orig++) for (Processes::const_iterator orig = ce_proc.begin(); orig != ce_proc.end(); orig++)
*dest++ = new DynamicProcess(dynamic_cast<const DynamicProcess&>(**orig)); *dest++ = new DynamicProcess(dynamic_cast<const DynamicProcess&>(**orig));
} }
@ -81,27 +81,27 @@ ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
typedef SubRequestQueue::iterator it5_t; typedef SubRequestQueue::iterator it5_t;
for(it1_t it1 = _processes.begin(); it1 != _processes.end(); it1++) for (it1_t it1 = _processes.begin(); it1 != _processes.end(); it1++)
{ {
const v2_t& threads = (*it1)->get_threads(); const v2_t& threads = (*it1)->get_threads();
for(it2_t it2 = threads.begin(); it2 != threads.end(); it2++) for (it2_t it2 = threads.begin(); it2 != threads.end(); it2++)
{ {
const v3_t& reqs = (*it2)->get_requests(); const v3_t& reqs = (*it2)->get_requests();
for(it3_t it3 = reqs.begin(); it3 != reqs.end(); it3++) for (it3_t it3 = reqs.begin(); it3 != reqs.end(); it3++)
{ {
// an optimization here: there is no reason in iterating through // an optimization here: there is no reason in iterating through
// future or exausted requests. (Do you know why?) // future or exausted requests. (Do you know why?)
const v4_t& subr = (*it3)->get_subrequests(); const v4_t& subr = (*it3)->get_subrequests();
for(it4_t it4 = subr.begin(); it4 != subr.end(); it4++) for (it4_t it4 = subr.begin(); it4 != subr.end(); it4++)
{ {
SubRequest::state curr_state = (*it4)->get_state(); SubRequest::state curr_state = (*it4)->get_state();
if(curr_state != Request::state_future && curr_state != Request::state_exhausted) if (curr_state != Request::state_future && curr_state != Request::state_exhausted)
{ {
// the subrequest is the following queue: // the subrequest is the following queue:
SubRequestQueue & queue = get_request_queue((*it4)->get_resource_key()); SubRequestQueue & queue = get_request_queue((*it4)->get_resource_key());
// we must replace the old pointer: // we must replace the old pointer:
bool found = false; bool found = false;
for(it5_t it5 = queue.begin(); !found && it5 != queue.end(); it5++) for (it5_t it5 = queue.begin(); !found && it5 != queue.end(); it5++)
{ {
DynamicSubRequest& _old = dynamic_cast<DynamicSubRequest&>(**it5); DynamicSubRequest& _old = dynamic_cast<DynamicSubRequest&>(**it5);
DynamicSubRequest& _new = dynamic_cast<DynamicSubRequest&>(**it4); DynamicSubRequest& _new = dynamic_cast<DynamicSubRequest&>(**it4);
@ -201,7 +201,7 @@ ConcreteEnvironment::~ConcreteEnvironment()
memory::deletor<Process>()); memory::deletor<Process>());
// We do the same with Resources. // We do the same with Resources.
for(Resources::iterator it = _resources.begin(); it != _resources.end(); it++) for (Resources::iterator it = _resources.begin(); it != _resources.end(); it++)
delete it->second; delete it->second;
// After this, the destructor of _sched_queue is invoked (only invalid pointers) // After this, the destructor of _sched_queue is invoked (only invalid pointers)

View File

@ -187,7 +187,8 @@ namespace sgpem
SubRequestQueues _sreq_queues; SubRequestQueues _sreq_queues;
}; //~ class ConcreteEnvironment }
; //~ class ConcreteEnvironment
} //~ namespace sgpem } //~ namespace sgpem

View File

@ -55,8 +55,8 @@ template<typename T>
static bool deep_remove(std::vector<T*>& v, const T& obj) static bool deep_remove(std::vector<T*>& v, const T& obj)
{ {
typedef typename std::vector<T*> Vector; typedef typename std::vector<T*> Vector;
for(typename Vector::iterator it = v.begin(); it != v.end(); it++) for (typename Vector::iterator it = v.begin(); it != v.end(); it++)
if(**it == obj) if (**it == obj)
{ {
delete *it; delete *it;
v.erase(it); v.erase(it);
@ -70,8 +70,8 @@ template<typename T>
static T* deep_find(const std::vector<T*>& v, const T& obj) static T* deep_find(const std::vector<T*>& v, const T& obj)
{ {
typedef typename std::vector<T*> Vector; typedef typename std::vector<T*> Vector;
for(typename Vector::const_iterator it = v.begin(); it != v.end(); it++) for (typename Vector::const_iterator it = v.begin(); it != v.end(); it++)
if(**it == obj) if (**it == obj)
{ {
return *it; return *it;
} }
@ -98,7 +98,7 @@ ConcreteHistory::ConcreteHistory(const ConcreteHistory& h) :
History(h) History(h)
{ {
typedef Snapshots::const_iterator SnapIt; typedef Snapshots::const_iterator SnapIt;
for(SnapIt it = h._snapshots.begin(); it != h._snapshots.end(); ++it) for (SnapIt it = h._snapshots.begin(); it != h._snapshots.end(); ++it)
_snapshots.push_back(new ConcreteEnvironment(*(*it))); _snapshots.push_back(new ConcreteEnvironment(*(*it)));
} }
@ -128,7 +128,7 @@ ConcreteHistory::get_last_environment() const
const ConcreteEnvironment& const ConcreteEnvironment&
ConcreteHistory::get_environment_at(position index) const ConcreteHistory::get_environment_at(position index) const
throw(std::out_of_range) throw(std::out_of_range)
{ {
return *_snapshots.at(index); return *_snapshots.at(index);
} }
@ -141,7 +141,7 @@ ConcreteHistory::remove(resource_key_t resource_key)
ConcreteEnvironment& initial = *_snapshots.front(); ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Resources& resources = initial.get_resources(); ConcreteEnvironment::Resources& resources = initial.get_resources();
ConcreteEnvironment::Resources::iterator found = resources.find(resource_key); ConcreteEnvironment::Resources::iterator found = resources.find(resource_key);
if(found == resources.end()) if (found == resources.end())
return; return;
reset(false); reset(false);
@ -168,18 +168,18 @@ ConcreteHistory::remove(resource_key_t resource_key)
// all hail the cyclomatic complexity! // all hail the cyclomatic complexity!
ConcreteEnvironment::Processes& processes = initial.get_processes(); ConcreteEnvironment::Processes& processes = initial.get_processes();
typedef ConcreteEnvironment::Processes::iterator ProcIt; typedef ConcreteEnvironment::Processes::iterator ProcIt;
for(ProcIt it1 = processes.begin(); it1 != processes.end(); it1++) for (ProcIt it1 = processes.begin(); it1 != processes.end(); it1++)
{ {
Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads(); Threads& threads = dynamic_cast<DynamicProcess&>(**it1).get_dynamic_threads();
for(Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++) for (Threads::iterator it2 = threads.begin(); it2 != threads.end(); it2++)
{ {
Requests& reqs = (*it2)->get_dynamic_requests(); Requests& reqs = (*it2)->get_dynamic_requests();
for(Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++) for (Requests::iterator it3 = reqs.begin(); it3 != reqs.end(); it3++)
{ {
SubRequests& subr = (*it3)->get_dynamic_subrequests(); SubRequests& subr = (*it3)->get_dynamic_subrequests();
SubRequests::iterator it4 = subr.begin(); SubRequests::iterator it4 = subr.begin();
while(it4 != subr.end()) while (it4 != subr.end())
if((*it4)->get_resource_key() == resource_key) if ((*it4)->get_resource_key() == resource_key)
{ {
delete *it4; delete *it4;
it4 = subr.erase(it4); it4 = subr.erase(it4);
@ -204,7 +204,7 @@ ConcreteHistory::remove(Process& process)
ConcreteEnvironment& initial = *_snapshots.front(); ConcreteEnvironment& initial = *_snapshots.front();
ConcreteEnvironment::Processes& processes = initial.get_processes(); ConcreteEnvironment::Processes& processes = initial.get_processes();
bool found = deep_remove<Process>(processes, process); bool found = deep_remove<Process>(processes, process);
if(found) if (found)
reset(true); reset(true);
} }
@ -220,13 +220,13 @@ ConcreteHistory::remove(Thread& thread)
Process* found = deep_find<Process>(processes, dyn_thr.get_process()); Process* found = deep_find<Process>(processes, dyn_thr.get_process());
if(found == NULL) if (found == NULL)
return; // not found, just return. return; // not found, just return.
DynamicProcess& dynamic_found = dynamic_cast<DynamicProcess&>(*found); DynamicProcess& dynamic_found = dynamic_cast<DynamicProcess&>(*found);
bool removed = deep_remove<DynamicThread>(dynamic_found.get_dynamic_threads(), dyn_thr); bool removed = deep_remove<DynamicThread>(dynamic_found.get_dynamic_threads(), dyn_thr);
if(removed) if (removed)
reset(true); reset(true);
} }
@ -244,15 +244,15 @@ ConcreteHistory::remove(Request& request)
Process* proc_ref = deep_find<Process>(processes, dyn_proc); Process* proc_ref = deep_find<Process>(processes, dyn_proc);
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref); DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
if(dyn_proc_ref == NULL) if (dyn_proc_ref == NULL)
return; // not found, just return. return; // not found, just return.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr); DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
if(thr_ref == NULL) if (thr_ref == NULL)
return; // not found, just return. return; // not found, just return.
bool removed = deep_remove<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req); bool removed = deep_remove<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
if(removed) if (removed)
reset(true); reset(true);
} }
@ -274,18 +274,18 @@ ConcreteHistory::remove(SubRequest& subrequest)
Process* proc_ref = deep_find<Process>(processes, dyn_proc); Process* proc_ref = deep_find<Process>(processes, dyn_proc);
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref); DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
if(dyn_proc_ref == NULL) if (dyn_proc_ref == NULL)
return; // not found, just return. return; // not found, just return.
DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr); DynamicThread* thr_ref = deep_find<DynamicThread>(dyn_proc_ref->get_dynamic_threads(), dyn_thr);
if(thr_ref == NULL) if (thr_ref == NULL)
return; // not found, just return. return; // not found, just return.
DynamicRequest* req_ref = deep_find<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req); DynamicRequest* req_ref = deep_find<DynamicRequest>(thr_ref->get_dynamic_requests(), dyn_req);
if(req_ref == NULL) if (req_ref == NULL)
return; // not found, just return. return; // not found, just return.
bool removed = deep_remove<DynamicSubRequest>(req_ref->get_dynamic_subrequests(), dyn_sub); bool removed = deep_remove<DynamicSubRequest>(req_ref->get_dynamic_subrequests(), dyn_sub);
if(removed) if (removed)
reset(true); reset(true);
} }
@ -309,15 +309,15 @@ ConcreteHistory::add_resource(const Glib::ustring& name,
// alakazam! Black magic at work... get a unique index for this resource // alakazam! Black magic at work... get a unique index for this resource
resource_key_t index = 0; resource_key_t index = 0;
while(resources.find(index) != resources.end()) while (resources.find(index) != resources.end())
index++; index++;
// Found a hole in the map, fill it like little Hans, // Found a hole in the map, fill it like little Hans,
// its finger and the spilling dam. // its finger and the spilling dam.
Resources::iterator temp = resources.insert(pair<resource_key_t,Resource*>(index, resource)).first; Resources::iterator temp = resources.insert(pair<resource_key_t, Resource*>(index, resource)).first;
// The same for request queues. // The same for request queues.
SubRequestQueue emptysrq; SubRequestQueue emptysrq;
_snapshots.front()->get_subrequest_queues().insert(pair<resource_key_t,SubRequestQueue>(index, emptysrq)); _snapshots.front()->get_subrequest_queues().insert(pair<resource_key_t, SubRequestQueue>(index, emptysrq));
notify_change(); notify_change();
@ -412,7 +412,7 @@ ConcreteHistory::reset(bool notify)
for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>()); for_each(it, _snapshots.end(), deletor<ConcreteEnvironment>());
_snapshots.resize(1); // Truncate to keep only our "model" _snapshots.resize(1); // Truncate to keep only our "model"
if(notify) if (notify)
notify_change(); notify_change();
} }
@ -420,6 +420,6 @@ void
ConcreteHistory::notify_change() ConcreteHistory::notify_change()
{ {
History::RegisteredObservers::iterator it; History::RegisteredObservers::iterator it;
for(it =_observers.begin(); it != _observers.end(); it++) for (it = _observers.begin(); it != _observers.end(); it++)
(*it)->update(*this); (*it)->update(*this);
} }

View File

@ -95,7 +95,8 @@ namespace sgpem
// Disable assignment, implement it only if needed // Disable assignment, implement it only if needed
ConcreteHistory& operator=(const ConcreteHistory& op2); ConcreteHistory& operator=(const ConcreteHistory& op2);
}; //~ class ConcreteHistory }
; //~ class ConcreteHistory
}//~ namespace sgpem }//~ namespace sgpem

View File

@ -75,7 +75,7 @@ ConcreteSimulation::stop()
void void
ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException) ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
{ {
switch(_state) switch (_state)
{ {
case state_running: case state_running:
return; return;
@ -88,7 +88,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
_state = state_running; _state = state_running;
if(get_policy() == NULL) if (get_policy() == NULL)
{ {
stop(); stop();
throw NullPolicyException("no policy selected"); throw NullPolicyException("no policy selected");
@ -103,12 +103,12 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
{ {
//step forward //step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy()); bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if(!yet_to_finish) stop(); if (!yet_to_finish) stop();
//sleep //sleep
Glib::usleep(_timer_interval*1000); Glib::usleep(_timer_interval*1000);
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
stop(); stop();
throw; throw;
@ -118,7 +118,7 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
if (_state == state_stopped || _state == state_paused) if (_state == state_stopped || _state == state_paused)
return; return;
} }
while(true); while (true);
} }
//******* STEP by STEP //******* STEP by STEP
@ -129,12 +129,12 @@ ConcreteSimulation::run() throw(UserInterruptException, NullPolicyException)
assert(get_policy() != NULL); assert(get_policy() != NULL);
//step forward //step forward
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy()); bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
if(yet_to_finish) if (yet_to_finish)
pause(); pause();
else else
stop(); stop();
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
stop(); stop();
throw; throw;
@ -159,7 +159,7 @@ ConcreteSimulation::set_policy(CPUPolicy* p)
{ {
_policy = p; _policy = p;
if(p != NULL) if (p != NULL)
CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p); CPUPoliciesGatekeeper::get_instance().activate_policy(&_history, p);
} }

View File

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

View File

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

View File

@ -46,7 +46,7 @@ DynamicProcess::DynamicProcess(const DynamicProcess &other) :
const vector<DynamicThread*>& other_threads = other._dynamic_threads; const vector<DynamicThread*>& other_threads = other._dynamic_threads;
for(ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it) for (ThreadIt it = other_threads.begin(); it != other_threads.end(); ++it)
new DynamicThread(*(*it), this); new DynamicThread(*(*it), this);
} }
@ -81,7 +81,7 @@ DynamicProcess::get_state() const
unsigned int closest = 0; unsigned int closest = 0;
vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin(); vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
for(; it != _dynamic_threads.end(); it++) for (; it != _dynamic_threads.end(); it++)
{ {
if ((**it).get_state() == state_running) running++; if ((**it).get_state() == state_running) running++;
if ((**it).get_state() == state_ready) ready++; if ((**it).get_state() == state_ready) ready++;
@ -225,7 +225,7 @@ unsigned int
DynamicProcess::get_elapsed_time() const DynamicProcess::get_elapsed_time() const
{ {
unsigned int result = 0; unsigned int result = 0;
for(std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin(); for (std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++) it != _dynamic_threads.end(); it++)
{ {
result += (*it)->get_elapsed_time(); result += (*it)->get_elapsed_time();
@ -237,11 +237,11 @@ int
DynamicProcess::get_last_acquisition() const DynamicProcess::get_last_acquisition() const
{ {
int result = -1; int result = -1;
for(std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin(); for (std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++) it != _dynamic_threads.end(); it++)
{ {
int acq = (*it)->get_last_acquisition(); int acq = (*it)->get_last_acquisition();
if(result < acq) if (result < acq)
result = acq; result = acq;
} }
return result; return result;
@ -251,11 +251,11 @@ int
DynamicProcess::get_last_release() const DynamicProcess::get_last_release() const
{ {
int result = -1; int result = -1;
for(std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin(); for (std::vector<DynamicThread*>::const_iterator it = _dynamic_threads.begin();
it != _dynamic_threads.end(); it++) it != _dynamic_threads.end(); it++)
{ {
int acq = (*it)->get_last_release(); int acq = (*it)->get_last_release();
if(result < acq) if (result < acq)
result = acq; result = acq;
} }
return result; return result;

View File

@ -58,7 +58,7 @@ DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner
// Not sure of this, but the constructor of DynamicSubRequest should take care // Not sure of this, but the constructor of DynamicSubRequest should take care
// of adding itself to the vector of sub requests. This is only my opinion, // of adding itself to the vector of sub requests. This is only my opinion,
// but I think this is a complicated way of doing things... // but I think this is a complicated way of doing things...
for(SubReqVec::const_iterator it = other_subs.begin(); it != other_subs.end(); ++it) for (SubReqVec::const_iterator it = other_subs.begin(); it != other_subs.end(); ++it)
new DynamicSubRequest(*(*it), this); new DynamicSubRequest(*(*it), this);
// Leave this line: it helps us with a compiler warning if // Leave this line: it helps us with a compiler warning if
@ -122,11 +122,11 @@ DynamicRequest::get_state() const
#endif // ~NDEBUG #endif // ~NDEBUG
const SubReqs& sreqs = _dynamic_subrequests; const SubReqs& sreqs = _dynamic_subrequests;
for(SubReqs::const_iterator it = sreqs.begin(); it != sreqs.end(); it++) for (SubReqs::const_iterator it = sreqs.begin(); it != sreqs.end(); it++)
{ {
SubRequest& cur = **it; SubRequest& cur = **it;
switch(cur.get_state()) switch (cur.get_state())
{ {
case state_allocated: case state_allocated:
return state_allocated; return state_allocated;
@ -139,7 +139,7 @@ DynamicRequest::get_state() const
// have the same state since state_allocable, // have the same state since state_allocable,
// state_terminated and state_future are mutually // state_terminated and state_future are mutually
// exclusive // exclusive
if(at_least_once) if (at_least_once)
assert(result == cur.get_state()); assert(result == cur.get_state());
at_least_once = true; at_least_once = true;
#endif //~ NDEBUG #endif //~ NDEBUG

View File

@ -37,8 +37,8 @@ DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
{ {
assert(core != NULL); assert(core != NULL);
assert(owner != NULL); assert(owner != NULL);
// Leave this line: it helps us with a compiler warning if // Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes: // the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests(); std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this); siblings.push_back(this);
} }
@ -51,15 +51,14 @@ DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other,
{ {
assert(owner != NULL); assert(owner != NULL);
// Leave this line: it helps us with a compiler warning if // Leave this line: it helps us with a compiler warning if
// the get_dynamic* method signature changes: // the get_dynamic* method signature changes:
std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests(); std::vector<DynamicSubRequest*>& siblings = owner->get_dynamic_subrequests();
siblings.push_back(this); siblings.push_back(this);
} }
DynamicSubRequest::~DynamicSubRequest() DynamicSubRequest::~DynamicSubRequest()
{ {}
}
bool bool
@ -131,7 +130,7 @@ DynamicSubRequest::decrease_remaining_time()
{ {
assert(_state == Request::state_allocated); assert(_state == Request::state_allocated);
unsigned int temp = get_remaining_time(); unsigned int temp = get_remaining_time();
if(temp > 0) if (temp > 0)
_ran_for++; _ran_for++;
return temp; return temp;

View File

@ -59,7 +59,7 @@ DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent)
const vector<DynamicRequest*>& other_req = other._dynamic_requests; const vector<DynamicRequest*>& other_req = other._dynamic_requests;
for(ReqIt it = other_req.begin(); it != other_req.end(); ++it) for (ReqIt it = other_req.begin(); it != other_req.end(); ++it)
new DynamicRequest(*(*it), this); new DynamicRequest(*(*it), this);
// Leave this line: it helps us with a compiler warning if // Leave this line: it helps us with a compiler warning if
@ -140,7 +140,7 @@ DynamicThread::decrease_remaining_time()
{ {
// strict check for us to better debug scheduler // strict check for us to better debug scheduler
assert(_ran_for < get_total_cpu_time()); assert(_ran_for < get_total_cpu_time());
if(_ran_for < get_total_cpu_time()) if (_ran_for < get_total_cpu_time())
_ran_for++; _ran_for++;
} }

View File

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

View File

@ -41,18 +41,18 @@ namespace sgpem
// read modules directories // read modules directories
{ {
const Glib::ustring* val = search_value(Glib::ustring("modules-dir-number")); const Glib::ustring* val = search_value(Glib::ustring("modules-dir-number"));
if(val) if (val)
{ {
std::istringstream istr(val->c_str()); std::istringstream istr(val->c_str());
int n; int n;
istr >> n; istr >> n;
for(int i=1; i<=n; i++) for (int i = 1; i <= n; i++)
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << "modules-dir-" << i << std::ends; ostr << "modules-dir-" << i << std::ends;
Glib::ustring key(ostr.str()); Glib::ustring key(ostr.str());
val = search_value(key); val = search_value(key);
if(val) if (val)
{ {
_globalPreferences.add_modules_dir(*val); _globalPreferences.add_modules_dir(*val);
} }
@ -63,18 +63,18 @@ namespace sgpem
// read policies directories // read policies directories
{ {
const Glib::ustring* val = search_value(Glib::ustring("policies-dir-number")); const Glib::ustring* val = search_value(Glib::ustring("policies-dir-number"));
if(val) if (val)
{ {
std::istringstream istr(val->c_str()); std::istringstream istr(val->c_str());
int n; int n;
istr >> n; istr >> n;
for(int i=1; i<=n; i++) for (int i = 1; i <= n; i++)
{ {
std::ostringstream ostr; std::ostringstream ostr;
ostr << "policies-dir-" << i << std::ends; ostr << "policies-dir-" << i << std::ends;
Glib::ustring key(ostr.str()); Glib::ustring key(ostr.str());
val = search_value(key); val = search_value(key);
if(val) if (val)
{ {
_globalPreferences.add_policies_dir(*val); _globalPreferences.add_policies_dir(*val);
} }
@ -88,9 +88,10 @@ namespace sgpem
{ {
// add modules directories // add modules directories
{ {
GlobalPreferences::dir_iterator iter=_globalPreferences.modules_dir_begin(); GlobalPreferences::dir_iterator iter = _globalPreferences.modules_dir_begin();
int n=0; int n = 0;
while(iter!=_globalPreferences.modules_dir_end()){ while (iter != _globalPreferences.modules_dir_end())
{
std::ostringstream ostr; std::ostringstream ostr;
n++; n++;
ostr << "modules-dir-" << n << std::ends; ostr << "modules-dir-" << n << std::ends;
@ -106,9 +107,10 @@ namespace sgpem
} }
// add policies directories // add policies directories
{ {
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin(); GlobalPreferences::dir_iterator iter = _globalPreferences.policies_dir_begin();
int n=0; int n = 0;
while(iter!=_globalPreferences.policies_dir_end()){ while (iter != _globalPreferences.policies_dir_end())
{
std::ostringstream ostr; std::ostringstream ostr;
n++; n++;
ostr << "policies-dir-" << n << std::ends; ostr << "policies-dir-" << n << std::ends;

View File

@ -31,13 +31,11 @@ using namespace std;
History::History() History::History()
: _notify(true) : _notify(true)
{ {}
}
History::~History() History::~History()
{ {}
}
void void
@ -59,9 +57,9 @@ History::detach(const HistoryObserver& observer)
void void
History::notify_change() History::notify_change()
{ {
if(!_notify) return; if (!_notify) return;
for(RegisteredObservers::iterator it =_observers.begin(); for (RegisteredObservers::iterator it = _observers.begin();
it != _observers.end(); it++) it != _observers.end(); it++)
(*it)->update(*this); (*it)->update(*this);
} }
@ -74,7 +72,7 @@ History::set_notify_enabled(bool enabled)
_notify = enabled; _notify = enabled;
// Force notify if we re-enable it // Force notify if we re-enable it
if(old_value == false && _notify == true) if (old_value == false && _notify == true)
notify_change(); notify_change();
return old_value; return old_value;

View File

@ -123,7 +123,8 @@ namespace sgpem
private: private:
bool _notify; bool _notify;
}; //~ class History }
; //~ class History
}//~ namespace sgpem }//~ namespace sgpem

View File

@ -34,7 +34,8 @@ namespace sgpem
virtual void update(const History& changed_history) = 0; virtual void update(const History& changed_history) = 0;
virtual ~HistoryObserver(); virtual ~HistoryObserver();
}; // class HistoryObserver }
; // class HistoryObserver
}//~ namespace sgpem }//~ namespace sgpem

View File

@ -37,26 +37,26 @@ HoltGraph::update(const History& changed_history)
_active_threads.clear(); _active_threads.clear();
_active_requests.clear(); _active_requests.clear();
for(unsigned int pi = 0; pi < processes.size(); ++pi) for (unsigned int pi = 0; pi < processes.size(); ++pi)
{ {
vector<Thread*> threads = processes[pi]->get_threads(); vector<Thread*> threads = processes[pi]->get_threads();
for(unsigned int ti = 0; ti < threads.size(); ++ti) for (unsigned int ti = 0; ti < threads.size(); ++ti)
{ {
vector<Request*> requests = threads[ti]->get_requests(); vector<Request*> requests = threads[ti]->get_requests();
for(unsigned int ri = 0; ri < requests.size(); ++ri) for (unsigned int ri = 0; ri < requests.size(); ++ri)
{ {
Request& r = *requests[ri]; Request& r = *requests[ri];
if(r.get_state() == Request::state_allocated) if (r.get_state() == Request::state_allocated)
{ {
_active_requests.push_back(&r); _active_requests.push_back(&r);
_active_threads.insert(&r.get_thread()); _active_threads.insert(&r.get_thread());
vector<SubRequest*> subrequests = r.get_subrequests(); vector<SubRequest*> subrequests = r.get_subrequests();
for(unsigned int sri = 0; sri < subrequests.size(); ++sri) for (unsigned int sri = 0; sri < subrequests.size(); ++sri)
{ {
Environment::resource_key_t key = subrequests[sri]->get_resource_key(); Environment::resource_key_t key = subrequests[sri]->get_resource_key();

View File

@ -56,7 +56,8 @@ namespace sgpem
std::set<const Resource*> _resources; std::set<const Resource*> _resources;
std::set<const Thread*> _active_threads; std::set<const Thread*> _active_threads;
Requests _active_requests; Requests _active_requests;
}; // class HistoryObserver }
; // class HistoryObserver
}//~ namespace sgpem }//~ namespace sgpem

View File

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

View File

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

View File

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

View File

@ -35,11 +35,11 @@ Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
get_author_ptr(NULL), get_author_ptr(NULL),
get_version_ptr(NULL) get_version_ptr(NULL)
{ {
if(!*this) throw InvalidPluginException(Module::get_last_error()); if (!*this) throw InvalidPluginException(Module::get_last_error());
// Type-safeness here is an optional, as always. :-) // Type-safeness here is an optional, as always. :-)
std::string prefix = "sgpem__Plugin__"; std::string prefix = "sgpem__Plugin__";
if(!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) && if (!(get_symbol(prefix + "on_init", (void*&) on_init_ptr) &&
get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) && get_symbol(prefix + "on_exit", (void*&) on_exit_ptr) &&
get_symbol(prefix + "describe", (void*&) describe_ptr) && get_symbol(prefix + "describe", (void*&) describe_ptr) &&
get_symbol(prefix + "get_name", (void*&) get_name_ptr) && get_symbol(prefix + "get_name", (void*&) get_name_ptr) &&
@ -52,10 +52,10 @@ Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
void void
Module::set_enabled(bool enabled) Module::set_enabled(bool enabled)
{ {
if(_enabled == enabled) if (_enabled == enabled)
return; return;
if(enabled) if (enabled)
on_init_ptr(); on_init_ptr();
else else
on_exit_ptr(); on_exit_ptr();

View File

@ -64,7 +64,8 @@ namespace sgpem
f_ustring get_author_ptr; f_ustring get_author_ptr;
f_float get_version_ptr; f_float get_version_ptr;
}; //~ class Module }
; //~ class Module
} //~ namespace sgpem } //~ namespace sgpem

View File

@ -59,14 +59,14 @@ PluginManager::rescan_dirs()
Glib::PatternSpec shared_obj(Glib::ustring("*.") + G_MODULE_SUFFIX); Glib::PatternSpec shared_obj(Glib::ustring("*.") + G_MODULE_SUFFIX);
while(it != prefs.modules_dir_end()) while (it != prefs.modules_dir_end())
{ {
Glib::Dir dir(*it); Glib::Dir dir(*it);
for(Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it) for (Glib::DirIterator dir_it = dir.begin(); dir_it != dir.end(); ++dir_it)
{ {
// only attempt to load .so files // only attempt to load .so files
if(shared_obj.match(*dir_it)) if (shared_obj.match(*dir_it))
{ {
std::string module_path = Module::build_path(*it, *dir_it); std::string module_path = Module::build_path(*it, *dir_it);
@ -78,7 +78,7 @@ PluginManager::rescan_dirs()
_modules.push_back(module); _modules.push_back(module);
std::cerr << "\tSuccess" << std::endl; std::cerr << "\tSuccess" << std::endl;
} }
catch(InvalidPluginException e) catch (InvalidPluginException e)
{ {
std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl; std::cerr << "\tFailed, invalid plugin: " << e.what() << std::endl;
} }

View File

@ -49,7 +49,8 @@ namespace sgpem
std::vector<Module*> _modules; std::vector<Module*> _modules;
}; //~ class PluginManager }
; //~ class PluginManager
} //~ namespace sgpem } //~ namespace sgpem

View File

@ -27,9 +27,9 @@ using sgpem::ReadyQueue;
void void
ReadyQueue::swap(position a, position b) ReadyQueue::swap(position a, position b)
throw (std::out_of_range) throw (std::out_of_range)
{ {
if(a == b) return; if (a == b) return;
// Usage of "at()" isn't casual: // Usage of "at()" isn't casual:
// at() checks indexes, "[]" doesn't. // at() checks indexes, "[]" doesn't.
@ -51,7 +51,7 @@ ReadyQueue::size() const
sgpem::Thread& sgpem::Thread&
ReadyQueue::get_item_at(position index) ReadyQueue::get_item_at(position index)
throw (std::out_of_range) throw (std::out_of_range)
{ {
// Checks index access // Checks index access
return *_scheds.at(index); return *_scheds.at(index);
@ -59,7 +59,7 @@ ReadyQueue::get_item_at(position index)
const sgpem::Thread& const sgpem::Thread&
ReadyQueue::get_item_at(position index) const ReadyQueue::get_item_at(position index) const
throw (std::out_of_range) throw (std::out_of_range)
{ {
// Checks index access // Checks index access
return *_scheds.at(index); return *_scheds.at(index);

View File

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

View File

@ -50,7 +50,7 @@ typedef std::vector<DynamicThread*> Threads;
class Extender class Extender
{ {
public: public:
enum walk_purpose enum walk_purpose
{ {
@ -281,7 +281,7 @@ class Extender
} }
} }
} }
/* /*
// the following methods are never used in step forward (by now) // the following methods are never used in step forward (by now)
@ -390,9 +390,9 @@ class Extender
} }
} }
// /// If the thread is runnable, we may need to refill its quantum. // /// If the thread is runnable, we may need to refill its quantum.
// if (t.state == "RUNNING" && t.remaining_quantum == 0) // if (t.state == "RUNNING" && t.remaining_quantum == 0)
// t.remaining_quantum = quantum_size; // t.remaining_quantum = quantum_size;
} }
break; break;
} }
@ -400,12 +400,12 @@ class Extender
} }
front = old_front; front = old_front;
} }
*/ */
// private class members // private class members
private: private:
auto_ptr<ConcreteEnvironment> & env; auto_ptr<ConcreteEnvironment> & env;
int walk; int walk;
@ -440,7 +440,7 @@ collect_threads(const std::vector<Process*>& procs,
typedef std::vector<DynamicThread*> Threads; typedef std::vector<DynamicThread*> Threads;
collected_threads.clear(); collected_threads.clear();
for(Processes::const_iterator it1 = procs.begin(); it1 != procs.end(); it1++) for (Processes::const_iterator it1 = procs.begin(); it1 != procs.end(); it1++)
{ {
const Threads& ts = ((DynamicProcess&) **it1).get_dynamic_threads(); const Threads& ts = ((DynamicProcess&) **it1).get_dynamic_threads();
collected_threads.insert(collected_threads.end(), ts.begin(), ts.end()); collected_threads.insert(collected_threads.end(), ts.begin(), ts.end());
@ -454,9 +454,9 @@ static void prepare_ready_queue(ConcreteEnvironment& snapshot,
ReadyQueue& queue = snapshot.get_sorted_queue(); ReadyQueue& queue = snapshot.get_sorted_queue();
assert(queue.size() == 0); assert(queue.size() == 0);
for(Threads::const_iterator it = all_threads.begin(); for (Threads::const_iterator it = all_threads.begin();
it != all_threads.end(); it++) it != all_threads.end(); it++)
if((*it)->get_state() == Schedulable::state_ready) if ((*it)->get_state() == Schedulable::state_ready)
queue.append(**it); queue.append(**it);
} }
@ -468,8 +468,7 @@ static void prepare_ready_queue(ConcreteEnvironment& snapshot,
//private constructor. The parameter is discarded //private constructor. The parameter is discarded
Scheduler::Scheduler() Scheduler::Scheduler()
: _ready_queue(NULL), _policy(NULL), _step_mutex() : _ready_queue(NULL), _policy(NULL), _step_mutex()
{ {}
}
ReadyQueue* ReadyQueue*
@ -504,7 +503,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// store a readyqueue and policy pointer for the user-policy to retrieve, to when // store a readyqueue and policy pointer for the user-policy to retrieve, to when
// the policy returns // the policy returns
// TODO: restrict this area to maximise parallelism // TODO: restrict this area to maximise parallelism
Glib::Mutex::Lock lock(_step_mutex); Glib::Mutex::Lock lock (_step_mutex);
// NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method! // NOTE: Be sure to read the *ORIGINAL* documentation in the design document for this method!
@ -527,19 +526,19 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// designer + implementer (Matteo) comment follows: // designer + implementer (Matteo) comment follows:
for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++) for (Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
{ {
DynamicThread& current = **it; DynamicThread& current = **it;
// 1. mark future threads as ready, if appropriate // 1. mark future threads as ready, if appropriate
if(current.get_state() == Schedulable::state_future) if (current.get_state() == Schedulable::state_future)
{ {
// if there is at least a future process, don't terminate the simulation // if there is at least a future process, don't terminate the simulation
Process& parent = current.get_process(); Process& parent = current.get_process();
if (parent.get_state() == Schedulable::state_future) if (parent.get_state() == Schedulable::state_future)
simulation_ended = false; simulation_ended = false;
// start a thread only if its parent is arrived! // start a thread only if its parent is arrived!
if(parent.get_arrival_time() <= current_instant && parent.get_elapsed_time() == current.get_arrival_time()) if (parent.get_arrival_time() <= current_instant && parent.get_elapsed_time() == current.get_arrival_time())
{ {
current.set_state(Schedulable::state_ready); current.set_state(Schedulable::state_ready);
// in this way we will never have threads ready having remaining time == 0 // in this way we will never have threads ready having remaining time == 0
@ -550,7 +549,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// Save the current running thread for future usage, if it hasn't ended // Save the current running thread for future usage, if it hasn't ended
// its allotted time // its allotted time
if(current.get_state() == Schedulable::state_running) if (current.get_state() == Schedulable::state_running)
{ {
assert(running_thread == NULL); // ... and one to bind them all. assert(running_thread == NULL); // ... and one to bind them all.
running_thread = &current; // Even if we change its state to terminate running_thread = &current; // Even if we change its state to terminate
@ -558,24 +557,24 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// increasing the time elapsed of the running thread + process // increasing the time elapsed of the running thread + process
// should be done here as the first thing, instead than // should be done here as the first thing, instead than
// directly after selecting them // directly after selecting them
if(current.get_total_cpu_time() - current.get_elapsed_time() > 0) if (current.get_total_cpu_time() - current.get_elapsed_time() > 0)
current.decrease_remaining_time(); current.decrease_remaining_time();
// 2. mark threads that used all their allotted time as terminated // 2. mark threads that used all their allotted time as terminated
if(current.get_total_cpu_time() - current.get_elapsed_time() == 0) if (current.get_total_cpu_time() - current.get_elapsed_time() == 0)
current.set_state(Schedulable::state_terminated); current.set_state(Schedulable::state_terminated);
} }
// 3. check for simulation termination (we can directly use threads // 3. check for simulation termination (we can directly use threads
// for this check, since processes' state is based upon threads' one) // for this check, since processes' state is based upon threads' one)
if( /* we still think that */ simulation_ended && if ( /* we still think that */ simulation_ended &&
(current.get_state() & (Schedulable::state_blocked | (current.get_state() & (Schedulable::state_blocked |
Schedulable::state_terminated)) == 0) Schedulable::state_terminated)) == 0)
simulation_ended = false; simulation_ended = false;
} }
// 4a. Look for exhausted requests for the running thread // 4a. Look for exhausted requests for the running thread
if(running_thread != NULL) if (running_thread != NULL)
{ {
bool running_terminated = running_thread->get_state() == Schedulable::state_terminated; bool running_terminated = running_thread->get_state() == Schedulable::state_terminated;
Extender e(new_snapshot, Extender e(new_snapshot,
@ -583,17 +582,17 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
running_thread->get_elapsed_time()); running_thread->get_elapsed_time());
Requests& reqs = running_thread->get_dynamic_requests(); Requests& reqs = running_thread->get_dynamic_requests();
for(Requests::iterator r_it = reqs.begin(); r_it != reqs.end(); r_it++) for (Requests::iterator r_it = reqs.begin(); r_it != reqs.end(); r_it++)
e.extendRequest(**r_it); e.extendRequest(**r_it);
} }
// Unblock blocked threads.. by discovering just-now-allocable requests // Unblock blocked threads.. by discovering just-now-allocable requests
for(Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++) for (Threads::iterator it = all_threads.begin(); it != all_threads.end(); it++)
{ {
DynamicThread& current = **it; DynamicThread& current = **it;
// for each still blocked thread // for each still blocked thread
if(current.get_state() == Schedulable::state_blocked) if (current.get_state() == Schedulable::state_blocked)
{ {
// Since it was blocked then one and only one (why?) request is unallocable. // Since it was blocked then one and only one (why?) request is unallocable.
// lets' find it and see if our information is outdated (i.e. now it is // lets' find it and see if our information is outdated (i.e. now it is
@ -602,7 +601,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// for each request // for each request
Requests& reqs = current.get_dynamic_requests(); Requests& reqs = current.get_dynamic_requests();
Extender e(new_snapshot, Extender::walk_to_advance, current.get_elapsed_time()); Extender e(new_snapshot, Extender::walk_to_advance, current.get_elapsed_time());
for(Requests::iterator r_it = reqs.begin(); r_it != reqs.end() && !blocked; r_it++) for (Requests::iterator r_it = reqs.begin(); r_it != reqs.end() && !blocked; r_it++)
{ {
// update its state. // update its state.
e.extendRequest(**r_it); e.extendRequest(**r_it);
@ -620,7 +619,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// ---------- FIXME ---------------- // ---------- FIXME ----------------
// Check correctness: Now if the simulation ended we // Check correctness: Now if the simulation ended we
// append the newly created environment and return false // append the newly created environment and return false
if(simulation_ended) goto final_cleanup; if (simulation_ended) goto final_cleanup;
bool preemptible_policy; bool preemptible_policy;
@ -639,7 +638,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// ?. See if old running_thread has to be put to ready state // ?. See if old running_thread has to be put to ready state
// This happens when the policy makes use of preemptability by // This happens when the policy makes use of preemptability by
// priority, or when a time slice ended // priority, or when a time slice ended
if(running_thread != NULL && running_thread->get_state() == Schedulable::state_running && if (running_thread != NULL && running_thread->get_state() == Schedulable::state_running &&
(preemptible_policy || (preemptible_policy ||
time_slice == current_instant - running_thread->get_last_acquisition()) ) time_slice == current_instant - running_thread->get_last_acquisition()) )
{ {
@ -671,7 +670,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
found = true; found = true;
// the thread may block on raising a request // the thread may block on raising a request
Requests& reqs = running_thread->get_dynamic_requests(); Requests& reqs = running_thread->get_dynamic_requests();
for(Requests::iterator r_it = reqs.begin(); r_it != reqs.end() for (Requests::iterator r_it = reqs.begin(); r_it != reqs.end()
&& running_thread->get_state() != Schedulable::state_blocked; r_it++) && running_thread->get_state() != Schedulable::state_blocked; r_it++)
{ {
Extender e(new_snapshot, Extender::walk_to_allocate_cpu, running_thread->get_elapsed_time()); Extender e(new_snapshot, Extender::walk_to_allocate_cpu, running_thread->get_elapsed_time());
@ -686,7 +685,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
// if the old running thread may not directly continue, pick from the ready queue. // if the old running thread may not directly continue, pick from the ready queue.
//int debug = 1000; //int debug = 1000;
while(_ready_queue->size() != 0 && !found)//&& debug-- > 0); while (_ready_queue->size() != 0 && !found)//&& debug-- > 0);
{ {
// try with the first on the queue // try with the first on the queue
found = true; found = true;
@ -694,7 +693,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
Requests& reqs = candidate.get_dynamic_requests(); Requests& reqs = candidate.get_dynamic_requests();
for(Requests::iterator r_it = reqs.begin(); r_it != reqs.end(); r_it++) for (Requests::iterator r_it = reqs.begin(); r_it != reqs.end(); r_it++)
{ {
Extender e(new_snapshot, Extender::walk_to_allocate_cpu, candidate.get_elapsed_time()); Extender e(new_snapshot, Extender::walk_to_allocate_cpu, candidate.get_elapsed_time());
e.extendRequest(**r_it); e.extendRequest(**r_it);
@ -726,7 +725,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
} // end of try } // end of try
catch(UserInterruptException& e) catch (UserInterruptException& e)
{ {
// Reset values that the policy doesn't need anymore // Reset values that the policy doesn't need anymore
_policy = NULL; _policy = NULL;
@ -740,7 +739,7 @@ Scheduler::step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInter
throw; throw;
} }
final_cleanup: final_cleanup:
// append the new snapshot... // append the new snapshot...
// ...and remember to release the auto_ptr! // ...and remember to release the auto_ptr!

View File

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

View File

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

View File

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

View File

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

View File

@ -44,7 +44,7 @@ StaticProcess::get_total_cpu_time() const
typedef std::vector<StaticThread*>::const_iterator ThreadIterator; typedef std::vector<StaticThread*>::const_iterator ThreadIterator;
unsigned int result = 0; unsigned int result = 0;
for(ThreadIterator it = _threads.begin(); it != _threads.end(); it++) for (ThreadIterator it = _threads.begin(); it != _threads.end(); it++)
result += (*it)->get_total_cpu_time(); result += (*it)->get_total_cpu_time();
return result; return result;
} }

View File

@ -30,24 +30,24 @@ namespace sgpem
{ {
/* Force template instantiation to allow visibility outside this DSO */ /* Force template instantiation to allow visibility outside this DSO */
template SG_DLLEXPORT int string_to<int>(const Glib::ustring&); template SG_DLLEXPORT int string_to<int>(const Glib::ustring&);
template SG_DLLEXPORT float string_to<float>(const Glib::ustring&); template SG_DLLEXPORT float string_to<float>(const Glib::ustring&);
// Specialized further down in this file: // Specialized further down in this file:
// template SG_DLLEXPORT bool string_to<bool>(const Glib::ustring&); // template SG_DLLEXPORT bool string_to<bool>(const Glib::ustring&);
/** /**
\brief A function that converts a Unicode string to an integer value \brief A function that converts a Unicode string to an integer value
The string can contain ONLY digits and the "minus" character. The string can contain ONLY digits and the "minus" character.
\returns TRUE if the string is well formatted \returns TRUE if the string is well formatted
\returns FALSE otherwise \returns FALSE otherwise
*/ */
bool bool
string_to_int(const ustring& str, int& num) string_to_int(const ustring& str, int& num)
{ {
static const ustring allvalid = "0123456789-"; static const ustring allvalid = "0123456789-";
static const ustring digits = "0123456789"; static const ustring digits = "0123456789";
@ -78,13 +78,13 @@ string_to_int(const ustring& str, int& num)
if (start == 1) if (start == 1)
num *= -1; num *= -1;
return true; return true;
} }
template <typename T> template <typename T>
T T
string_to(const ustring& str) throw(domain_error) string_to(const ustring& str) throw(domain_error)
{ {
if(tokenize(str).size() != 1) if (tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens")); throw domain_error(_("too few or too many tokens"));
istringstream iss(str); istringstream iss(str);
@ -97,7 +97,7 @@ string_to(const ustring& str) throw(domain_error)
{ {
iss >> value; iss >> value;
} }
catch(ios_base::failure e) catch (ios_base::failure e)
{ {
throw domain_error(e.what()); throw domain_error(e.what());
} }
@ -106,17 +106,17 @@ string_to(const ustring& str) throw(domain_error)
// how useless!!! // how useless!!!
iss.exceptions(ios_base::goodbit); iss.exceptions(ios_base::goodbit);
if(iss.peek() != istringstream::traits_type::eof()) if (iss.peek() != istringstream::traits_type::eof())
throw domain_error(_("incorrect number format")); throw domain_error(_("incorrect number format"));
return value; return value;
} }
template <> template <>
SG_DLLEXPORT bool SG_DLLEXPORT bool
string_to<bool>(const Glib::ustring& str) throw(domain_error) string_to<bool>(const Glib::ustring& str) throw(domain_error)
{ {
if(tokenize(str).size() != 1) if (tokenize(str).size() != 1)
throw domain_error(_("too few or too many tokens")); throw domain_error(_("too few or too many tokens"));
istringstream iss(str); istringstream iss(str);
@ -129,7 +129,7 @@ string_to<bool>(const Glib::ustring& str) throw(domain_error)
{ {
iss >> boolalpha >> value; iss >> boolalpha >> value;
} }
catch(ios_base::failure e) catch (ios_base::failure e)
{ {
throw domain_error(e.what()); throw domain_error(e.what());
} }
@ -138,18 +138,18 @@ string_to<bool>(const Glib::ustring& str) throw(domain_error)
// how useless!!! // how useless!!!
iss.exceptions(ios_base::goodbit); iss.exceptions(ios_base::goodbit);
if(iss.peek() != istringstream::traits_type::eof()) if (iss.peek() != istringstream::traits_type::eof())
throw domain_error(_("incorrect boolean")); throw domain_error(_("incorrect boolean"));
return value; return value;
} }
/** /**
\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 void
int_to_string(const int& num, ustring& str) int_to_string(const int& num, ustring& str)
{ {
if (num == 0) if (num == 0)
{ {
str = '0'; str = '0';
@ -171,41 +171,41 @@ int_to_string(const int& num, ustring& str)
} }
if (negative) if (negative)
str = '-' + str; str = '-' + str;
} }
void void
float_to_string(const float& f, Glib::ustring& str) float_to_string(const float& f, Glib::ustring& str)
{ {
stringstream ss; stringstream ss;
ss << f; ss << f;
char p[20]; char p[20];
ss.getline(p, 20); ss.getline(p, 20);
str = p; str = p;
} }
void void
string_to_float(const Glib::ustring& str, float& f) string_to_float(const Glib::ustring& str, float& f)
{ {
stringstream ss; stringstream ss;
ss << str; ss << str;
ss >> f; ss >> f;
} }
// helper function for tokenize() // helper function for tokenize()
static void static void
add_token(Tokens& tokens, const ustring& token) add_token(Tokens& tokens, const ustring& token)
{ {
if(token.size() > 0) if (token.size() > 0)
tokens.push_back(token); tokens.push_back(token);
} }
Tokens Tokens
tokenize(const ustring& str) tokenize(const ustring& str)
{ {
istringstream iss(str); istringstream iss(str);
Tokens tokens; Tokens tokens;
while(iss) while (iss)
{ {
ustring token; ustring token;
iss >> token; iss >> token;
@ -218,7 +218,7 @@ tokenize(const ustring& str)
{ {
index = token.find('='); index = token.find('=');
if(index != ustring::npos) if (index != ustring::npos)
{ {
add_token(tokens, token.substr(0, index)); add_token(tokens, token.substr(0, index));
add_token(tokens, "="); add_token(tokens, "=");
@ -227,12 +227,12 @@ tokenize(const ustring& str)
token = token.substr(index + 1, token.size()); token = token.substr(index + 1, token.size());
} }
} }
while(index != ustring::npos); while (index != ustring::npos);
add_token(tokens, token); add_token(tokens, token);
} }
return tokens; return tokens;
} }
} }

View File

@ -27,8 +27,7 @@ using namespace sgpem;
CairoElements::CairoElements(cairo_t* const ctx) CairoElements::CairoElements(cairo_t* const ctx)
: _ctx(ctx) : _ctx(ctx)
{ {}
}
void void
@ -62,8 +61,8 @@ CairoElements::draw_3dsphere(const Point& center, float radius, const Color& cl)
cairo_pattern_add_color_stop_rgba(grad, 1, r - .4, g - .4, b - .4, 1); cairo_pattern_add_color_stop_rgba(grad, 1, r - .4, g - .4, b - .4, 1);
cairo_pattern_add_color_stop_rgba(grad, 0, r, g, b, .7); cairo_pattern_add_color_stop_rgba(grad, 0, r, g, b, .7);
cairo_set_source(cr, grad); cairo_set_source(cr, grad);
cairo_translate(cr, x*.2, (y + radius*8/9) * 1/3); cairo_translate(cr, x*.2, (y + radius*8 / 9) * 1 / 3);
cairo_scale(cr, .8, 2./3); cairo_scale(cr, .8, 2. / 3);
cairo_arc(cr, x, y, radius, 0, 2*M_PI); cairo_arc(cr, x, y, radius, 0, 2*M_PI);
cairo_fill(cr); cairo_fill(cr);
cairo_pattern_destroy(grad); cairo_pattern_destroy(grad);
@ -75,8 +74,8 @@ CairoElements::draw_3dsphere(const Point& center, float radius, const Color& cl)
cairo_pattern_add_color_stop_rgba(grad, 0, 1, 1, 1, .9); cairo_pattern_add_color_stop_rgba(grad, 0, 1, 1, 1, .9);
cairo_pattern_add_color_stop_rgba(grad, 1, 1, 1, 1, .2); cairo_pattern_add_color_stop_rgba(grad, 1, 1, 1, 1, .2);
cairo_set_source(cr, grad); cairo_set_source(cr, grad);
cairo_translate(cr, x * .2, (y - radius*8/9) * 1/3); cairo_translate(cr, x * .2, (y - radius*8 / 9) * 1 / 3);
cairo_scale(cr, .8, 2./3); cairo_scale(cr, .8, 2. / 3);
cairo_arc(cr, x, y, radius, 0, 2*M_PI); cairo_arc(cr, x, y, radius, 0, 2*M_PI);
cairo_fill(cr); cairo_fill(cr);
cairo_pattern_destroy(grad); cairo_pattern_destroy(grad);
@ -113,14 +112,14 @@ CairoElements::draw_container(const Rectangle& area)
cairo_move_to(cr, x0 + corner_radius, y0); cairo_move_to(cr, x0 + corner_radius, y0);
// NW -> NE // NW -> NE
cairo_line_to(cr, x0+w - corner_radius, y0); cairo_line_to(cr, x0 + w - corner_radius, y0);
cairo_curve_to(cr, x0+w, y0, x0+w, y0, x0+w, y0 + corner_radius); cairo_curve_to(cr, x0 + w, y0, x0 + w, y0, x0 + w, y0 + corner_radius);
// NE -> SE // NE -> SE
cairo_line_to(cr, x0+w, y0+h - corner_radius); cairo_line_to(cr, x0 + w, y0 + h - corner_radius);
cairo_curve_to(cr, x0+w, y0+h, x0+w, y0+h, x0+w - corner_radius, y0+h); cairo_curve_to(cr, x0 + w, y0 + h, x0 + w, y0 + h, x0 + w - corner_radius, y0 + h);
// SE -> SW // SE -> SW
cairo_line_to(cr, x0 + corner_radius, y0+h); cairo_line_to(cr, x0 + corner_radius, y0 + h);
cairo_curve_to(cr, x0, y0+h, x0, y0+h, x0, y0+h - corner_radius); cairo_curve_to(cr, x0, y0 + h, x0, y0 + h, x0, y0 + h - corner_radius);
// SW -> NW // SW -> NW
cairo_line_to(cr, x0, y0 + corner_radius); cairo_line_to(cr, x0, y0 + corner_radius);
cairo_curve_to(cr, x0, y0, x0, y0, x0 + corner_radius, y0); cairo_curve_to(cr, x0, y0, x0, y0, x0 + corner_radius, y0);
@ -158,14 +157,14 @@ CairoElements::draw_expandable(const Rectangle& area, bool expanded)
cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_source_rgb(cr, 0, 0, 0);
cairo_stroke(cr); cairo_stroke(cr);
cairo_move_to(cr, x0 + w/10, y0 + h/2); cairo_move_to(cr, x0 + w / 10, y0 + h / 2);
cairo_line_to(cr, x0 + w*9/10, y0 + h/2); cairo_line_to(cr, x0 + w*9 / 10, y0 + h / 2);
cairo_stroke(cr); cairo_stroke(cr);
if(!expanded) if (!expanded)
{ {
cairo_move_to(cr, x0 + w/2, y0 + h/10); cairo_move_to(cr, x0 + w / 2, y0 + h / 10);
cairo_line_to(cr, x0 + w/2, y0 + h*9/10); cairo_line_to(cr, x0 + w / 2, y0 + h*9 / 10);
cairo_stroke(cr); cairo_stroke(cr);
} }
@ -175,12 +174,10 @@ CairoElements::draw_expandable(const Rectangle& area, bool expanded)
Rectangle draw_thread_status(const Point& top_left_crn, Rectangle draw_thread_status(const Point& top_left_crn,
const Thread& thread_info) const Thread& thread_info)
{ {}
}
Rectangle draw_process_status(const Point& top_left_crn, Rectangle draw_process_status(const Point& top_left_crn,
const Process& process_info) const Process& process_info)
{ {}
}

View File

@ -54,7 +54,7 @@ CairoWidget::update(const History& history)
{ {
// get_window() returns a null pointer // get_window() returns a null pointer
// if the widget has not been realized // if the widget has not been realized
if(!is_realized()) if (!is_realized())
return; // Nowhere to draw to. return; // Nowhere to draw to.
// Determine the final height before to start drawing // Determine the final height before to start drawing
@ -89,7 +89,7 @@ CairoWidget::update(const History& history)
void void
CairoWidget::on_realize() CairoWidget::on_realize()
{ {
if(is_realized()) return; if (is_realized()) return;
Gtk::Widget::on_realize(); Gtk::Widget::on_realize();
ensure_style(); ensure_style();
@ -140,7 +140,7 @@ CairoWidget::on_size_allocate(const Gtk::Allocation& allocation)
{ {
set_allocation(allocation); set_allocation(allocation);
if(is_realized()) if (is_realized())
get_window()->move_resize(allocation.get_x(), allocation.get_y(), get_window()->move_resize(allocation.get_x(), allocation.get_y(),
allocation.get_width(), allocation.get_height()); allocation.get_width(), allocation.get_height());
} }
@ -149,7 +149,7 @@ CairoWidget::on_size_allocate(const Gtk::Allocation& allocation)
bool bool
CairoWidget::on_expose_event(GdkEventExpose* event) CairoWidget::on_expose_event(GdkEventExpose* event)
{ {
if(event == NULL || event->count > 0) if (event == NULL || event->count > 0)
return false; return false;
// calculated dinamically: // calculated dinamically:
@ -159,7 +159,7 @@ CairoWidget::on_expose_event(GdkEventExpose* event)
// Clip to redraw only the smallest possible area // Clip to redraw only the smallest possible area
// Use double buffering or we're CPU-dead // Use double buffering or we're CPU-dead
// Copy from the buffer to the screen // Copy from the buffer to the screen
if(_buf) if (_buf)
get_window()->draw_drawable(get_style()->get_black_gc(), _buf, get_window()->draw_drawable(get_style()->get_black_gc(), _buf,
event->area.x, event->area.y, event->area.x, event->area.y,
event->area.x, event->area.y, event->area.x, event->area.y,

View File

@ -81,8 +81,7 @@ GuiBuilder::GuiBuilder(const std::string& gladefile)
GuiBuilder::~GuiBuilder() GuiBuilder::~GuiBuilder()
{ {}
}
Gtk::Window& Gtk::Window&

View File

@ -31,7 +31,8 @@
/** \brief This class initialize and starts the whole GUI /** \brief This class initialize and starts the whole GUI
*/ */
namespace sgpem { namespace sgpem
{
class GuiBuilder class GuiBuilder
{ {

View File

@ -102,11 +102,11 @@ parse_options(int argc, char** argv)
GlobalPreferences& prefs = GlobalPreferences::get_instance(); GlobalPreferences& prefs = GlobalPreferences::get_instance();
for(Glib::OptionGroup::vecustrings::const_iterator it = policies_dir_val.begin(); for (Glib::OptionGroup::vecustrings::const_iterator it = policies_dir_val.begin();
it != policies_dir_val.end(); ++it) it != policies_dir_val.end(); ++it)
prefs.add_policies_dir(*it); prefs.add_policies_dir(*it);
for(Glib::OptionGroup::vecustrings::const_iterator it = modules_dir_val.begin(); for (Glib::OptionGroup::vecustrings::const_iterator it = modules_dir_val.begin();
it != modules_dir_val.end(); ++it) it != modules_dir_val.end(); ++it)
prefs.add_modules_dir(*it); prefs.add_modules_dir(*it);
@ -115,16 +115,16 @@ parse_options(int argc, char** argv)
// initialize plugins, too // initialize plugins, too
vector<Module*> modules = PluginManager::get_instance().get_module_list(); vector<Module*> modules = PluginManager::get_instance().get_module_list();
for(vector<Module*>::iterator it = modules.begin(); it != modules.end(); ++it) for (vector<Module*>::iterator it = modules.begin(); it != modules.end(); ++it)
(*it)->set_enabled(true); (*it)->set_enabled(true);
vector<CPUPolicyManager*> managers = CPUPoliciesGatekeeper::get_instance().get_registered(); vector<CPUPolicyManager*> managers = CPUPoliciesGatekeeper::get_instance().get_registered();
for(vector<CPUPolicyManager*>::iterator it = managers.begin(); it != managers.end(); ++it) for (vector<CPUPolicyManager*>::iterator it = managers.begin(); it != managers.end(); ++it)
(*it)->init(); (*it)->init();
if(no_gui_enabled) if (no_gui_enabled)
{ {
// We don't return to main, instead we // We don't return to main, instead we
// initialize the command line version // initialize the command line version
@ -133,7 +133,7 @@ parse_options(int argc, char** argv)
std::string str; std::string str;
std::cout << std::endl << "% "; std::cout << std::endl << "% ";
while(getline(std::cin, str)) while (getline(std::cin, str))
{ {
// Enter main loop // Enter main loop
TextSimulation::parse_command(sim, str); TextSimulation::parse_command(sim, str);
@ -143,14 +143,14 @@ parse_options(int argc, char** argv)
else else
{ {
GuiBuilder* gui = new GuiBuilder(); GuiBuilder* gui = new GuiBuilder();
if(fnames.begin() != fnames.end()) if (fnames.begin() != fnames.end())
gui->open_file(*fnames.begin()); gui->open_file(*fnames.begin());
main_loop.run(gui->get_initial_window()); main_loop.run(gui->get_initial_window());
delete gui; delete gui;
} }
} // ~ try } // ~ try
catch(Glib::OptionError e) catch (Glib::OptionError e)
{ {
std::cout << _("Bad invocation: ") << e.what() << std::endl; std::cout << _("Bad invocation: ") << e.what() << std::endl;
std::cout << _("Use the `-?' or `--help' option to see the help") << std::endl; std::cout << _("Use the `-?' or `--help' option to see the help") << std::endl;

View File

@ -29,13 +29,11 @@ using namespace sgpem;
SchedulablesWidget::SchedulablesWidget() SchedulablesWidget::SchedulablesWidget()
: Glib::ObjectBase("sgpem_SchedulablesWidget"), CairoWidget() : Glib::ObjectBase("sgpem_SchedulablesWidget"), CairoWidget()
{ {}
}
SchedulablesWidget::~SchedulablesWidget() SchedulablesWidget::~SchedulablesWidget()
{ {}
}
void void

View File

@ -34,8 +34,8 @@ template<typename Instantiated_class>
Instantiated_class& Instantiated_class&
sgpem::Singleton<Instantiated_class>::get_instance() sgpem::Singleton<Instantiated_class>::get_instance()
{ {
Glib::RecMutex::Lock lock(_mutex); Glib::RecMutex::Lock lock (_mutex);
if(_instance == NULL) if (_instance == NULL)
_instance = new Instantiated_class(); _instance = new Instantiated_class();
return *_instance; return *_instance;
} }

View File

@ -47,9 +47,9 @@ namespace memory
template<typename T, bool isArray> template<typename T, bool isArray>
smart_ptr<T, isArray>::~smart_ptr() throw() smart_ptr<T, isArray>::~smart_ptr() throw()
{ {
if(--(_contents->rc) == 0) if (--(_contents->rc) == 0)
{ {
if(_contents->ptr != 0) if (_contents->ptr != 0)
!isArray ? delete _contents->ptr : delete [] _contents->ptr; !isArray ? delete _contents->ptr : delete [] _contents->ptr;
delete _contents; delete _contents;
} }
@ -61,11 +61,11 @@ namespace memory
smart_ptr<T, isArray>& smart_ptr<T, isArray>&
smart_ptr<T, isArray>::operator=(const smart_ptr& sptr) throw() smart_ptr<T, isArray>::operator=(const smart_ptr& sptr) throw()
{ {
if(this != &sptr && _contents != sptr._contents) if (this != &sptr && _contents != sptr._contents)
{ {
if(--(_contents->rc) == 0) if (--(_contents->rc) == 0)
{ {
if(_contents->ptr != 0) if (_contents->ptr != 0)
!isArray ? delete _contents->ptr : delete [] _contents->ptr; !isArray ? delete _contents->ptr : delete [] _contents->ptr;
delete _contents; delete _contents;
} }
@ -165,11 +165,11 @@ namespace memory
smart_ptr<T, isArray>::smart_ptr(const smart_ptr<U, isArray>& sptr) smart_ptr<T, isArray>::smart_ptr(const smart_ptr<U, isArray>& sptr)
throw(std::bad_cast) throw(std::bad_cast)
{ {
if(!sptr._contents->ptr || dynamic_cast<T*>(sptr._contents->ptr) == 0) if (!sptr._contents->ptr || dynamic_cast<T*>(sptr._contents->ptr) == 0)
throw std::bad_cast(); throw std::bad_cast();
// I know, I know... this is Evil(TM): // I know, I know... this is Evil(TM):
_contents = reinterpret_cast<typename smart_ptr<T, isArray>::contents_type*>(sptr._contents); _contents = reinterpret_cast<typename smart_ptr<T, isArray>::contents_type* > (sptr._contents);
(_contents->rc)++; (_contents->rc)++;
} }

View File

@ -24,9 +24,9 @@
using namespace sgpem; using namespace sgpem;
memory::smart_ptr<sgpem::DynamicSchedulable> memory::smart_ptr<sgpem::DynamicSchedulable>
History::get_scheduled_at(int time) const History::get_scheduled_at(int time) const
{ {
using namespace memory; using namespace memory;
smart_ptr<DynamicSchedulable> scheduled_at = smart_ptr<DynamicSchedulable>(); smart_ptr<DynamicSchedulable> scheduled_at = smart_ptr<DynamicSchedulable>();
if (0 <= time && time <= _total_time_elapsed) if (0 <= time && time <= _total_time_elapsed)
@ -45,18 +45,18 @@ using namespace sgpem;
} }
} }
return scheduled_at; return scheduled_at;
} }
memory::smart_ptr<sgpem::ReadyQueue> memory::smart_ptr<sgpem::ReadyQueue>
History::get_simulation_status_at(int time) const History::get_simulation_status_at(int time) const
{ {
using namespace memory; using namespace memory;
smart_ptr<ReadyQueue> simulation_status_at = smart_ptr<ReadyQueue>(); smart_ptr<ReadyQueue> simulation_status_at = smart_ptr<ReadyQueue>();
if (0 <= time && time <= _total_time_elapsed) if (0 <= time && time <= _total_time_elapsed)
{ {
if (_slice == memory::smart_ptr<Slice>()) if (_slice == memory::smart_ptr<Slice>())
std::cout<<"History::get_simulation_status_at.NULL.error"; std::cout << "History::get_simulation_status_at.NULL.error";
else else
simulation_status_at = memory::smart_ptr<ReadyQueue> simulation_status_at = memory::smart_ptr<ReadyQueue>
( (
@ -67,47 +67,47 @@ using namespace sgpem;
); );
} }
return simulation_status_at; return simulation_status_at;
} }
int int
History::get_current_time() const History::get_current_time() const
{ {
return _total_time_elapsed; return _total_time_elapsed;
} }
void void
History::enqueue_slice(const sgpem::ReadyQueue& status) History::enqueue_slice(const sgpem::ReadyQueue& status)
{ {
_slice = memory::smart_ptr<Slice>(new Slice(_total_time_elapsed, 1, status)); _slice = memory::smart_ptr<Slice>(new Slice(_total_time_elapsed, 1, status));
_total_time_elapsed++; _total_time_elapsed++;
} }
void void
History::truncate_at(int instant) History::truncate_at(int instant)
{ {
//std::cout << "\nRecreating a Singleton History"; //std::cout << "\nRecreating a Singleton History";
_slice = memory::smart_ptr<Slice>(); _slice = memory::smart_ptr<Slice>();
_total_time_elapsed = -1; _total_time_elapsed = -1;
} }
History& History&
History::get_instance() History::get_instance()
{ {
if (History::_instance == NULL) if (History::_instance == NULL)
History::_instance = new History(); History::_instance = new History();
return *History::_instance; return *History::_instance;
} }
History::History() History::History()
{ {
_slice = memory::smart_ptr<Slice>(); _slice = memory::smart_ptr<Slice>();
_total_time_elapsed = -1; _total_time_elapsed = -1;
} }
History * History::_instance = NULL; History * History::_instance = NULL;

View File

@ -33,19 +33,19 @@ PolicyManager::get_registered_manager()
return *_registered; return *_registered;
} }
Policy& Policy&
PolicyManager::get_policy() PolicyManager::get_policy()
{ {
return PRRPolicy::get_instance(); return PRRPolicy::get_instance();
} }
void void
PolicyManager::init() PolicyManager::init()
{} {}
PolicyManager::~PolicyManager() PolicyManager::~PolicyManager()
{ {
if(_registered == this) _registered = NULL; if (_registered == this) _registered = NULL;
} }

View File

@ -36,7 +36,7 @@ PRRPolicy::PRRPolicy(int quantum)
Policy& Policy&
PRRPolicy::get_instance() PRRPolicy::get_instance()
{ {
if(_instance == NULL) _instance = new PRRPolicy(3); // quantum size if (_instance == NULL) _instance = new PRRPolicy(3); // quantum size
return *_instance; return *_instance;
} }
@ -44,14 +44,14 @@ PRRPolicy::get_instance()
PRRPolicy::~PRRPolicy() PRRPolicy::~PRRPolicy()
{} {}
void void
PRRPolicy::configure() PRRPolicy::configure()
throw(UserInterruptException) throw(UserInterruptException)
{} {}
void void
PRRPolicy::sort_queue() const PRRPolicy::sort_queue() const
throw(UserInterruptException) throw(UserInterruptException)
{ {
ReadyQueue* local_sl = Scheduler::get_instance().get_ready_queue(); ReadyQueue* local_sl = Scheduler::get_instance().get_ready_queue();
for (uint useless = 0; useless < local_sl->size(); useless++) for (uint useless = 0; useless < local_sl->size(); useless++)
@ -64,54 +64,54 @@ PRRPolicy::sort_queue() const
local_sl->swap(i, i + 1); local_sl->swap(i, i + 1);
} }
void void
PRRPolicy::activate() PRRPolicy::activate()
{} {}
void void
PRRPolicy::deactivate() PRRPolicy::deactivate()
{} {}
int int
PRRPolicy::get_id() const PRRPolicy::get_id() const
{ {
return 42; return 42;
} }
sgpem::policy_sorts_type sgpem::policy_sorts_type
PRRPolicy::wants() const PRRPolicy::wants() const
throw(UserInterruptException) throw(UserInterruptException)
{ {
return policy_sorts_processes; return policy_sorts_processes;
} }
Glib::ustring Glib::ustring
PRRPolicy::get_name() const PRRPolicy::get_name() const
{ {
return "42"; return "42";
} }
Glib::ustring Glib::ustring
PRRPolicy::get_description() const PRRPolicy::get_description() const
{ {
return "42"; return "42";
} }
bool bool
PRRPolicy::is_pre_emptive() const PRRPolicy::is_pre_emptive() const
throw(UserInterruptException) throw(UserInterruptException)
{ {
return 1; return 1;
} }
int int
PRRPolicy::get_time_slice() const PRRPolicy::get_time_slice() const
throw(UserInterruptException) throw(UserInterruptException)
{ {
return _quantum; return _quantum;
} }
PolicyParameters& PolicyParameters&
PRRPolicy::get_parameters() PRRPolicy::get_parameters()
{ {
return _parameters; return _parameters;

View File

@ -32,7 +32,8 @@
// from here and further until the bottom, all to throw away I suppose // from here and further until the bottom, all to throw away I suppose
int int
main(int argc, char** argv) { main(int argc, char** argv)
{
using namespace sgpem; using namespace sgpem;
using Glib::ustring; using Glib::ustring;
@ -42,7 +43,7 @@ main(int argc, char** argv) {
GlobalPreferences& gp = GlobalPreferences::get_instance(); GlobalPreferences& gp = GlobalPreferences::get_instance();
if(argc<2) if (argc < 2)
{ {
cout << "GlobalPreferences serialization test program" << endl; cout << "GlobalPreferences serialization test program" << endl;
cout << "Syntax: test-global_preferences_serialization [mod1 mod2 ...][% pol1 pol2 ...]" << endl << endl; cout << "Syntax: test-global_preferences_serialization [mod1 mod2 ...][% pol1 pol2 ...]" << endl << endl;
@ -51,14 +52,14 @@ main(int argc, char** argv) {
<< ", read it and compare with saved one." << endl << endl; << ", read it and compare with saved one." << endl << endl;
} }
int i=1; int i = 1;
while(i<argc && (*argv[i]!='%')) while (i < argc && (*argv[i] != '%'))
{ {
gp.add_modules_dir( Glib::ustring(argv[i]) ); gp.add_modules_dir( Glib::ustring(argv[i]) );
i++; i++;
} }
i++; i++;
while(i<argc) while (i < argc)
{ {
gp.add_policies_dir( Glib::ustring(argv[i]) ); gp.add_policies_dir( Glib::ustring(argv[i]) );
i++; i++;
@ -78,14 +79,14 @@ main(int argc, char** argv) {
gp.write_configrc(os1); gp.write_configrc(os1);
i=1; i = 1;
while(i<argc && (*argv[i]!='%')) while (i < argc && (*argv[i] != '%'))
{ {
gp.add_modules_dir( Glib::ustring("bis-") + Glib::ustring(argv[i]) ); gp.add_modules_dir( Glib::ustring("bis-") + Glib::ustring(argv[i]) );
i++; i++;
} }
i++; i++;
while(i<argc) while (i < argc)
{ {
gp.add_policies_dir( Glib::ustring("bis-") + Glib::ustring(argv[i]) ); gp.add_policies_dir( Glib::ustring("bis-") + Glib::ustring(argv[i]) );
i++; i++;
@ -108,12 +109,12 @@ main(int argc, char** argv) {
cout << "Preferences writed into os3 (t3)" << endl << endl; cout << "Preferences writed into os3 (t3)" << endl << endl;
gp.write_configrc(os3); gp.write_configrc(os3);
cout << "Comparing dump of (t1) and (t2): " << (os1.str()==os2.str()?"equals":"not equals") << endl; cout << "Comparing dump of (t1) and (t2): " << (os1.str() == os2.str() ? "equals" : "not equals") << endl;
cout << "Comparing dump of (t1) and (t3): " << (os1.str()==os3.str()?"equals":"not equals") << endl; cout << "Comparing dump of (t1) and (t3): " << (os1.str() == os3.str() ? "equals" : "not equals") << endl;
int ret = 1; int ret = 1;
if(os1.str()!=os2.str() if (os1.str() != os2.str()
&& os1.str()==os3.str()) && os1.str() == os3.str())
{ {
cout << "test successful" << endl; cout << "test successful" << endl;
ret = 0; ret = 0;

View File

@ -42,7 +42,7 @@ using Glib::ustring;
// it is updated // it is updated
class DummyObserver : public HistoryObserver class DummyObserver : public HistoryObserver
{ {
public: public:
DummyObserver() : _i(0) {} DummyObserver() : _i(0) {}
void update(const History& history) void update(const History& history)
{ {
@ -96,15 +96,15 @@ find_thread(ConcreteEnvironment& env, Thread& _thread)
Environment::Processes& processes = env.get_processes(); Environment::Processes& processes = env.get_processes();
// please forgive me, I'm sick of using iterators... // please forgive me, I'm sick of using iterators...
for(unsigned int i = 0; i < processes.size(); ++i) for (unsigned int i = 0; i < processes.size(); ++i)
{ {
Process& p = *processes[i]; Process& p = *processes[i];
vector<Thread*> threads = p.get_threads(); vector<Thread*> threads = p.get_threads();
for(unsigned int j = 0; j < threads.size(); ++j) for (unsigned int j = 0; j < threads.size(); ++j)
{ {
DynamicThread& t = (DynamicThread&)*threads[j]; DynamicThread& t = (DynamicThread&) * threads[j];
if(t == thread) if (t == thread)
return t; return t;
} }
} }
@ -119,15 +119,15 @@ find_thread(const ConcreteEnvironment& env, const Thread& _thread)
const Environment::Processes& processes = env.get_processes(); const Environment::Processes& processes = env.get_processes();
// please forgive me, I'm sick of using iterators... // please forgive me, I'm sick of using iterators...
for(unsigned int i = 0; i < processes.size(); ++i) for (unsigned int i = 0; i < processes.size(); ++i)
{ {
const Process& p = *processes[i]; const Process& p = *processes[i];
vector<const Thread*> threads = p.get_threads(); vector<const Thread*> threads = p.get_threads();
for(unsigned int j = 0; j < threads.size(); ++j) for (unsigned int j = 0; j < threads.size(); ++j)
{ {
const DynamicThread& t = (const DynamicThread&)*threads[j]; const DynamicThread& t = (const DynamicThread&) * threads[j];
if(t == thread) if (t == thread)
return t; return t;
} }
} }
@ -149,7 +149,7 @@ main(int argc, char** argv)
test << "Checking if it contains only one Environment... "; test << "Checking if it contains only one Environment... ";
if(h.get_size() == 1) if (h.get_size() == 1)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -161,7 +161,7 @@ main(int argc, char** argv)
test << "Checking if the environment is empty... "; test << "Checking if the environment is empty... ";
if(environment.get_processes().size() == 0 && if (environment.get_processes().size() == 0 &&
environment.get_resources().size() == 0 && environment.get_resources().size() == 0 &&
environment.get_sorted_queue().size() == 0) environment.get_sorted_queue().size() == 0)
test << "PASS"; test << "PASS";
@ -340,7 +340,7 @@ main(int argc, char** argv)
test << "Checking if history size is 6... "; test << "Checking if history size is 6... ";
if(h.get_size() == 6) if (h.get_size() == 6)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -351,7 +351,7 @@ main(int argc, char** argv)
test << "Checking if dynamic priority of thread at instant 1 and 5 is different... "; test << "Checking if dynamic priority of thread at instant 1 and 5 is different... ";
if(t1.get_priority_push() != t5.get_priority_push()) if (t1.get_priority_push() != t5.get_priority_push())
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -362,7 +362,7 @@ main(int argc, char** argv)
test << "Checking if dynamic priority of thread at instant 4, is different "; test << "Checking if dynamic priority of thread at instant 4, is different ";
test << "from that at instant 1 and 5, and equal to the one expected... "; test << "from that at instant 1 and 5, and equal to the one expected... ";
if(t4.get_priority_push() != t1.get_priority_push() && if (t4.get_priority_push() != t1.get_priority_push() &&
t4.get_priority_push() != t5.get_priority_push() && t4.get_priority_push() != t5.get_priority_push() &&
t4.get_priority_push() == priorities[3]) t4.get_priority_push() == priorities[3])
test << "PASS"; test << "PASS";
@ -379,28 +379,28 @@ main(int argc, char** argv)
bool subreq_pass = true; bool subreq_pass = true;
for(unsigned int i = 0; i < le_processes.size(); ++i) for (unsigned int i = 0; i < le_processes.size(); ++i)
{ {
vector<Thread*> threads = le_processes[i]->get_threads(); vector<Thread*> threads = le_processes[i]->get_threads();
for(unsigned int j = 0; j < threads.size(); ++j) for (unsigned int j = 0; j < threads.size(); ++j)
{ {
vector<Request*> requests = threads[j]->get_requests(); vector<Request*> requests = threads[j]->get_requests();
for(unsigned int k = 0; k < requests.size(); ++k) for (unsigned int k = 0; k < requests.size(); ++k)
{ {
vector<SubRequest*> subrequests = requests[k]->get_subrequests(); vector<SubRequest*> subrequests = requests[k]->get_subrequests();
for(unsigned int x = 0; x < subrequests.size(); ++x) for (unsigned int x = 0; x < subrequests.size(); ++x)
{ {
if(le_resources.find(subrequests[x]->get_resource_key()) == le_resources.end()) if (le_resources.find(subrequests[x]->get_resource_key()) == le_resources.end())
subreq_pass = false; subreq_pass = false;
} }
} }
} }
} }
if(subreq_pass) if (subreq_pass)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -413,7 +413,7 @@ main(int argc, char** argv)
h.get_environment_at(6); h.get_environment_at(6);
test << "FAIL"; test << "FAIL";
} }
catch(out_of_range) catch (out_of_range)
{ {
test << "PASS"; test << "PASS";
} }
@ -431,7 +431,7 @@ main(int argc, char** argv)
test << "Checking if history has size 1 after adding a thread... "; test << "Checking if history has size 1 after adding a thread... ";
if(h.get_size() == 1) if (h.get_size() == 1)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -447,7 +447,7 @@ main(int argc, char** argv)
test << "Checking if history has size 1 after removing a resource... "; test << "Checking if history has size 1 after removing a resource... ";
if(h.get_size() == 1) if (h.get_size() == 1)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -465,32 +465,32 @@ main(int argc, char** argv)
bool final_bad_match = false; bool final_bad_match = false;
bool final_sreq2_match = false; bool final_sreq2_match = false;
for(unsigned int i = 0; i < final_processes.size(); ++i) for (unsigned int i = 0; i < final_processes.size(); ++i)
{ {
DynamicProcess& p = (DynamicProcess&)*final_processes[i]; DynamicProcess& p = (DynamicProcess&) * final_processes[i];
if(!final_p1_match && p == p1) if (!final_p1_match && p == p1)
final_p1_match = true; final_p1_match = true;
else if(!final_p2_match && p == p2) else if (!final_p2_match && p == p2)
final_p2_match = true; final_p2_match = true;
else else
final_bad_match = true; final_bad_match = true;
vector<DynamicThread*>& threads = p.get_dynamic_threads(); vector<DynamicThread*>& threads = p.get_dynamic_threads();
for(unsigned int j = 0; j < threads.size(); ++j) for (unsigned int j = 0; j < threads.size(); ++j)
{ {
vector<DynamicRequest*> requests = threads[j]->get_dynamic_requests(); vector<DynamicRequest*> requests = threads[j]->get_dynamic_requests();
for(unsigned int k = 0; k < requests.size(); ++k) for (unsigned int k = 0; k < requests.size(); ++k)
{ {
vector<DynamicSubRequest*> subrequests = requests[k]->get_dynamic_subrequests(); vector<DynamicSubRequest*> subrequests = requests[k]->get_dynamic_subrequests();
for(unsigned int x = 0; x < subrequests.size(); ++x) for (unsigned int x = 0; x < subrequests.size(); ++x)
{ {
// NOTE this will of course fail if the subrequests which should not be here // NOTE this will of course fail if the subrequests which should not be here
// are still in the environment // are still in the environment
if(!final_sreq2_match && *subrequests[x] == sreq2) if (!final_sreq2_match && *subrequests[x] == sreq2)
final_sreq2_match = true; final_sreq2_match = true;
else else
final_bad_match = true; final_bad_match = true;
@ -501,16 +501,16 @@ main(int argc, char** argv)
typedef Environment::Resources::const_iterator ResourceIt; typedef Environment::Resources::const_iterator ResourceIt;
if(final_resources.size() == 1) if (final_resources.size() == 1)
{ {
DynamicResource& r = (DynamicResource&)*(final_resources.begin()->second); DynamicResource& r = (DynamicResource&) * (final_resources.begin()->second);
if(!(r == *res2.second)) if (!(r == *res2.second))
final_bad_match = true; final_bad_match = true;
} }
else else
final_bad_match = true; final_bad_match = true;
if(!final_bad_match && final_p1_match && final_p2_match && final_sreq2_match) if (!final_bad_match && final_p1_match && final_p2_match && final_sreq2_match)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";
@ -528,7 +528,7 @@ main(int argc, char** argv)
h.get_environment_at(-17); h.get_environment_at(-17);
test << "FAIL"; test << "FAIL";
} }
catch(out_of_range) catch (out_of_range)
{ {
test << "PASS"; test << "PASS";
} }
@ -536,7 +536,7 @@ main(int argc, char** argv)
test << "Internal observer's counter should be 21... "; test << "Internal observer's counter should be 21... ";
if(observer._i == 21) if (observer._i == 21)
test << "PASS"; test << "PASS";
else else
test << "FAIL"; test << "FAIL";

View File

@ -31,14 +31,15 @@
// from here and further until the bottom, all to throw away I suppose // from here and further until the bottom, all to throw away I suppose
int int
main(int argc, char** argv) { main(int argc, char** argv)
{
using namespace sgpem; using namespace sgpem;
using Glib::ustring; using Glib::ustring;
using std::cout; using std::cout;
using std::endl; using std::endl;
if((argc<4) || (argc%2)!=0) if ((argc < 4) || (argc % 2) != 0)
{ {
cout << "KeyFile class test program" << endl; cout << "KeyFile class test program" << endl;
cout << "Syntax: test-key_file filename key1 value1 [key2 value2...]" << endl; cout << "Syntax: test-key_file filename key1 value1 [key2 value2...]" << endl;
@ -63,7 +64,7 @@ main(int argc, char** argv) {
KeyFile kfile_bis; KeyFile kfile_bis;
// fill KeyFile object // fill KeyFile object
for(int index = 2; index<argc; index+=2) for (int index = 2; index < argc; index += 2)
{ {
kfile.insert_key_value(Glib::ustring(argv[index]), Glib::ustring(argv[index+1])); kfile.insert_key_value(Glib::ustring(argv[index]), Glib::ustring(argv[index+1]));
} }
@ -76,18 +77,18 @@ main(int argc, char** argv) {
// compare writed vs. readed data // compare writed vs. readed data
bool ok = true; bool ok = true;
for(int index = 2; ok && index<argc; index+=2) for (int index = 2; ok && index < argc; index += 2)
{ {
Glib::ustring val(argv[index+1]); Glib::ustring val(argv[index+1]);
const Glib::ustring* pt = kfile_bis.search_value(Glib::ustring(argv[index])); const Glib::ustring* pt = kfile_bis.search_value(Glib::ustring(argv[index]));
if(!pt || (*pt)!=val) if (!pt || (*pt) != val)
{ {
ok = false; ok = false;
} }
} }
// output response... // output response...
if(ok) if (ok)
{ {
cout << "Test successful" << endl; cout << "Test successful" << endl;
return 0; return 0;

View File

@ -89,7 +89,7 @@ namespace sgpem
History& History&
TestHistory::get_instance() TestHistory::get_instance()
{ {
if(!_instance) if (!_instance)
_instance = new TestHistory(); _instance = new TestHistory();
return *_instance; return *_instance;
} }

View File

@ -69,7 +69,7 @@ namespace sgpem
static Policy& get_instance() static Policy& get_instance()
{ {
if(!_instance) _instance = new Policy(3); // quantum size if (!_instance) _instance = new Policy(3); // quantum size
return *_instance; return *_instance;
} }
@ -167,7 +167,7 @@ namespace sgpem
PolicyManager::~PolicyManager() PolicyManager::~PolicyManager()
{ {
if(_registered == this) _registered = NULL; if (_registered == this) _registered = NULL;
} }
PolicyManager& PolicyManager&
@ -199,7 +199,7 @@ namespace sgpem
History::get_instance() History::get_instance()
{ {
if(!_instance) _instance = new Policy(3); // quantum size if (!_instance) _instance = new Policy(3); // quantum size
return *_instance; return *_instance;
} }
@ -213,7 +213,6 @@ namespace sgpem
// this class should invoke the Scheduler Stepforward method. // this class should invoke the Scheduler Stepforward method.
class StepForwardTester class StepForwardTester
{ {
} }
// from here and further until the bottom, all to throw away I suppose // from here and further until the bottom, all to throw away I suppose

View File

@ -77,8 +77,7 @@ namespace sgpem
description(_description), low_bound(_low_bound), description(_description), low_bound(_low_bound),
up_bound(_up_bound), required(_required), preset(_preset), up_bound(_up_bound), required(_required), preset(_preset),
value(_preset) value(_preset)
{ {}
}
template <typename T> template <typename T>
CommandParameter<T>::CommandParameter(const PolicyParameters::Parameter<T>& pparam) : CommandParameter<T>::CommandParameter(const PolicyParameters::Parameter<T>& pparam) :
@ -86,24 +85,21 @@ namespace sgpem
low_bound(pparam.get_lower_bound()), low_bound(pparam.get_lower_bound()),
up_bound(pparam.get_upper_bound()), required(pparam.is_required()), up_bound(pparam.get_upper_bound()), required(pparam.is_required()),
preset(pparam.get_default()), value(pparam.get_value()) preset(pparam.get_default()), value(pparam.get_value())
{ {}
}
} }
TextSimulation::TextSimulation() : TextSimulation::TextSimulation() :
_saved(true) _saved(true)
{ {}
}
TextSimulation::~TextSimulation() TextSimulation::~TextSimulation()
{ {}
}
bool bool
TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num) TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
{ {
if(arguments.size() < num) if (arguments.size() < num)
{ {
ostringstream oss; ostringstream oss;
oss << _("ERROR: this command requires at least ") << num << _(" arguments\n"); oss << _("ERROR: this command requires at least ") << num << _(" arguments\n");
@ -111,7 +107,7 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
return false; return false;
} }
else if(arguments.size() > num) else if (arguments.size() > num)
p_stderr(_("WARNING: some arguments will be ignored\n")); p_stderr(_("WARNING: some arguments will be ignored\n"));
return true; return true;
@ -120,12 +116,12 @@ TextSimulation::check_arguments_num(const Tokens& arguments, unsigned int num)
bool bool
TextSimulation::unsaved_ask_confirm() const TextSimulation::unsaved_ask_confirm() const
{ {
if(!_saved) if (!_saved)
{ {
p_stderr(_("WARNING: Simulation was not recently saved. " p_stderr(_("WARNING: Simulation was not recently saved. "
"If you continue some changes to the simulation might be lost.\n")); "If you continue some changes to the simulation might be lost.\n"));
for(bool bad_arg = true; bad_arg;) for (bool bad_arg = true; bad_arg;)
{ {
p_stdout(_("Continue? [y/n] ")); p_stdout(_("Continue? [y/n] "));
@ -133,11 +129,11 @@ TextSimulation::unsaved_ask_confirm() const
Tokens tokens = tokenize(buf); Tokens tokens = tokenize(buf);
if(tokens.size() == 1 && tokens[0].size() == 1) if (tokens.size() == 1 && tokens[0].size() == 1)
{ {
if(tokens[0].lowercase() == _("n")) if (tokens[0].lowercase() == _("n"))
return false; return false;
else if(tokens[0].lowercase() == _("y")) else if (tokens[0].lowercase() == _("y"))
bad_arg = false; bad_arg = false;
} }
} }
@ -150,7 +146,7 @@ template <typename Container>
void void
TextSimulation::show(const Container& entities) TextSimulation::show(const Container& entities)
{ {
for(unsigned int i = 0; i < entities.size(); ++i) for (unsigned int i = 0; i < entities.size(); ++i)
{ {
ostringstream oss; ostringstream oss;
oss << i + 1 << ". " << entities[i]->get_name() << endl; oss << i + 1 << ". " << entities[i]->get_name() << endl;
@ -163,9 +159,9 @@ namespace sgpem
{ {
template <> template <>
void void
TextSimulation::show<vector<Request*> >(const vector<Request*>& entities) TextSimulation::show<vector<Request*> > (const vector<Request*>& entities)
{ {
for(unsigned int i = 0; i < entities.size(); ++i) for (unsigned int i = 0; i < entities.size(); ++i)
{ {
ostringstream oss; ostringstream oss;
oss << i + 1 << ". instant: " << entities[i]->get_instant() << endl; oss << i + 1 << ". instant: " << entities[i]->get_instant() << endl;
@ -175,9 +171,9 @@ namespace sgpem
template <> template <>
void void
TextSimulation::show<vector<SubRequest*> >(const vector<SubRequest*>& entities) TextSimulation::show<vector<SubRequest*> > (const vector<SubRequest*>& entities)
{ {
for(unsigned int i = 0; i < entities.size(); ++i) for (unsigned int i = 0; i < entities.size(); ++i)
{ {
ostringstream oss; ostringstream oss;
@ -188,11 +184,11 @@ namespace sgpem
template <> template <>
void void
TextSimulation::show<map<int, Resource*> >(const map<int, Resource*>& entities) TextSimulation::show<map<int, Resource*> > (const map<int, Resource*>& entities)
{ {
typedef map<int, Resource*>::const_iterator ResourceIt; typedef map<int, Resource*>::const_iterator ResourceIt;
for(ResourceIt it = entities.begin(); it != entities.end(); ++it) for (ResourceIt it = entities.begin(); it != entities.end(); ++it)
{ {
ostringstream oss; ostringstream oss;
@ -202,7 +198,7 @@ namespace sgpem
} }
} }
} } //~ namespace sgpem
template <typename T> template <typename T>
void void
@ -216,7 +212,7 @@ TextSimulation::get_parameter(CommandParameter<T>& parameter)
ostringstream buf; ostringstream buf;
if(parameter.required) if (parameter.required)
buf << "*"; buf << "*";
buf << parameter.description << " (range: [" << parameter.low_bound << ", " << buf << parameter.description << " (range: [" << parameter.low_bound << ", " <<
@ -232,35 +228,35 @@ TextSimulation::get_parameter(CommandParameter<T>& parameter)
// to find if it's only composed of white spaces... // to find if it's only composed of white spaces...
// Indedeed there's a pro: by using extensively tokenize() we are more sure // Indedeed there's a pro: by using extensively tokenize() we are more sure
// it's correct ;-) // it's correct ;-)
if(tokenize(input).size() > 0) if (tokenize(input).size() > 0)
{ {
try try
{ {
value = string_to<T>(input); value = string_to<T>(input);
if(value > parameter.up_bound || value < parameter.low_bound) if (value > parameter.up_bound || value < parameter.low_bound)
{ {
p_stderr(_("ERROR: Provided value is out of range\n")); p_stderr(_("ERROR: Provided value is out of range\n"));
correct = false; correct = false;
} }
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: Please provide a valid numeric value\n")); p_stderr(_("ERROR: Please provide a valid numeric value\n"));
correct = false; correct = false;
} }
if(correct) if (correct)
parameter.value = value; parameter.value = value;
} }
else if(parameter.required) else if (parameter.required)
{ {
p_stderr(_("ERROR: This is a mandatory attribute; you MUST provide a valid value!\n")); p_stderr(_("ERROR: This is a mandatory attribute; you MUST provide a valid value!\n"));
correct = false; correct = false;
} }
} }
while(!correct); while (!correct);
} }
// Specializations need to go explicitly inside the namespace. why? // Specializations need to go explicitly inside the namespace. why?
@ -272,11 +268,11 @@ namespace sgpem
{ {
bool loop = true; bool loop = true;
while(loop) while (loop)
{ {
ustring buf; ustring buf;
if(parameter.required) if (parameter.required)
buf += "*"; buf += "*";
p_stdout(buf + parameter.description + p_stdout(buf + parameter.description +
@ -290,7 +286,7 @@ namespace sgpem
// it's correct ;-) // it's correct ;-)
Tokens tokens = tokenize(buf); Tokens tokens = tokenize(buf);
if(tokens.size() == 0 && parameter.required) if (tokens.size() == 0 && parameter.required)
p_stderr(_("ERROR: This is a mandatory atribute; you MUST provide a valid value!\n")); p_stderr(_("ERROR: This is a mandatory atribute; you MUST provide a valid value!\n"));
else else
{ {
@ -313,7 +309,7 @@ namespace sgpem
ostringstream buf; ostringstream buf;
if(parameter.required) if (parameter.required)
buf << "*"; buf << "*";
buf << parameter.description << buf << parameter.description <<
@ -329,25 +325,25 @@ namespace sgpem
// it's correct ;-) // it's correct ;-)
Tokens tokens = tokenize(str); Tokens tokens = tokenize(str);
if(tokens.size() != 0) if (tokens.size() != 0)
{ {
try try
{ {
parameter.value = string_to<bool>(str); parameter.value = string_to<bool>(str);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: Please provide a valid boolean value ('true' or 'false')\n")); p_stderr(_("ERROR: Please provide a valid boolean value ('true' or 'false')\n"));
correct = false; correct = false;
} }
} }
else if(parameter.required) else if (parameter.required)
{ {
p_stderr(_("ERROR: This is a mandatory atribute; you MUST provide a valid value!\n")); p_stderr(_("ERROR: This is a mandatory atribute; you MUST provide a valid value!\n"));
correct = false; correct = false;
} }
} }
while(!correct); while (!correct);
} }
} }
@ -363,13 +359,13 @@ TextSimulation::on_run(const Tokens& arguments)
{ {
Simulation::get_instance().run(); Simulation::get_instance().run();
} }
catch(UserInterruptException e) catch (UserInterruptException e)
{ {
p_stderr(_("ERROR: ")); p_stderr(_("ERROR: "));
p_stderr(e.what()); p_stderr(e.what());
p_stderr(_("\nSimulation is now stopped\n")); p_stderr(_("\nSimulation is now stopped\n"));
} }
catch(NullPolicyException e) catch (NullPolicyException e)
{ {
p_stderr(_("ERROR: ")); p_stderr(_("ERROR: "));
p_stderr(e.what()); p_stderr(e.what());
@ -402,7 +398,7 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
CPUPolicy* policy = Simulation::get_instance().get_policy(); CPUPolicy* policy = Simulation::get_instance().get_policy();
if(policy == NULL) if (policy == NULL)
{ {
p_stderr(_("ERROR: No policy actually selected for the simulation\n")); p_stderr(_("ERROR: No policy actually selected for the simulation\n"));
return; return;
@ -421,7 +417,7 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
IntParams int_params = parameters.get_registered_int_parameters(); IntParams int_params = parameters.get_registered_int_parameters();
for(IntParams::iterator it = int_params.begin(); it != int_params.end();) for (IntParams::iterator it = int_params.begin(); it != int_params.end();)
{ {
PolicyParameters::Parameter<int> &p = it->second; PolicyParameters::Parameter<int> &p = it->second;
CommandParameter<int> cmd_p(p); CommandParameter<int> cmd_p(p);
@ -442,7 +438,7 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
FloatParams float_params = parameters.get_registered_float_parameters(); FloatParams float_params = parameters.get_registered_float_parameters();
for(FloatParams::iterator it = float_params.begin(); it != float_params.end();) for (FloatParams::iterator it = float_params.begin(); it != float_params.end();)
{ {
PolicyParameters::Parameter<float> &p = it->second; PolicyParameters::Parameter<float> &p = it->second;
@ -459,7 +455,7 @@ TextSimulation::on_configure_cpu_policy(const Tokens& arguments)
StringParams string_params = parameters.get_registered_string_parameters(); StringParams string_params = parameters.get_registered_string_parameters();
for(StringParams::iterator it = string_params.begin(); it != string_params.end();) for (StringParams::iterator it = string_params.begin(); it != string_params.end();)
{ {
PolicyParameters::Parameter<ustring> &p = it->second; PolicyParameters::Parameter<ustring> &p = it->second;
@ -479,20 +475,20 @@ TextSimulation::on_help(const Tokens& arguments)
{ {
ustring command; ustring command;
if(arguments.size() > 0) if (arguments.size() > 0)
{ {
command = arguments[0].uppercase(); command = arguments[0].uppercase();
// print warning if necessary // print warning if necessary
check_arguments_num(arguments, 1); check_arguments_num(arguments, 1);
} }
if(command.size() == 0) if (command.size() == 0)
p_stdout(_("Avaiable commands:\nRUN\nSTOP\nPAUSE\n" p_stdout(_("Avaiable commands:\nRUN\nSTOP\nPAUSE\n"
"CONFIGURE-CPU-POLICY\nHELP\nGET\nSET\nSHOW\nADD\n" "CONFIGURE-CPU-POLICY\nHELP\nGET\nSET\nSHOW\nADD\n"
"REMOVE\nSAVE\nLOAD\nQUIT\n\n" "REMOVE\nSAVE\nLOAD\nQUIT\n\n"
"HELP followed by a command name shows help about it.\n" "HELP followed by a command name shows help about it.\n"
"ex. `HELP RUN` shows help about the command RUN\n")); "ex. `HELP RUN` shows help about the command RUN\n"));
else if(command == "RUN") else if (command == "RUN")
p_stdout(_("-- RUN COMMAND --\nStarts the simulation. It can be " p_stdout(_("-- RUN COMMAND --\nStarts the simulation. It can be "
"continuous or step-by-step depending on the mode configured with " "continuous or step-by-step depending on the mode configured with "
"SET CONTINUOUS (default=true).\n\n" "SET CONTINUOUS (default=true).\n\n"
@ -501,25 +497,25 @@ TextSimulation::on_help(const Tokens& arguments)
"The instant 0 represents the initial state, " "The instant 0 represents the initial state, "
"during which no process is running. The scheduler " "during which no process is running. The scheduler "
"activity begins at instant 1.\n")); "activity begins at instant 1.\n"));
else if(command == "STOP") else if (command == "STOP")
p_stdout(_("-- STOP COMMAND --\nStops the simulation. The next call to RUN will " p_stdout(_("-- STOP COMMAND --\nStops the simulation. The next call to RUN will "
"bring the simulation to the first instant and start it.\n")); "bring the simulation to the first instant and start it.\n"));
else if(command == "PAUSE") else if (command == "PAUSE")
p_stdout(_("-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will " p_stdout(_("-- PAUSE COMMAND --\nPauses the simulation. The next call to RUN will "
"continue it.\n")); "continue it.\n"));
else if(command == "CONFIGURE-CPU-POLICY") else if (command == "CONFIGURE-CPU-POLICY")
p_stdout(_("-- CONFIGURE-CPU-POLICY COMMAND --\nConfigure parameters exposed by " p_stdout(_("-- CONFIGURE-CPU-POLICY COMMAND --\nConfigure parameters exposed by "
"the cpu policy.\n\nThis is currently the only way to control the behaviour of " "the cpu policy.\n\nThis is currently the only way to control the behaviour of "
"cpu policies without modifying their source code.\n")); "cpu policies without modifying their source code.\n"));
else if(command == "HELP") else if (command == "HELP")
p_stdout(_("-- HELP COMMAND --\nThe help you're reading.\n")); p_stdout(_("-- HELP COMMAND --\nThe help you're reading.\n"));
else if(command == "GET") else if (command == "GET")
p_stdout(_("-- GET COMMAND --\nSyntax: GET <attr_name>\n" p_stdout(_("-- GET COMMAND --\nSyntax: GET <attr_name>\n"
"\twhere <attr_name> may be simulation-tick or continuous.\n")); "\twhere <attr_name> may be simulation-tick or continuous.\n"));
else if(command == "SET") else if (command == "SET")
p_stdout(_("-- SET COMMAND --\nSyntax: SET <attr_name> [=] <value>\n" p_stdout(_("-- SET COMMAND --\nSyntax: SET <attr_name> [=] <value>\n"
"\twhere <attr_name> may be simulation-tick, continuous or cpu-policy.\n")); "\twhere <attr_name> may be simulation-tick, continuous or cpu-policy.\n"));
else if(command == "SHOW") else if (command == "SHOW")
p_stderr(_("-- SHOW COMMAND --\nDisplays the name of the entities (if available) " p_stderr(_("-- SHOW COMMAND --\nDisplays the name of the entities (if available) "
"and other informations prefixed by its numeric identifier.\n\n" "and other informations prefixed by its numeric identifier.\n\n"
"Syntax depends from entities being displayed:\n" "Syntax depends from entities being displayed:\n"
@ -530,7 +526,7 @@ TextSimulation::on_help(const Tokens& arguments)
"identifier of the thread child of process identified by <process_id>\n" "identifier of the thread child of process identified by <process_id>\n"
"`SHOW subrequests <process_id> <thread_id> <request_id>` where the numeric ids " "`SHOW subrequests <process_id> <thread_id> <request_id>` where the numeric ids "
"follow the same logic of the previous commands\n")); "follow the same logic of the previous commands\n"));
else if(command == "ADD") else if (command == "ADD")
p_stderr(_("-- ADD COMMAND --\nAdds an entity by using a questionary-like approach.\n\n" p_stderr(_("-- ADD COMMAND --\nAdds an entity by using a questionary-like approach.\n\n"
"Syntax depends from entity being added:\n" "Syntax depends from entity being added:\n"
"`ADD process|resource`\n" "`ADD process|resource`\n"
@ -540,7 +536,7 @@ TextSimulation::on_help(const Tokens& arguments)
"identifier of the thread child of process identified by <process_id>\n" "identifier of the thread child of process identified by <process_id>\n"
"`ADD subrequest <process_id> <thread_id> <request_id>` where the numeric ids " "`ADD subrequest <process_id> <thread_id> <request_id>` where the numeric ids "
"follow the same logic of the previous commands\n")); "follow the same logic of the previous commands\n"));
else if(command == "REMOVE") else if (command == "REMOVE")
p_stderr(_("-- REMOVE COMMAND --\nRemoves an entity.\n\n" p_stderr(_("-- REMOVE COMMAND --\nRemoves an entity.\n\n"
"Syntax depends from entity being removed:\n" "Syntax depends from entity being removed:\n"
"`REMOVE process|resource <id>` where <id> is the process or resource identifier\n" "`REMOVE process|resource <id>` where <id> is the process or resource identifier\n"
@ -550,13 +546,13 @@ TextSimulation::on_help(const Tokens& arguments)
"numeric ids follow the same logic of the previous commands\n" "numeric ids follow the same logic of the previous commands\n"
"`REMOVE subrequest <process_id> <thread_id> <request_id> <subrequest_id>` where the " "`REMOVE subrequest <process_id> <thread_id> <request_id> <subrequest_id>` where the "
"numeric ids follow the same logic of the previous commands\n")); "numeric ids follow the same logic of the previous commands\n"));
else if(command == "SAVE") else if (command == "SAVE")
p_stderr(_("-- SAVE COMMAND --\nSaves the simulation.\n\n" p_stderr(_("-- SAVE COMMAND --\nSaves the simulation.\n\n"
"Syntax: SAVE <filename>\n")); "Syntax: SAVE <filename>\n"));
else if(command == "LOAD") else if (command == "LOAD")
p_stderr(_("-- LOAD COMMAND --\nLoads the simulation.\n\n" p_stderr(_("-- LOAD COMMAND --\nLoads the simulation.\n\n"
"Syntax: LOAD <filename>\n")); "Syntax: LOAD <filename>\n"));
else if(command == "QUIT") else if (command == "QUIT")
p_stderr(_("-- QUIT COMMAND --\nGently closes the program.\n")); p_stderr(_("-- QUIT COMMAND --\nGently closes the program.\n"));
else else
p_stderr(_("ERROR: Sorry, no help available for this command.\n")); p_stderr(_("ERROR: Sorry, no help available for this command.\n"));
@ -567,7 +563,7 @@ TextSimulation::on_quit(const Tokens& arguments)
{ {
check_arguments_num(arguments, 0); check_arguments_num(arguments, 0);
if(!unsaved_ask_confirm()) if (!unsaved_ask_confirm())
return; return;
p_stdout(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n")); p_stdout(_("\n\n*** Thank you for using SGPEM by Sirius Cybernetics Corporation ***\n\n"));
@ -579,18 +575,18 @@ TextSimulation::on_quit(const Tokens& arguments)
void void
TextSimulation::on_get(const Tokens& arguments) TextSimulation::on_get(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring attr = arguments[0].uppercase(); ustring attr = arguments[0].uppercase();
if(attr == "SIMULATION-TICK") if (attr == "SIMULATION-TICK")
{ {
ostringstream oss; ostringstream oss;
oss << "simulation-tick = " << Simulation::get_instance().get_timer() << "ms" << endl; oss << "simulation-tick = " << Simulation::get_instance().get_timer() << "ms" << endl;
p_stdout(oss.str()); p_stdout(oss.str());
} }
else if(attr == "CONTINUOUS") else if (attr == "CONTINUOUS")
{ {
ostringstream oss; ostringstream oss;
oss << "continuous = " << boolalpha << Simulation::get_instance().get_mode() << endl; oss << "continuous = " << boolalpha << Simulation::get_instance().get_mode() << endl;
@ -605,38 +601,38 @@ TextSimulation::on_set(const Tokens& arguments)
{ {
// handle the optional "=' (I knew that I was buying myself a problem when I // handle the optional "=' (I knew that I was buying myself a problem when I
// decided to support the assigment operator!) // decided to support the assigment operator!)
if(arguments.size() >= 3) if (arguments.size() >= 3)
check_arguments_num(arguments, 3); check_arguments_num(arguments, 3);
else if(!check_arguments_num(arguments, 2)) else if (!check_arguments_num(arguments, 2))
return; return;
ustring attr = arguments[0].uppercase(); ustring attr = arguments[0].uppercase();
ustring value; ustring value;
if(arguments[1] == "=") if (arguments[1] == "=")
value = arguments[2]; value = arguments[2];
else else
value = arguments[1]; value = arguments[1];
if(attr == "SIMULATION-TICK") if (attr == "SIMULATION-TICK")
{ {
try try
{ {
int timer = string_to<int>(value); int timer = string_to<int>(value);
if(timer < 0) if (timer < 0)
throw domain_error(""); throw domain_error("");
Simulation::get_instance().set_timer(timer); Simulation::get_instance().set_timer(timer);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: you must provide a valid unsigned integer value\n")); p_stderr(_("ERROR: you must provide a valid unsigned integer value\n"));
} }
} }
else if(attr == "CPU-POLICY") else if (attr == "CPU-POLICY")
{ {
int policy; int policy;
@ -644,7 +640,7 @@ TextSimulation::on_set(const Tokens& arguments)
{ {
policy = string_to<int>(value) - 1; policy = string_to<int>(value) - 1;
if(policy < 0) if (policy < 0)
throw domain_error(""); throw domain_error("");
typedef vector<CPUPolicyManager*> ManagerVec; typedef vector<CPUPolicyManager*> ManagerVec;
@ -654,27 +650,27 @@ TextSimulation::on_set(const Tokens& arguments)
ManagerVec managers = gatekeeper.get_registered(); ManagerVec managers = gatekeeper.get_registered();
for(ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it) for (ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it)
{ {
vector<CPUPolicy*> policies = (*it)->get_avail_policies(); vector<CPUPolicy*> policies = (*it)->get_avail_policies();
for(CPUPolicyIt it = policies.begin(); it != policies.end(); ++it) for (CPUPolicyIt it = policies.begin(); it != policies.end(); ++it)
{ {
if(policy == 0) if (policy == 0)
Simulation::get_instance().set_policy(*it); Simulation::get_instance().set_policy(*it);
--policy; --policy;
} }
} }
if(policy >= 0) if (policy >= 0)
throw domain_error(""); throw domain_error("");
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: invalid unsigned integer or not a valid policy index\n")); p_stderr(_("ERROR: invalid unsigned integer or not a valid policy index\n"));
} }
} }
else if(attr == "CONTINUOUS") else if (attr == "CONTINUOUS")
{ {
try try
{ {
@ -682,7 +678,7 @@ TextSimulation::on_set(const Tokens& arguments)
Simulation::get_instance().set_mode(continuous); Simulation::get_instance().set_mode(continuous);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: you must provide a valid boolean value ('true' or 'false')\n")); p_stderr(_("ERROR: you must provide a valid boolean value ('true' or 'false')\n"));
} }
@ -694,7 +690,7 @@ TextSimulation::on_set(const Tokens& arguments)
void void
TextSimulation::on_show(const Tokens& arguments) TextSimulation::on_show(const Tokens& arguments)
{ {
if(arguments.size() < 1) if (arguments.size() < 1)
{ {
//print error //print error
check_arguments_num(arguments, 1); check_arguments_num(arguments, 1);
@ -718,7 +714,7 @@ TextSimulation::on_show(const Tokens& arguments)
entities_handlers["CPU-POLICIES"] = &TextSimulation::on_show_cpu_policies; entities_handlers["CPU-POLICIES"] = &TextSimulation::on_show_cpu_policies;
entities_handlers["RESOURCE-POLICIES"] = &TextSimulation::on_show_resource_policies; entities_handlers["RESOURCE-POLICIES"] = &TextSimulation::on_show_resource_policies;
if(entities_handlers.find(entities) == entities_handlers.end()) if (entities_handlers.find(entities) == entities_handlers.end())
p_stderr(_("ERROR: invalid argument\n")); p_stderr(_("ERROR: invalid argument\n"));
else else
(this->*(entities_handlers[entities]))(args); (this->*(entities_handlers[entities]))(args);
@ -749,7 +745,7 @@ TextSimulation::on_show_resources(const Tokens& arguments)
void void
TextSimulation::on_show_threads(const Tokens& arguments) TextSimulation::on_show_threads(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -764,12 +760,12 @@ TextSimulation::on_show_threads(const Tokens& arguments)
int pid = string_to<int>(process) - 1; int pid = string_to<int>(process) - 1;
threads = processes.at(pid)->get_threads(); threads = processes.at(pid)->get_threads();
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided process identifier is not a valid integer\n")); p_stderr(_("ERROR: provided process identifier is not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: this process identifier does not belong to an existing process\n")); p_stderr(_("ERROR: this process identifier does not belong to an existing process\n"));
return; return;
@ -782,7 +778,7 @@ TextSimulation::on_show_threads(const Tokens& arguments)
void void
TextSimulation::on_show_requests(const Tokens& arguments) TextSimulation::on_show_requests(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 2)) if (!check_arguments_num(arguments, 2))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -800,12 +796,12 @@ TextSimulation::on_show_requests(const Tokens& arguments)
vector<Thread*> threads = processes.at(pid)->get_threads(); vector<Thread*> threads = processes.at(pid)->get_threads();
requests = threads.at(tid)->get_requests(); requests = threads.at(tid)->get_requests();
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -817,7 +813,7 @@ TextSimulation::on_show_requests(const Tokens& arguments)
void void
TextSimulation::on_show_subrequests(const Tokens& arguments) TextSimulation::on_show_subrequests(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 3)) if (!check_arguments_num(arguments, 3))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -838,12 +834,12 @@ TextSimulation::on_show_subrequests(const Tokens& arguments)
vector<Request*> requests = threads.at(tid)->get_requests(); vector<Request*> requests = threads.at(tid)->get_requests();
subrequests = requests.at(rid)->get_subrequests(); subrequests = requests.at(rid)->get_subrequests();
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -865,10 +861,10 @@ TextSimulation::on_show_cpu_policies(const Tokens& arguments)
ManagerVec managers = gatekeeper.get_registered(); ManagerVec managers = gatekeeper.get_registered();
unsigned int index = 1; unsigned int index = 1;
for(ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it) for (ManagerVec::iterator it = managers.begin(); it != managers.end(); ++it)
{ {
vector<CPUPolicy*> policies = (*it)->get_avail_policies(); vector<CPUPolicy*> policies = (*it)->get_avail_policies();
for(CPUPolicyIt it = policies.begin(); it != policies.end(); ++it) for (CPUPolicyIt it = policies.begin(); it != policies.end(); ++it)
{ {
ostringstream oss; ostringstream oss;
oss << index << ". " << (*it)->get_name() << endl; oss << index << ". " << (*it)->get_name() << endl;
@ -891,14 +887,14 @@ TextSimulation::on_show_resource_policies(const Tokens& arguments)
void void
TextSimulation::on_add(const Tokens& arguments) TextSimulation::on_add(const Tokens& arguments)
{ {
if(arguments.size() < 1) if (arguments.size() < 1)
{ {
//print error //print error
check_arguments_num(arguments, 1); check_arguments_num(arguments, 1);
return; return;
} }
if(Simulation::get_instance().get_state() != Simulation::state_stopped) if (Simulation::get_instance().get_state() != Simulation::state_stopped)
{ {
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped\n")); p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped\n"));
Simulation::get_instance().stop(); Simulation::get_instance().stop();
@ -919,7 +915,7 @@ TextSimulation::on_add(const Tokens& arguments)
entity_handlers["REQUEST"] = &TextSimulation::on_add_request; entity_handlers["REQUEST"] = &TextSimulation::on_add_request;
entity_handlers["SUBREQUEST"] = &TextSimulation::on_add_subrequest; entity_handlers["SUBREQUEST"] = &TextSimulation::on_add_subrequest;
if(entity_handlers.find(entity) == entity_handlers.end()) if (entity_handlers.find(entity) == entity_handlers.end())
p_stderr(_("ERROR: invalid argument\n")); p_stderr(_("ERROR: invalid argument\n"));
else else
(this->*(entity_handlers[entity]))(args); (this->*(entity_handlers[entity]))(args);
@ -966,7 +962,7 @@ TextSimulation::on_add_resource(const Tokens& arguments)
void void
TextSimulation::on_add_thread(const Tokens& arguments) TextSimulation::on_add_thread(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -980,12 +976,12 @@ TextSimulation::on_add_thread(const Tokens& arguments)
{ {
p = processes.at(string_to<int>(process) - 1); p = processes.at(string_to<int>(process) - 1);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1010,7 +1006,7 @@ TextSimulation::on_add_thread(const Tokens& arguments)
void void
TextSimulation::on_add_request(const Tokens& arguments) TextSimulation::on_add_request(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 2)) if (!check_arguments_num(arguments, 2))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -1029,12 +1025,12 @@ TextSimulation::on_add_request(const Tokens& arguments)
vector<Thread*> threads = processes.at(pid)->get_threads(); vector<Thread*> threads = processes.at(pid)->get_threads();
t = threads.at(tid); t = threads.at(tid);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1052,7 +1048,7 @@ TextSimulation::on_add_request(const Tokens& arguments)
void void
TextSimulation::on_add_subrequest(const Tokens& arguments) TextSimulation::on_add_subrequest(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 3)) if (!check_arguments_num(arguments, 3))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -1075,12 +1071,12 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
r = requests.at(rid); r = requests.at(rid);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1095,10 +1091,10 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
{ {
get_parameter(resource_key); get_parameter(resource_key);
if(resources.find(resource_key.value) == resources.end()) if (resources.find(resource_key.value) == resources.end())
p_stderr(_("ERROR: invalid resource identifier\n")); p_stderr(_("ERROR: invalid resource identifier\n"));
} }
while(resources.find(resource_key.value) == resources.end()); while (resources.find(resource_key.value) == resources.end());
get_parameter(duration); get_parameter(duration);
@ -1110,14 +1106,14 @@ TextSimulation::on_add_subrequest(const Tokens& arguments)
void void
TextSimulation::on_remove(const Tokens& arguments) TextSimulation::on_remove(const Tokens& arguments)
{ {
if(arguments.size() < 1) if (arguments.size() < 1)
{ {
//print error //print error
check_arguments_num(arguments, 1); check_arguments_num(arguments, 1);
return; return;
} }
if(Simulation::get_instance().get_state() != Simulation::state_stopped) if (Simulation::get_instance().get_state() != Simulation::state_stopped)
p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped")); p_stderr(_("WARNING: Simulation is not stopped, it will be automatically stopped"));
//make a local copy which we'll probably modify //make a local copy which we'll probably modify
@ -1135,7 +1131,7 @@ TextSimulation::on_remove(const Tokens& arguments)
entity_handlers["REQUEST"] = &TextSimulation::on_remove_request; entity_handlers["REQUEST"] = &TextSimulation::on_remove_request;
entity_handlers["SUBREQUEST"] = &TextSimulation::on_remove_subrequest; entity_handlers["SUBREQUEST"] = &TextSimulation::on_remove_subrequest;
if(entity_handlers.find(entity) == entity_handlers.end()) if (entity_handlers.find(entity) == entity_handlers.end())
p_stderr(_("ERROR: invalid argument\n")); p_stderr(_("ERROR: invalid argument\n"));
else else
(this->*(entity_handlers[entity]))(args); (this->*(entity_handlers[entity]))(args);
@ -1144,7 +1140,7 @@ TextSimulation::on_remove(const Tokens& arguments)
void void
TextSimulation::on_remove_process(const Tokens& arguments) TextSimulation::on_remove_process(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -1158,12 +1154,12 @@ TextSimulation::on_remove_process(const Tokens& arguments)
{ {
p = processes.at(string_to<int>(process) - 1); p = processes.at(string_to<int>(process) - 1);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1176,7 +1172,7 @@ TextSimulation::on_remove_process(const Tokens& arguments)
void void
TextSimulation::on_remove_resource(const Tokens& arguments) TextSimulation::on_remove_resource(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring resource = arguments[0]; ustring resource = arguments[0];
@ -1192,15 +1188,15 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
const Environment::Resources& resources = const Environment::Resources& resources =
h.get_environment_at(0).get_resources(); h.get_environment_at(0).get_resources();
if(resources.find(rid) == resources.end()) if (resources.find(rid) == resources.end())
throw out_of_range(_("invalid resource id")); throw out_of_range(_("invalid resource id"));
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1212,7 +1208,7 @@ TextSimulation::on_remove_resource(const Tokens& arguments)
void void
TextSimulation::on_remove_thread(const Tokens& arguments) TextSimulation::on_remove_thread(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 2)) if (!check_arguments_num(arguments, 2))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -1231,12 +1227,12 @@ TextSimulation::on_remove_thread(const Tokens& arguments)
vector<Thread*> threads = processes.at(pid)->get_threads(); vector<Thread*> threads = processes.at(pid)->get_threads();
t = threads.at(tid); t = threads.at(tid);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1249,7 +1245,7 @@ TextSimulation::on_remove_thread(const Tokens& arguments)
void void
TextSimulation::on_remove_request(const Tokens& arguments) TextSimulation::on_remove_request(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 3)) if (!check_arguments_num(arguments, 3))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -1271,12 +1267,12 @@ TextSimulation::on_remove_request(const Tokens& arguments)
vector<Request*> requests = threads.at(tid)->get_requests(); vector<Request*> requests = threads.at(tid)->get_requests();
r = requests.at(rid); r = requests.at(rid);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1289,7 +1285,7 @@ TextSimulation::on_remove_request(const Tokens& arguments)
void void
TextSimulation::on_remove_subrequest(const Tokens& arguments) TextSimulation::on_remove_subrequest(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 4)) if (!check_arguments_num(arguments, 4))
return; return;
ustring process = arguments[0]; ustring process = arguments[0];
@ -1314,12 +1310,12 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments)
vector<SubRequest*> subrequests = requests.at(rid)->get_subrequests(); vector<SubRequest*> subrequests = requests.at(rid)->get_subrequests();
r = subrequests.at(srid); r = subrequests.at(srid);
} }
catch(domain_error e) catch (domain_error e)
{ {
p_stderr(_("ERROR: provided identifier(s) not a valid integer\n")); p_stderr(_("ERROR: provided identifier(s) not a valid integer\n"));
return; return;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n")); p_stderr(_("ERROR: the identifier(s) do not belong to an existing entity\n"));
return; return;
@ -1332,7 +1328,7 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments)
void void
TextSimulation::on_save(const Tokens& arguments) TextSimulation::on_save(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring filename = arguments[0]; ustring filename = arguments[0];
@ -1353,11 +1349,11 @@ TextSimulation::on_save(const Tokens& arguments)
_saved = true; _saved = true;
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: No registered serializer available\n")); p_stderr(_("ERROR: No registered serializer available\n"));
} }
catch(SerializerError e) catch (SerializerError e)
{ {
string msg = _("ERROR: "); string msg = _("ERROR: ");
@ -1368,12 +1364,12 @@ TextSimulation::on_save(const Tokens& arguments)
void void
TextSimulation::on_load(const Tokens& arguments) TextSimulation::on_load(const Tokens& arguments)
{ {
if(!check_arguments_num(arguments, 1)) if (!check_arguments_num(arguments, 1))
return; return;
ustring filename = arguments[0]; ustring filename = arguments[0];
if(!unsaved_ask_confirm()) if (!unsaved_ask_confirm())
return; return;
try try
@ -1390,11 +1386,11 @@ TextSimulation::on_load(const Tokens& arguments)
serializer.restore_snapshot(filename, history); serializer.restore_snapshot(filename, history);
} }
catch(out_of_range e) catch (out_of_range e)
{ {
p_stderr(_("ERROR: No registered serializer available\n")); p_stderr(_("ERROR: No registered serializer available\n"));
} }
catch(SerializerError e) catch (SerializerError e)
{ {
string msg = _("ERROR: "); string msg = _("ERROR: ");
@ -1447,12 +1443,12 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
Tokens arguments = tokenize(str); Tokens arguments = tokenize(str);
if(arguments.size() == 0) if (arguments.size() == 0)
return; return;
ustring key = arguments[0].uppercase(); ustring key = arguments[0].uppercase();
if(command_handlers.find(key) == command_handlers.end()) if (command_handlers.find(key) == command_handlers.end())
{ {
p_stderr(_("ERROR: command not supported\n")); p_stderr(_("ERROR: command not supported\n"));
return; return;
@ -1462,14 +1458,14 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
(sim.*(command_handlers[key]))(arguments); (sim.*(command_handlers[key]))(arguments);
if(key == "ADD" || key == "REMOVE") if (key == "ADD" || key == "REMOVE")
sim._saved = false; sim._saved = false;
} }
static ostream& static ostream&
operator<<(ostream& os, Schedulable::state state) operator<<(ostream& os, Schedulable::state state)
{ {
switch(state) switch (state)
{ {
case Schedulable::state_running: case Schedulable::state_running:
os << "RUNNING"; os << "RUNNING";
@ -1496,7 +1492,7 @@ operator<<(ostream& os, Schedulable::state state)
static ostream& static ostream&
operator<<(ostream& os, Request::state state) operator<<(ostream& os, Request::state state)
{ {
switch(state) switch (state)
{ {
case Request::state_unallocable: case Request::state_unallocable:
os << "UNALLOCABLE"; os << "UNALLOCABLE";
@ -1534,7 +1530,7 @@ TextSimulation::update(const History& changed_history)
// this is a damn uint, so we must hack and hack // this is a damn uint, so we must hack and hack
int printed_instant; int printed_instant;
if(changed_history.get_size() > 1) if (changed_history.get_size() > 1)
printed_instant = static_cast<int>(changed_history.get_size()) - 2; printed_instant = static_cast<int>(changed_history.get_size()) - 2;
else else
printed_instant = -1; printed_instant = -1;
@ -1548,7 +1544,7 @@ TextSimulation::update(const History& changed_history)
const Environment& env = changed_history.get_last_environment(); const Environment& env = changed_history.get_last_environment();
const ReadyQueue& q = env.get_sorted_queue(); const ReadyQueue& q = env.get_sorted_queue();
for(unsigned int i = 0; i < q.size(); ++i) for (unsigned int i = 0; i < q.size(); ++i)
{ {
const Thread& t = q.get_item_at(i); const Thread& t = q.get_item_at(i);
@ -1562,7 +1558,7 @@ TextSimulation::update(const History& changed_history)
const Environment::Resources& resources = env.get_resources(); const Environment::Resources& resources = env.get_resources();
typedef Environment::Resources::const_iterator ResourceIt; typedef Environment::Resources::const_iterator ResourceIt;
for(ResourceIt it = resources.begin(); it != resources.end(); ++it) for (ResourceIt it = resources.begin(); it != resources.end(); ++it)
{ {
const Resource& r = *it->second; const Resource& r = *it->second;
Environment::resource_key_t key = it->first; Environment::resource_key_t key = it->first;
@ -1580,7 +1576,7 @@ TextSimulation::update(const History& changed_history)
p_stdout(_("\t\t\tqueue: { ")); p_stdout(_("\t\t\tqueue: { "));
for(unsigned int i = 0; i < req_queue.size(); ++i) for (unsigned int i = 0; i < req_queue.size(); ++i)
{ {
if (i == r.get_places()) if (i == r.get_places())
oss << " || "; oss << " || ";
@ -1603,7 +1599,7 @@ TextSimulation::update(const History& changed_history)
const Environment::Processes& processes = env.get_processes(); const Environment::Processes& processes = env.get_processes();
for(unsigned int pi = 0; pi < processes.size(); ++pi) for (unsigned int pi = 0; pi < processes.size(); ++pi)
{ {
Process& p = *processes[pi]; Process& p = *processes[pi];
@ -1619,7 +1615,7 @@ TextSimulation::update(const History& changed_history)
vector<Thread*> threads = p.get_threads(); vector<Thread*> threads = p.get_threads();
for(unsigned int ti = 0; ti < threads.size(); ++ti) for (unsigned int ti = 0; ti < threads.size(); ++ti)
{ {
Thread& t = *threads[ti]; Thread& t = *threads[ti];
@ -1635,13 +1631,13 @@ TextSimulation::update(const History& changed_history)
vector<Request*> requests = t.get_requests(); vector<Request*> requests = t.get_requests();
for(unsigned int ri = 0; ri < requests.size(); ++ri) for (unsigned int ri = 0; ri < requests.size(); ++ri)
{ {
Request& r = *requests[ri]; Request& r = *requests[ri];
vector<SubRequest*> subrequests = r.get_subrequests(); vector<SubRequest*> subrequests = r.get_subrequests();
for(unsigned int sri = 0; sri < subrequests.size(); ++sri) for (unsigned int sri = 0; sri < subrequests.size(); ++sri)
{ {
SubRequest& sr = *subrequests[sri]; SubRequest& sr = *subrequests[sri];
oss << _(" --> request ") << ri + 1 << "." << sri + 1 << ") "; oss << _(" --> request ") << ri + 1 << "." << sri + 1 << ") ";