- 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:
parent
aaf8e068d3
commit
d3c7b46853
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
@ -209,10 +209,10 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
|
||||||
|
|
||||||
|
|
||||||
throw UserInterruptException(_("User-defined policy is "
|
throw UserInterruptException(_("User-defined policy is "
|
||||||
"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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ PythonCPUPolicyManager::~PythonCPUPolicyManager()
|
||||||
void
|
void
|
||||||
PythonCPUPolicyManager::init()
|
PythonCPUPolicyManager::init()
|
||||||
{
|
{
|
||||||
if(_initialized)
|
if (_initialized)
|
||||||
// No-op
|
// No-op
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -114,35 +114,35 @@ 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;
|
||||||
|
|
||||||
//strip extension
|
//strip extension
|
||||||
std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3);
|
std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
|
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
|
||||||
|
|
||||||
_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cout << "no" << endl;
|
cout << "no" << endl;
|
||||||
|
|
|
@ -57,7 +57,7 @@ namespace sgpem
|
||||||
/** The selected and active PyhonCPUPolicy object. */
|
/** The selected and active PyhonCPUPolicy object. */
|
||||||
void collect_policies();
|
void collect_policies();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PythonCPUPolicyManager(const PythonCPUPolicyManager&);
|
PythonCPUPolicyManager(const PythonCPUPolicyManager&);
|
||||||
PythonCPUPolicyManager& operator=(const PythonCPUPolicyManager&);
|
PythonCPUPolicyManager& operator=(const PythonCPUPolicyManager&);
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,11 @@ using namespace std;
|
||||||
static CPUPolicy*
|
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;
|
||||||
|
@ -72,29 +72,29 @@ main(int argc, char** argv)
|
||||||
PythonCPUPolicyManager polman;
|
PythonCPUPolicyManager polman;
|
||||||
polman.init();
|
polman.init();
|
||||||
|
|
||||||
Simulation& sim = Simulation::get_instance();
|
Simulation& sim = Simulation::get_instance();
|
||||||
History& his = sim.get_history();
|
History& his = sim.get_history();
|
||||||
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
|
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
|
||||||
|
|
||||||
const std::vector<CPUPolicy*>& policies = polman.get_avail_policies();
|
const std::vector<CPUPolicy*>& policies = polman.get_avail_policies();
|
||||||
|
|
||||||
// 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
|
||||||
{
|
{
|
||||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_configure");
|
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_configure");
|
||||||
assert(pol != NULL);
|
assert(pol != NULL);
|
||||||
|
|
||||||
// FIXME : Maybe activating a policy only to configure it is an overkill?
|
// FIXME : Maybe activating a policy only to configure it is an overkill?
|
||||||
// Who gives a fuck about it?
|
// Who gives a fuck about it?
|
||||||
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++;
|
||||||
|
@ -103,12 +103,12 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
|
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
|
||||||
assert(pol != NULL);
|
assert(pol != NULL);
|
||||||
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++;
|
||||||
|
@ -117,12 +117,12 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
||||||
assert(pol != NULL);
|
assert(pol != NULL);
|
||||||
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++;
|
||||||
|
@ -132,12 +132,12 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
||||||
assert(pol != NULL);
|
assert(pol != NULL);
|
||||||
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++;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -131,7 +131,7 @@ main(int argc, char** argv)
|
||||||
cout << "test failed" << endl;
|
cout << "test failed" << endl;
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,18 +201,18 @@ 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()
|
||||||
/* << " key: " << (*riter).first */
|
/* << " key: " << (*riter).first */
|
||||||
<< " places: " << r->get_places() << endl;
|
<< " places: " << r->get_places() << endl;
|
||||||
riter++;
|
riter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,12 +221,12 @@ 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()
|
||||||
<< " arrival_time: " << p->get_arrival_time()
|
<< " arrival_time: " << p->get_arrival_time()
|
||||||
<< " base_priority: " << p->get_base_priority() << endl;
|
<< " base_priority: " << p->get_base_priority() << endl;
|
||||||
iter++;
|
iter++;
|
||||||
|
|
||||||
typedef std::vector<Thread*> Threads;
|
typedef std::vector<Thread*> Threads;
|
||||||
|
@ -234,20 +234,20 @@ 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);
|
||||||
os << " thread name: " << t->get_name()
|
os << " thread name: " << t->get_name()
|
||||||
<< " arrival_time: " << t->get_arrival_time()
|
<< " arrival_time: " << t->get_arrival_time()
|
||||||
<< " base_priority: " << t->get_base_priority() << endl;
|
<< " base_priority: " << t->get_base_priority() << endl;
|
||||||
|
|
||||||
typedef std::vector<Request*> Requests;
|
typedef std::vector<Request*> Requests;
|
||||||
typedef std::vector<Request*>::const_iterator req_iterator;
|
typedef std::vector<Request*>::const_iterator req_iterator;
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.");
|
||||||
}
|
}
|
||||||
|
@ -67,41 +66,42 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
|
||||||
|
|
||||||
void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError)
|
void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError)
|
||||||
{
|
{
|
||||||
// TODO - all to do!!
|
// TODO - all to do!!
|
||||||
// DEBUG - remove me when finished
|
// DEBUG - remove me when finished
|
||||||
|
|
||||||
#ifdef LIBXML_SAX1_ENABLED
|
#ifdef LIBXML_SAX1_ENABLED
|
||||||
xmlDocPtr doc;
|
xmlDocPtr doc;
|
||||||
|
|
||||||
LIBXML_TEST_VERSION
|
LIBXML_TEST_VERSION
|
||||||
xmlKeepBlanksDefault(0);
|
xmlKeepBlanksDefault(0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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();
|
{
|
||||||
throw SerializerError("Parsing Error: doc is invalid.");
|
|
||||||
}
|
|
||||||
|
|
||||||
clear_history(hist);
|
|
||||||
XMLSerializerFactory fact(hist);
|
|
||||||
|
|
||||||
// read all elements and fill hist
|
|
||||||
read_doc(doc, fact);
|
|
||||||
|
|
||||||
// frees all xml related data
|
|
||||||
xmlFreeDoc(doc);
|
|
||||||
|
|
||||||
/* Clean up everything else before quitting. */
|
|
||||||
xmlCleanupParser();
|
xmlCleanupParser();
|
||||||
|
throw SerializerError("Parsing Error: doc is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
clear_history(hist);
|
||||||
|
XMLSerializerFactory fact(hist);
|
||||||
|
|
||||||
|
// read all elements and fill hist
|
||||||
|
read_doc(doc, fact);
|
||||||
|
|
||||||
|
// frees all xml related data
|
||||||
|
xmlFreeDoc(doc);
|
||||||
|
|
||||||
|
/* Clean up everything else before quitting. */
|
||||||
|
xmlCleanupParser();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/*
|
/*
|
||||||
* 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 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,45 +112,45 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
|
||||||
|
|
||||||
const Glib::ustring XMLSerializer::get_filename_extension()
|
const Glib::ustring XMLSerializer::get_filename_extension()
|
||||||
{
|
{
|
||||||
return Glib::ustring("xsgp");
|
return Glib::ustring("xsgp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Glib::ustring XMLSerializer::get_filename_description()
|
const Glib::ustring XMLSerializer::get_filename_description()
|
||||||
{
|
{
|
||||||
return Glib::ustring("SGPEMv2 XML savefile");
|
return Glib::ustring("SGPEMv2 XML savefile");
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMLSerializer::fill_doc(xmlDocPtr doc, const History& hist)
|
void XMLSerializer::fill_doc(xmlDocPtr doc, const History& hist)
|
||||||
{
|
{
|
||||||
xmlNodePtr root_node = NULL;/* node pointers */
|
xmlNodePtr root_node = NULL;/* node pointers */
|
||||||
/*
|
/*
|
||||||
* Creates a new document, a node and set it as a root node
|
* Creates a new document, a node and set it as a root node
|
||||||
*/
|
*/
|
||||||
root_node = xmlNewNode(NULL, (const xmlChar *) "sgpem");
|
root_node = xmlNewNode(NULL, (const xmlChar *) "sgpem");
|
||||||
xmlDocSetRootElement(doc, root_node);
|
xmlDocSetRootElement(doc, root_node);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates a DTD declaration. Isn't mandatory.
|
* Creates a DTD declaration. Isn't mandatory.
|
||||||
*/
|
*/
|
||||||
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
|
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
|
||||||
|
|
||||||
XMLVisitor xvisit(root_node);
|
XMLVisitor xvisit(root_node);
|
||||||
xvisit.from_history(hist);
|
xvisit.from_history(hist);
|
||||||
/*
|
/*
|
||||||
//
|
//
|
||||||
// xmlNewChild() creates a new node, which is "attached" as child node
|
// xmlNewChild() creates a new node, which is "attached" as child node
|
||||||
// of root_node node.
|
// of root_node node.
|
||||||
//
|
//
|
||||||
xmlNodePtr resources_node = xmlNewChild(root_node, NULL, (const xmlChar *) "resources", NULL);
|
xmlNodePtr resources_node = xmlNewChild(root_node, NULL, (const xmlChar *) "resources", NULL);
|
||||||
//
|
//
|
||||||
// The same as above, but the new child node doesn't have a content
|
// The same as above, but the new child node doesn't have a content
|
||||||
//
|
//
|
||||||
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
|
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
|
||||||
|
|
||||||
fill_resources(resources_node, hist);
|
fill_resources(resources_node, hist);
|
||||||
fill_schedulables(schedulables_node, hist);
|
fill_schedulables(schedulables_node, hist);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -198,71 +198,74 @@ void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const Histor
|
||||||
void XMLSerializer::clear_history(History& hist)
|
void XMLSerializer::clear_history(History& hist)
|
||||||
{
|
{
|
||||||
|
|
||||||
const Environment& env = hist.get_last_environment();
|
const Environment& env = hist.get_last_environment();
|
||||||
|
|
||||||
const Environment::Processes& pvect = env.get_processes();
|
const Environment::Processes& pvect = env.get_processes();
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
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())
|
||||||
{
|
{
|
||||||
hist.remove((*riter).first);
|
hist.remove((*riter).first);
|
||||||
riter = rvect.begin();
|
riter = rvect.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError)
|
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Check the document is of the right kind
|
* Check the document is of the right kind
|
||||||
*/
|
*/
|
||||||
xmlNodePtr root;
|
xmlNodePtr root;
|
||||||
root = xmlDocGetRootElement(doc);
|
root = xmlDocGetRootElement(doc);
|
||||||
if (root == NULL) {
|
if (root == NULL)
|
||||||
xmlFreeDoc(doc);
|
{
|
||||||
xmlCleanupParser();
|
xmlFreeDoc(doc);
|
||||||
throw SerializerError("Reading Error: xml doc is empty.");
|
xmlCleanupParser();
|
||||||
}
|
throw SerializerError("Reading Error: xml doc is empty.");
|
||||||
|
}
|
||||||
|
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
cur = root->children;
|
cur = root->children;
|
||||||
while(cur!=NULL)
|
while (cur != NULL)
|
||||||
|
{
|
||||||
|
Glib::ustring name((const char *)cur->name);
|
||||||
|
if (name == "resources")
|
||||||
{
|
{
|
||||||
Glib::ustring name((const char *)cur->name);
|
read_resources(cur, fact);
|
||||||
if(name=="resources")
|
|
||||||
{
|
|
||||||
read_resources(cur, fact);
|
|
||||||
}
|
|
||||||
if(name=="schedulables")
|
|
||||||
{
|
|
||||||
read_schedulables(cur, fact);
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
|
if (name == "schedulables")
|
||||||
|
{
|
||||||
|
read_schedulables(cur, fact);
|
||||||
|
}
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -276,129 +279,129 @@ XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
|
||||||
|
|
||||||
void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact)
|
void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
if (node_name == "resource")
|
||||||
{
|
{
|
||||||
Glib::ustring node_name((const char *)cur->name);
|
xmlAttrPtr prop = cur->properties;
|
||||||
if(node_name=="resource")
|
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||||
|
if (par != NULL)
|
||||||
{
|
{
|
||||||
xmlAttrPtr prop = cur->properties;
|
fact.factory_method(Glib::ustring("Resource"), *par);
|
||||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
|
||||||
if(par!=NULL)
|
|
||||||
{
|
|
||||||
fact.factory_method(Glib::ustring("Resource"), *par);
|
|
||||||
}
|
|
||||||
// fact.create_resource(*par);
|
|
||||||
}
|
}
|
||||||
|
// fact.create_resource(*par);
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
if (node_name == "process")
|
||||||
{
|
{
|
||||||
Glib::ustring node_name((const char *)cur->name);
|
xmlAttrPtr prop = cur->properties;
|
||||||
if(node_name=="process")
|
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||||
|
if (par != NULL)
|
||||||
{
|
{
|
||||||
xmlAttrPtr prop = cur->properties;
|
fact.factory_method(Glib::ustring("Process"), *par);
|
||||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
|
||||||
if(par!=NULL)
|
|
||||||
{
|
|
||||||
fact.factory_method(Glib::ustring("Process"), *par);
|
|
||||||
}
|
|
||||||
// pass the "threads node"
|
|
||||||
read_threads(cur->children, fact);
|
|
||||||
}
|
}
|
||||||
|
// pass the "threads node"
|
||||||
cur = cur->next;
|
read_threads(cur->children, fact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
if (node_name == "thread")
|
||||||
{
|
{
|
||||||
Glib::ustring node_name((const char *)cur->name);
|
xmlAttrPtr prop = cur->properties;
|
||||||
if(node_name=="thread")
|
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||||
|
if (par != NULL)
|
||||||
{
|
{
|
||||||
xmlAttrPtr prop = cur->properties;
|
fact.factory_method(Glib::ustring("Thread"), *par);
|
||||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
|
||||||
if(par!=NULL)
|
|
||||||
{
|
|
||||||
fact.factory_method(Glib::ustring("Thread"), *par);
|
|
||||||
}
|
|
||||||
// pass the "requests node"
|
|
||||||
read_requests(cur->children, fact);
|
|
||||||
}
|
}
|
||||||
|
// pass the "requests node"
|
||||||
cur = cur->next;
|
read_requests(cur->children, fact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
if (node_name == "request")
|
||||||
{
|
{
|
||||||
Glib::ustring node_name((const char *)cur->name);
|
xmlAttrPtr prop = cur->properties;
|
||||||
if(node_name=="request")
|
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||||
|
if (par != NULL)
|
||||||
{
|
{
|
||||||
xmlAttrPtr prop = cur->properties;
|
fact.factory_method(Glib::ustring("Request"), *par);
|
||||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
|
||||||
if(par!=NULL)
|
|
||||||
{
|
|
||||||
fact.factory_method(Glib::ustring("Request"), *par);
|
|
||||||
}
|
|
||||||
// pass the "subrequest nodes"
|
|
||||||
read_subrequests(cur->children, fact);
|
|
||||||
}
|
}
|
||||||
|
// pass the "subrequest nodes"
|
||||||
cur = cur->next;
|
read_subrequests(cur->children, fact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
if (node_name == "subrequest")
|
||||||
{
|
{
|
||||||
Glib::ustring node_name((const char *)cur->name);
|
xmlAttrPtr prop = cur->properties;
|
||||||
if(node_name=="subrequest")
|
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||||
|
if (par != NULL)
|
||||||
{
|
{
|
||||||
xmlAttrPtr prop = cur->properties;
|
fact.factory_method(Glib::ustring("SubRequest"), *par);
|
||||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
|
||||||
if(par!=NULL)
|
|
||||||
{
|
|
||||||
fact.factory_method(Glib::ustring("SubRequest"), *par);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* comment */
|
/* comment */
|
||||||
|
|
|
@ -35,13 +35,11 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,19 +36,17 @@ 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)
|
||||||
{
|
{
|
||||||
throw SerializerError(
|
throw SerializerError(
|
||||||
_("XMLVisitor: unsupported method from_resource(const Resource& obj)")
|
_("XMLVisitor: unsupported method from_resource(const Resource& obj)")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,9 +98,9 @@ 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());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -42,80 +42,80 @@ ConcreteEnvironment::ConcreteEnvironment()
|
||||||
|
|
||||||
|
|
||||||
ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
|
ConcreteEnvironment::ConcreteEnvironment(const ConcreteEnvironment& ce) :
|
||||||
Environment(ce), _resources(ce._resources), _processes(), _sched_queue(), _sreq_queues(ce._sreq_queues)
|
Environment(ce), _resources(ce._resources), _processes(), _sched_queue(), _sreq_queues(ce._sreq_queues)
|
||||||
{
|
{
|
||||||
// The ReadyQueue won't be copied. Pointers to objects contained into
|
// The ReadyQueue won't be copied. Pointers to objects contained into
|
||||||
// the ready queue _will_ have changed in the new one. The ready queue
|
// the ready queue _will_ have changed in the new one. The ready queue
|
||||||
// needs to be reset: it is Scheduler that builds it again from time to time.
|
// needs to be reset: it is Scheduler that builds it again from time to time.
|
||||||
|
|
||||||
// Update resource pointers in a way you won't like :-)
|
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
// DynamicProcess object need to be copied.
|
// DynamicProcess object need to be copied.
|
||||||
// The deep copy is guaranteed by the DynamicProcess copy constructor
|
// The deep copy is guaranteed by the DynamicProcess copy constructor
|
||||||
{
|
{
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update the subrequest queues.
|
// Update the subrequest queues.
|
||||||
|
|
||||||
// for each subrequest
|
// for each subrequest
|
||||||
typedef Processes::const_iterator it1_t;
|
typedef Processes::const_iterator it1_t;
|
||||||
|
|
||||||
typedef std::vector<Thread*> v2_t;
|
typedef std::vector<Thread*> v2_t;
|
||||||
typedef v2_t::const_iterator it2_t;
|
typedef v2_t::const_iterator it2_t;
|
||||||
|
|
||||||
typedef std::vector<Request*> v3_t;
|
typedef std::vector<Request*> v3_t;
|
||||||
typedef v3_t::const_iterator it3_t;
|
typedef v3_t::const_iterator it3_t;
|
||||||
|
|
||||||
typedef std::vector<SubRequest*> v4_t;
|
typedef std::vector<SubRequest*> v4_t;
|
||||||
typedef v4_t::const_iterator it4_t;
|
typedef v4_t::const_iterator it4_t;
|
||||||
|
|
||||||
typedef SubRequestQueue::iterator it5_t;
|
typedef SubRequestQueue::iterator it5_t;
|
||||||
|
|
||||||
for(it1_t it1 = _processes.begin(); it1 != _processes.end(); it1++)
|
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);
|
||||||
if (&_old.get_core() == &_new.get_core())
|
if (&_old.get_core() == &_new.get_core())
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
*it5 = *it4;
|
*it5 = *it4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -195,14 +195,14 @@ ConcreteEnvironment::get_sorted_queue()
|
||||||
|
|
||||||
ConcreteEnvironment::~ConcreteEnvironment()
|
ConcreteEnvironment::~ConcreteEnvironment()
|
||||||
{
|
{
|
||||||
// This call will invoke the DynamicProcess virtual destructor
|
// This call will invoke the DynamicProcess virtual destructor
|
||||||
// Which will delete on cascade all DynamicThreads and so on.
|
// Which will delete on cascade all DynamicThreads and so on.
|
||||||
for_each(_processes.begin(), _processes.end(),
|
for_each(_processes.begin(), _processes.end(),
|
||||||
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)
|
||||||
// After that, the destructor of _processes is invoked (only invalid pointers)
|
// After that, the destructor of _processes is invoked (only invalid pointers)
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace sgpem
|
||||||
///
|
///
|
||||||
/// \return a constant set of snapshots of processes
|
/// \return a constant set of snapshots of processes
|
||||||
virtual const Processes&
|
virtual const Processes&
|
||||||
get_processes() const;
|
get_processes() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ namespace sgpem
|
||||||
/// \return a set of snapshots of processes
|
/// \return a set of snapshots of processes
|
||||||
/// \see get_processes()
|
/// \see get_processes()
|
||||||
virtual Processes&
|
virtual Processes&
|
||||||
get_processes();
|
get_processes();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ namespace sgpem
|
||||||
/// \return a indexed constant set of snapshot of resources.
|
/// \return a indexed constant set of snapshot of resources.
|
||||||
/// \see DynamicSybrequest::get_resource()
|
/// \see DynamicSybrequest::get_resource()
|
||||||
virtual const Resources&
|
virtual const Resources&
|
||||||
get_resources() const;
|
get_resources() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace sgpem
|
||||||
/// \return an indexed set of snapshots of resources
|
/// \return an indexed set of snapshots of resources
|
||||||
/// \see get_resources()
|
/// \see get_resources()
|
||||||
virtual Resources&
|
virtual Resources&
|
||||||
get_resources();
|
get_resources();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,10 +124,10 @@ namespace sgpem
|
||||||
/// \param resource The resource the requests are for
|
/// \param resource The resource the requests are for
|
||||||
/// \return The current ready requests queue.
|
/// \return The current ready requests queue.
|
||||||
virtual const SubRequestQueue&
|
virtual const SubRequestQueue&
|
||||||
get_request_queue(resource_key_t resource_key) const;
|
get_request_queue(resource_key_t resource_key) const;
|
||||||
|
|
||||||
SubRequestQueue&
|
SubRequestQueue&
|
||||||
get_request_queue(resource_key_t resource_key);
|
get_request_queue(resource_key_t resource_key);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ namespace sgpem
|
||||||
///
|
///
|
||||||
/// \return the current ready queue (constant).
|
/// \return the current ready queue (constant).
|
||||||
virtual const ReadyQueue&
|
virtual const ReadyQueue&
|
||||||
get_sorted_queue() const;
|
get_sorted_queue() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,14 +159,14 @@ namespace sgpem
|
||||||
/// \return the current ready queue.
|
/// \return the current ready queue.
|
||||||
/// \see get_sorted_queue()
|
/// \see get_sorted_queue()
|
||||||
virtual ReadyQueue&
|
virtual ReadyQueue&
|
||||||
get_sorted_queue();
|
get_sorted_queue();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// \brief The standard virtual destructor.
|
/// \brief The standard virtual destructor.
|
||||||
/// The standard virtual destructor.
|
/// The standard virtual destructor.
|
||||||
virtual
|
virtual
|
||||||
~ConcreteEnvironment();
|
~ConcreteEnvironment();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -175,11 +175,11 @@ namespace sgpem
|
||||||
/// Actually contains only DynamicResource objects.
|
/// Actually contains only DynamicResource objects.
|
||||||
// resources come before processes because of
|
// resources come before processes because of
|
||||||
// destruction order. See destructor implementation
|
// destruction order. See destructor implementation
|
||||||
Resources _resources;
|
Resources _resources;
|
||||||
|
|
||||||
/// \brief The container of all Process objecs.
|
/// \brief The container of all Process objecs.
|
||||||
/// Actually contains only DynamicProcess objects.
|
/// Actually contains only DynamicProcess objects.
|
||||||
Processes _processes;
|
Processes _processes;
|
||||||
|
|
||||||
/// \brief The queue of the ready schedulables
|
/// \brief The queue of the ready schedulables
|
||||||
/// Does not contain the running process.
|
/// Does not contain the running process.
|
||||||
|
@ -187,7 +187,8 @@ namespace sgpem
|
||||||
|
|
||||||
SubRequestQueues _sreq_queues;
|
SubRequestQueues _sreq_queues;
|
||||||
|
|
||||||
}; //~ class ConcreteEnvironment
|
}
|
||||||
|
; //~ class ConcreteEnvironment
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
|
|
@ -54,372 +54,372 @@ using memory::deletor;
|
||||||
template<typename T>
|
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);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
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;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
ConcreteHistory::ConcreteHistory()
|
ConcreteHistory::ConcreteHistory()
|
||||||
: History(), _snapshots()
|
: History(), _snapshots()
|
||||||
{
|
{
|
||||||
_snapshots.push_back(new ConcreteEnvironment());
|
_snapshots.push_back(new ConcreteEnvironment());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConcreteHistory::~ConcreteHistory()
|
ConcreteHistory::~ConcreteHistory()
|
||||||
{
|
{
|
||||||
for_each(_snapshots.begin(), _snapshots.end(),
|
for_each(_snapshots.begin(), _snapshots.end(),
|
||||||
deletor<ConcreteEnvironment>());
|
deletor<ConcreteEnvironment>());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConcreteHistory::ConcreteHistory(const ConcreteHistory& h) :
|
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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
|
ConcreteHistory::append_new_environment(ConcreteEnvironment* environment)
|
||||||
{
|
{
|
||||||
_snapshots.push_back(environment);
|
_snapshots.push_back(environment);
|
||||||
notify_change();
|
notify_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConcreteHistory::size_t
|
ConcreteHistory::size_t
|
||||||
ConcreteHistory::get_size() const
|
ConcreteHistory::get_size() const
|
||||||
{
|
{
|
||||||
return _snapshots.size();
|
return _snapshots.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const ConcreteEnvironment&
|
const ConcreteEnvironment&
|
||||||
ConcreteHistory::get_last_environment() const
|
ConcreteHistory::get_last_environment() const
|
||||||
{
|
{
|
||||||
// Should always be true:
|
// Should always be true:
|
||||||
assert(_snapshots.size() > 0);
|
assert(_snapshots.size() > 0);
|
||||||
return *_snapshots.back();
|
return *_snapshots.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::remove(resource_key_t resource_key)
|
ConcreteHistory::remove(resource_key_t resource_key)
|
||||||
{
|
{
|
||||||
// Pay attention that initial isn't deleted by reset()
|
// Pay attention that initial isn't deleted by reset()
|
||||||
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);
|
||||||
|
|
||||||
delete found->second;
|
delete found->second;
|
||||||
resources.erase(found);
|
resources.erase(found);
|
||||||
|
|
||||||
// Delete the queue associated with the resource.
|
// Delete the queue associated with the resource.
|
||||||
ConcreteEnvironment::SubRequestQueues& srq = initial.get_subrequest_queues();
|
ConcreteEnvironment::SubRequestQueues& srq = initial.get_subrequest_queues();
|
||||||
ConcreteEnvironment::SubRequestQueues::iterator qfound = srq.find(resource_key);
|
ConcreteEnvironment::SubRequestQueues::iterator qfound = srq.find(resource_key);
|
||||||
// There is always one!
|
// There is always one!
|
||||||
assert(qfound != srq.end());
|
assert(qfound != srq.end());
|
||||||
srq.erase(qfound);
|
srq.erase(qfound);
|
||||||
|
|
||||||
|
|
||||||
// Now search and erase subrequest that had a ref to the
|
// Now search and erase subrequest that had a ref to the
|
||||||
// removed resource
|
// removed resource
|
||||||
|
|
||||||
typedef std::vector<DynamicThread*> Threads;
|
typedef std::vector<DynamicThread*> Threads;
|
||||||
typedef std::vector<DynamicRequest*> Requests;
|
typedef std::vector<DynamicRequest*> Requests;
|
||||||
typedef std::vector<DynamicSubRequest*> SubRequests;
|
typedef std::vector<DynamicSubRequest*> SubRequests;
|
||||||
|
|
||||||
// Listening to "The Thing That Should Not Be"...
|
// Listening to "The Thing That Should Not Be"...
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
it4++;
|
it4++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //~ end monstrous construct, "The Thing That Should Not Be"
|
} //~ end monstrous construct, "The Thing That Should Not Be"
|
||||||
// Chtulhu ftaghn. There are worse things in life. Mother-in-laws,
|
// Chtulhu ftaghn. There are worse things in life. Mother-in-laws,
|
||||||
// for example. Or hangovers. Or being read poetry by a Vogon.
|
// for example. Or hangovers. Or being read poetry by a Vogon.
|
||||||
// Although the above construct really rates between the first tens.
|
// Although the above construct really rates between the first tens.
|
||||||
|
|
||||||
notify_change();
|
notify_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::remove(Process& process)
|
ConcreteHistory::remove(Process& process)
|
||||||
{
|
{
|
||||||
// Pay attention that initial isn't deleted by reset()
|
// Pay attention that initial isn't deleted by reset()
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::remove(Thread& thread)
|
ConcreteHistory::remove(Thread& thread)
|
||||||
{
|
{
|
||||||
DynamicThread& dyn_thr = dynamic_cast<DynamicThread&>(thread);
|
DynamicThread& dyn_thr = dynamic_cast<DynamicThread&>(thread);
|
||||||
|
|
||||||
// Pay attention that initial isn't deleted by reset()
|
// Pay attention that initial isn't deleted by reset()
|
||||||
ConcreteEnvironment& initial = *_snapshots.front();
|
ConcreteEnvironment& initial = *_snapshots.front();
|
||||||
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::remove(Request& request)
|
ConcreteHistory::remove(Request& request)
|
||||||
{
|
{
|
||||||
DynamicRequest& dyn_req = dynamic_cast<DynamicRequest&>(request);
|
DynamicRequest& dyn_req = dynamic_cast<DynamicRequest&>(request);
|
||||||
DynamicThread& dyn_thr = dyn_req.get_thread();
|
DynamicThread& dyn_thr = dyn_req.get_thread();
|
||||||
DynamicProcess& dyn_proc = dyn_thr.get_process();
|
DynamicProcess& dyn_proc = dyn_thr.get_process();
|
||||||
|
|
||||||
// Pay attention that initial isn't deleted by reset()
|
// Pay attention that initial isn't deleted by reset()
|
||||||
ConcreteEnvironment& initial = *_snapshots.front();
|
ConcreteEnvironment& initial = *_snapshots.front();
|
||||||
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
||||||
|
|
||||||
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
|
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
|
||||||
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::remove(SubRequest& subrequest)
|
ConcreteHistory::remove(SubRequest& subrequest)
|
||||||
{
|
{
|
||||||
// this function makes one relevant assumption:
|
// this function makes one relevant assumption:
|
||||||
// the initial environment does contain empty request queues only.
|
// the initial environment does contain empty request queues only.
|
||||||
|
|
||||||
DynamicSubRequest& dyn_sub = dynamic_cast<DynamicSubRequest&>(subrequest);
|
DynamicSubRequest& dyn_sub = dynamic_cast<DynamicSubRequest&>(subrequest);
|
||||||
DynamicRequest& dyn_req = dyn_sub.get_request();
|
DynamicRequest& dyn_req = dyn_sub.get_request();
|
||||||
DynamicThread& dyn_thr = dyn_req.get_thread();
|
DynamicThread& dyn_thr = dyn_req.get_thread();
|
||||||
DynamicProcess& dyn_proc = dyn_thr.get_process();
|
DynamicProcess& dyn_proc = dyn_thr.get_process();
|
||||||
|
|
||||||
// Pay attention that initial isn't deleted by reset()
|
// Pay attention that initial isn't deleted by reset()
|
||||||
ConcreteEnvironment& initial = *_snapshots.front();
|
ConcreteEnvironment& initial = *_snapshots.front();
|
||||||
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
ConcreteEnvironment::Processes& processes = initial.get_processes();
|
||||||
|
|
||||||
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
|
Process* proc_ref = deep_find<Process>(processes, dyn_proc);
|
||||||
DynamicProcess* dyn_proc_ref = dynamic_cast<DynamicProcess*>(proc_ref);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ConcreteHistory::ResourcePair
|
ConcreteHistory::ResourcePair
|
||||||
ConcreteHistory::add_resource(const Glib::ustring& name,
|
ConcreteHistory::add_resource(const Glib::ustring& name,
|
||||||
bool preemptable,
|
bool preemptable,
|
||||||
size_t places,
|
size_t places,
|
||||||
size_t availability)
|
size_t availability)
|
||||||
{
|
{
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
typedef ConcreteEnvironment::Resources Resources;
|
typedef ConcreteEnvironment::Resources Resources;
|
||||||
typedef ConcreteEnvironment::SubRequestQueue SubRequestQueue;
|
typedef ConcreteEnvironment::SubRequestQueue SubRequestQueue;
|
||||||
// And preemptable and availability?? FIXME!
|
// And preemptable and availability?? FIXME!
|
||||||
|
|
||||||
StaticResource* core = new StaticResource(name, places);
|
StaticResource* core = new StaticResource(name, places);
|
||||||
DynamicResource* resource = new DynamicResource(core);
|
DynamicResource* resource = new DynamicResource(core);
|
||||||
|
|
||||||
ConcreteEnvironment::Resources& resources = _snapshots.front()->get_resources();
|
ConcreteEnvironment::Resources& resources = _snapshots.front()->get_resources();
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
||||||
return *temp;
|
return *temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicProcess&
|
DynamicProcess&
|
||||||
ConcreteHistory::add_process(const Glib::ustring& name,
|
ConcreteHistory::add_process(const Glib::ustring& name,
|
||||||
time_t arrival_time,
|
time_t arrival_time,
|
||||||
prio_t base_priority)
|
prio_t base_priority)
|
||||||
{
|
{
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
StaticProcess* core = new StaticProcess(name, arrival_time, base_priority);
|
StaticProcess* core = new StaticProcess(name, arrival_time, base_priority);
|
||||||
DynamicProcess* proc = new DynamicProcess(core);
|
DynamicProcess* proc = new DynamicProcess(core);
|
||||||
|
|
||||||
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
|
ConcreteEnvironment::Processes& processes = _snapshots.front()->get_processes();
|
||||||
processes.push_back(proc);
|
processes.push_back(proc);
|
||||||
|
|
||||||
notify_change();
|
notify_change();
|
||||||
return *proc;
|
return *proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicThread&
|
DynamicThread&
|
||||||
ConcreteHistory::add_thread(const Glib::ustring& name,
|
ConcreteHistory::add_thread(const Glib::ustring& name,
|
||||||
Process& parent,
|
Process& parent,
|
||||||
time_t cpu_time,
|
time_t cpu_time,
|
||||||
time_t arrival_time,
|
time_t arrival_time,
|
||||||
prio_t base_priority)
|
prio_t base_priority)
|
||||||
{
|
{
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
// Holy cow! *THIS* is ugly!!!!
|
// Holy cow! *THIS* is ugly!!!!
|
||||||
DynamicProcess& parent_process = dynamic_cast<DynamicProcess&>(parent);
|
DynamicProcess& parent_process = dynamic_cast<DynamicProcess&>(parent);
|
||||||
StaticProcess& parent_core = parent_process.get_core();
|
StaticProcess& parent_core = parent_process.get_core();
|
||||||
StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority);
|
StaticThread* core = new StaticThread(name, parent_core, cpu_time, arrival_time, base_priority);
|
||||||
DynamicThread* thread = new DynamicThread(core, &parent_process);
|
DynamicThread* thread = new DynamicThread(core, &parent_process);
|
||||||
|
|
||||||
notify_change();
|
notify_change();
|
||||||
return *thread;
|
return *thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicRequest&
|
DynamicRequest&
|
||||||
ConcreteHistory::add_request(Thread& owner,
|
ConcreteHistory::add_request(Thread& owner,
|
||||||
time_t instant)
|
time_t instant)
|
||||||
{
|
{
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
DynamicThread& dyn_owner = dynamic_cast<DynamicThread&>(owner);
|
DynamicThread& dyn_owner = dynamic_cast<DynamicThread&>(owner);
|
||||||
StaticThread& owner_core = dyn_owner.get_core();
|
StaticThread& owner_core = dyn_owner.get_core();
|
||||||
|
|
||||||
StaticRequest* core = new StaticRequest(&owner_core, instant);
|
StaticRequest* core = new StaticRequest(&owner_core, instant);
|
||||||
DynamicRequest* req = new DynamicRequest(core, &dyn_owner);
|
DynamicRequest* req = new DynamicRequest(core, &dyn_owner);
|
||||||
|
|
||||||
dyn_owner.get_requests().push_back(req);
|
dyn_owner.get_requests().push_back(req);
|
||||||
|
|
||||||
notify_change();
|
notify_change();
|
||||||
return *req;
|
return *req;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicSubRequest&
|
DynamicSubRequest&
|
||||||
ConcreteHistory::add_subrequest(Request& request,
|
ConcreteHistory::add_subrequest(Request& request,
|
||||||
resource_key_t resource_key,
|
resource_key_t resource_key,
|
||||||
time_t duration)
|
time_t duration)
|
||||||
{
|
{
|
||||||
reset(false);
|
reset(false);
|
||||||
|
|
||||||
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
|
DynamicRequest& dyn_request = dynamic_cast<DynamicRequest&>(request);
|
||||||
|
|
||||||
StaticSubRequest* core = new StaticSubRequest(resource_key, duration);
|
StaticSubRequest* core = new StaticSubRequest(resource_key, duration);
|
||||||
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
|
DynamicSubRequest* subreq = new DynamicSubRequest(core, &dyn_request);
|
||||||
|
|
||||||
dyn_request.get_subrequests().push_back(subreq);
|
dyn_request.get_subrequests().push_back(subreq);
|
||||||
|
|
||||||
notify_change();
|
notify_change();
|
||||||
return *subreq;
|
return *subreq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ConcreteHistory::reset(bool notify)
|
ConcreteHistory::reset(bool notify)
|
||||||
{
|
{
|
||||||
assert(_snapshots.size() > 0);
|
assert(_snapshots.size() > 0);
|
||||||
Snapshots::iterator it = _snapshots.begin();
|
Snapshots::iterator it = _snapshots.begin();
|
||||||
it++; // Skip first environment that we saved
|
it++; // Skip first environment that we saved
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,53 +49,54 @@ namespace sgpem
|
||||||
ConcreteHistory(const ConcreteHistory&);
|
ConcreteHistory(const ConcreteHistory&);
|
||||||
virtual ~ConcreteHistory();
|
virtual ~ConcreteHistory();
|
||||||
|
|
||||||
virtual void append_new_environment(ConcreteEnvironment* environment);
|
virtual void append_new_environment(ConcreteEnvironment* environment);
|
||||||
virtual size_t get_size() const;
|
virtual size_t get_size() const;
|
||||||
virtual const ConcreteEnvironment& get_last_environment() const;
|
virtual const ConcreteEnvironment& get_last_environment() const;
|
||||||
virtual const ConcreteEnvironment& get_environment_at(position index) const throw(std::out_of_range);
|
virtual const ConcreteEnvironment& get_environment_at(position index) const throw(std::out_of_range);
|
||||||
|
|
||||||
virtual void remove(resource_key_t resource_key);
|
virtual void remove(resource_key_t resource_key);
|
||||||
virtual void remove(Process& process);
|
virtual void remove(Process& process);
|
||||||
virtual void remove(Thread& thread);
|
virtual void remove(Thread& thread);
|
||||||
virtual void remove(Request& request);
|
virtual void remove(Request& request);
|
||||||
virtual void remove(SubRequest& subrequest);
|
virtual void remove(SubRequest& subrequest);
|
||||||
|
|
||||||
|
|
||||||
virtual ResourcePair add_resource(const Glib::ustring& name,
|
virtual ResourcePair add_resource(const Glib::ustring& name,
|
||||||
bool preemptable = false,
|
bool preemptable = false,
|
||||||
size_t places = 1,
|
size_t places = 1,
|
||||||
size_t availability = 0);
|
size_t availability = 0);
|
||||||
|
|
||||||
virtual DynamicProcess& add_process(const Glib::ustring& name,
|
virtual DynamicProcess& add_process(const Glib::ustring& name,
|
||||||
time_t arrival_time,
|
time_t arrival_time,
|
||||||
prio_t base_priority = 0);
|
prio_t base_priority = 0);
|
||||||
|
|
||||||
virtual DynamicThread& add_thread(const Glib::ustring& name,
|
virtual DynamicThread& add_thread(const Glib::ustring& name,
|
||||||
Process& parent,
|
Process& parent,
|
||||||
time_t cpu_time,
|
time_t cpu_time,
|
||||||
time_t arrival_time = 0,
|
time_t arrival_time = 0,
|
||||||
prio_t base_priority = 0);
|
prio_t base_priority = 0);
|
||||||
|
|
||||||
virtual DynamicRequest& add_request(Thread& owner,
|
virtual DynamicRequest& add_request(Thread& owner,
|
||||||
time_t instant);
|
time_t instant);
|
||||||
|
|
||||||
virtual DynamicSubRequest& add_subrequest(Request& request,
|
virtual DynamicSubRequest& add_subrequest(Request& request,
|
||||||
resource_key_t resource_key,
|
resource_key_t resource_key,
|
||||||
time_t duration);
|
time_t duration);
|
||||||
|
|
||||||
virtual void reset(bool notify = true);
|
virtual void reset(bool notify = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::vector<ConcreteEnvironment*> Snapshots;
|
typedef std::vector<ConcreteEnvironment*> Snapshots;
|
||||||
Snapshots _snapshots;
|
Snapshots _snapshots;
|
||||||
|
|
||||||
virtual void notify_change();
|
virtual void notify_change();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// 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
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ using namespace memory;
|
||||||
using Glib::usleep;
|
using Glib::usleep;
|
||||||
|
|
||||||
ConcreteSimulation::ConcreteSimulation() :
|
ConcreteSimulation::ConcreteSimulation() :
|
||||||
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
|
_state(state_stopped), _mode(true), _timer_interval(1000), _policy(NULL)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -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,57 +88,57 @@ 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
//******* CONTINUOUS TIME
|
//******* CONTINUOUS TIME
|
||||||
if (_mode)
|
if (_mode)
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
//step forward
|
||||||
{
|
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
||||||
//step forward
|
if (!yet_to_finish) stop();
|
||||||
bool yet_to_finish = Scheduler::get_instance().step_forward(_history, *get_policy());
|
|
||||||
if(!yet_to_finish) stop();
|
|
||||||
|
|
||||||
//sleep
|
//sleep
|
||||||
Glib::usleep(_timer_interval*1000);
|
Glib::usleep(_timer_interval*1000);
|
||||||
}
|
|
||||||
catch(UserInterruptException e)
|
|
||||||
{
|
|
||||||
stop();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check the state
|
|
||||||
if (_state == state_stopped || _state == state_paused)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
while(true);
|
catch (UserInterruptException e)
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check the state
|
||||||
|
if (_state == state_stopped || _state == state_paused)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
//******* STEP by STEP
|
//******* STEP by STEP
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
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();
|
|
||||||
}
|
|
||||||
catch(UserInterruptException e)
|
|
||||||
{
|
|
||||||
stop();
|
stop();
|
||||||
throw;
|
}
|
||||||
}
|
catch (UserInterruptException e)
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,23 +119,23 @@ 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();
|
||||||
_active_policies.erase(removable);
|
_active_policies.erase(removable);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
act_it++;
|
act_it++;
|
||||||
}
|
}
|
||||||
} //~ for(avail_it)
|
} //~ for(avail_it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,27 +33,27 @@ using namespace sgpem;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
DynamicProcess::DynamicProcess(StaticProcess* core) :
|
DynamicProcess::DynamicProcess(StaticProcess* core) :
|
||||||
DynamicSchedulable(), _core(core)
|
DynamicSchedulable(), _core(core)
|
||||||
{
|
{
|
||||||
assert(core != NULL);
|
assert(core != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicProcess::DynamicProcess(const DynamicProcess &other) :
|
DynamicProcess::DynamicProcess(const DynamicProcess &other) :
|
||||||
Schedulable(), DynamicSchedulable(other), Process(),
|
Schedulable(), DynamicSchedulable(other), Process(),
|
||||||
_core(other._core)
|
_core(other._core)
|
||||||
{
|
{
|
||||||
typedef vector<DynamicThread*>::const_iterator ThreadIt;
|
typedef vector<DynamicThread*>::const_iterator ThreadIt;
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicProcess::~DynamicProcess()
|
DynamicProcess::~DynamicProcess()
|
||||||
{
|
{
|
||||||
for_each(_dynamic_threads.begin(), _dynamic_threads.end(),
|
for_each(_dynamic_threads.begin(), _dynamic_threads.end(),
|
||||||
memory::deletor<DynamicThread>());
|
memory::deletor<DynamicThread>());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Thread*>
|
std::vector<Thread*>
|
||||||
|
@ -71,65 +71,65 @@ DynamicProcess::get_threads() const
|
||||||
Schedulable::state
|
Schedulable::state
|
||||||
DynamicProcess::get_state() const
|
DynamicProcess::get_state() const
|
||||||
{
|
{
|
||||||
int total = _dynamic_threads.size();
|
int total = _dynamic_threads.size();
|
||||||
int running = 0;
|
int running = 0;
|
||||||
int ready = 0;
|
int ready = 0;
|
||||||
int blocked = 0;
|
int blocked = 0;
|
||||||
int terminated = 0;
|
int terminated = 0;
|
||||||
int future = 0;
|
int future = 0;
|
||||||
|
|
||||||
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++;
|
||||||
if ((**it).get_state() == state_blocked) blocked++;
|
if ((**it).get_state() == state_blocked) blocked++;
|
||||||
if ((**it).get_state() == state_terminated) terminated++;
|
if ((**it).get_state() == state_terminated) terminated++;
|
||||||
if ((**it).get_state() == state_future)
|
if ((**it).get_state() == state_future)
|
||||||
{
|
{
|
||||||
unsigned int arrival = (**it).get_arrival_time();
|
unsigned int arrival = (**it).get_arrival_time();
|
||||||
// if this is the first future occurrence, record its arrival;
|
// if this is the first future occurrence, record its arrival;
|
||||||
// else record its arrival if and only if it is smaller then the recorded one
|
// else record its arrival if and only if it is smaller then the recorded one
|
||||||
if (future == 0)
|
if (future == 0)
|
||||||
closest = arrival;
|
closest = arrival;
|
||||||
else
|
else
|
||||||
closest = (closest < arrival) ? closest : arrival;
|
closest = (closest < arrival) ? closest : arrival;
|
||||||
future++;
|
future++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(total > 0);
|
assert(total > 0);
|
||||||
assert(running == 1 || running == 0);
|
assert(running == 1 || running == 0);
|
||||||
assert(running + ready + blocked + terminated + future == total);
|
assert(running + ready + blocked + terminated + future == total);
|
||||||
|
|
||||||
if (running > 0)
|
if (running > 0)
|
||||||
return state_running;
|
return state_running;
|
||||||
if (ready > 0) // running == 0
|
if (ready > 0) // running == 0
|
||||||
return state_ready;
|
return state_ready;
|
||||||
if (blocked > 0) // running == 0 && ready == 0
|
if (blocked > 0) // running == 0 && ready == 0
|
||||||
return state_blocked;
|
return state_blocked;
|
||||||
// Now check if a "hole" happens: if all threads are terminated
|
// Now check if a "hole" happens: if all threads are terminated
|
||||||
// or blocked the next
|
// or blocked the next
|
||||||
// thread to start, e.g. the one with the least arrival_time, has
|
// thread to start, e.g. the one with the least arrival_time, has
|
||||||
// start time greater than the current process elapsed time, then
|
// start time greater than the current process elapsed time, then
|
||||||
// pass from state_future to state_terminated:
|
// pass from state_future to state_terminated:
|
||||||
if (closest > get_elapsed_time())
|
if (closest > get_elapsed_time())
|
||||||
return state_terminated;
|
return state_terminated;
|
||||||
if (terminated > 0) // running == 0 && ready == 0 && blocked == 0
|
if (terminated > 0) // running == 0 && ready == 0 && blocked == 0
|
||||||
return state_terminated;
|
return state_terminated;
|
||||||
if (future > 0) // running == 0 && ready == 0 && blocked == 0 && terminated == 0
|
if (future > 0) // running == 0 && ready == 0 && blocked == 0 && terminated == 0
|
||||||
return state_future;
|
|
||||||
|
|
||||||
// I'm not sure if we can get here (maybe if there are no threads?),
|
|
||||||
// but I don't like this compiler warning: 'control reaches end of non-void function'
|
|
||||||
return state_future;
|
return state_future;
|
||||||
|
|
||||||
// Since premature optimization is the root of all evil, and the
|
// I'm not sure if we can get here (maybe if there are no threads?),
|
||||||
// following code was very fast but also very wrong, the coder
|
// but I don't like this compiler warning: 'control reaches end of non-void function'
|
||||||
// will be punished by allowing her to code in C++ just after
|
return state_future;
|
||||||
// having passed "Algoritmi 3" exam with full marks.
|
|
||||||
|
// Since premature optimization is the root of all evil, and the
|
||||||
|
// following code was very fast but also very wrong, the coder
|
||||||
|
// will be punished by allowing her to code in C++ just after
|
||||||
|
// having passed "Algoritmi 3" exam with full marks.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
typedef vector<DynamicThread*>::const_iterator ThreadIt;
|
typedef vector<DynamicThread*>::const_iterator ThreadIt;
|
||||||
|
@ -189,8 +189,8 @@ DynamicProcess::get_state() const
|
||||||
}
|
}
|
||||||
} //~ "for" iterating over threads
|
} //~ "for" iterating over threads
|
||||||
|
|
||||||
// reused hole checking system
|
// reused hole checking system
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,32 +204,32 @@ DynamicProcess::serialize(SerializeVisitor& translator) const
|
||||||
StaticProcess&
|
StaticProcess&
|
||||||
DynamicProcess::get_core()
|
DynamicProcess::get_core()
|
||||||
{
|
{
|
||||||
return *_core;
|
return *_core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const StaticProcess&
|
const StaticProcess&
|
||||||
DynamicProcess::get_core() const
|
DynamicProcess::get_core() const
|
||||||
{
|
{
|
||||||
return *_core;
|
return *_core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<DynamicThread*>&
|
std::vector<DynamicThread*>&
|
||||||
DynamicProcess::get_dynamic_threads()
|
DynamicProcess::get_dynamic_threads()
|
||||||
{
|
{
|
||||||
return _dynamic_threads;
|
return _dynamic_threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
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();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,13 +237,13 @@ 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,13 +251,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
DynamicProcess(StaticProcess* core);
|
DynamicProcess(StaticProcess* core);
|
||||||
DynamicProcess(const DynamicProcess &other);
|
DynamicProcess(const DynamicProcess &other);
|
||||||
virtual ~DynamicProcess();
|
virtual ~DynamicProcess();
|
||||||
|
|
||||||
std::vector<Thread*> get_threads();
|
std::vector<Thread*> get_threads();
|
||||||
std::vector<const Thread*> get_threads() const;
|
std::vector<const Thread*> get_threads() const;
|
||||||
|
@ -61,8 +61,8 @@ namespace sgpem
|
||||||
virtual StaticProcess& get_core();
|
virtual StaticProcess& get_core();
|
||||||
virtual const StaticProcess& get_core() const;
|
virtual const StaticProcess& get_core() const;
|
||||||
|
|
||||||
// Does also the job of "add_thread" and "remove_thread"
|
// Does also the job of "add_thread" and "remove_thread"
|
||||||
std::vector<DynamicThread*>& get_dynamic_threads();
|
std::vector<DynamicThread*>& get_dynamic_threads();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
memory::smart_ptr<StaticProcess> _core;
|
memory::smart_ptr<StaticProcess> _core;
|
||||||
|
|
|
@ -47,7 +47,7 @@ DynamicRequest::DynamicRequest(StaticRequest *core,
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner) :
|
DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner) :
|
||||||
_static_request(other._static_request), _dynamic_thread(owner)
|
_static_request(other._static_request), _dynamic_thread(owner)
|
||||||
{
|
{
|
||||||
typedef vector<DynamicSubRequest*> SubReqVec;
|
typedef vector<DynamicSubRequest*> SubReqVec;
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -70,15 +70,15 @@ DynamicRequest::DynamicRequest(const DynamicRequest& other, DynamicThread* owner
|
||||||
|
|
||||||
DynamicRequest::~DynamicRequest()
|
DynamicRequest::~DynamicRequest()
|
||||||
{
|
{
|
||||||
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(),
|
for_each(_dynamic_subrequests.begin(), _dynamic_subrequests.end(),
|
||||||
memory::deletor<DynamicSubRequest>());
|
memory::deletor<DynamicSubRequest>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DynamicRequest::operator==(const Request& op2) const
|
DynamicRequest::operator==(const Request& op2) const
|
||||||
{
|
{
|
||||||
assert(dynamic_cast<const DynamicRequest*>(&op2) != NULL);
|
assert(dynamic_cast<const DynamicRequest*>(&op2) != NULL);
|
||||||
return _static_request == dynamic_cast<const DynamicRequest&>(op2)._static_request;
|
return _static_request == dynamic_cast<const DynamicRequest&>(op2)._static_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,42 +112,42 @@ DynamicRequest::get_instant() const
|
||||||
Request::state
|
Request::state
|
||||||
DynamicRequest::get_state() const
|
DynamicRequest::get_state() const
|
||||||
{
|
{
|
||||||
typedef std::vector<DynamicSubRequest*> SubReqs;
|
typedef std::vector<DynamicSubRequest*> SubReqs;
|
||||||
|
|
||||||
state result = state_future;
|
state result = state_future;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// Only for debug:
|
// Only for debug:
|
||||||
bool at_least_once = false;
|
bool at_least_once = false;
|
||||||
#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;
|
||||||
case state_unallocable:
|
case state_unallocable:
|
||||||
return state_unallocable;
|
return state_unallocable;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// We want to be sure that all subrequests
|
// We want to be sure that all subrequests
|
||||||
// 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
|
||||||
|
|
||||||
result = cur.get_state();
|
result = cur.get_state();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,12 +161,12 @@ DynamicRequest::serialize(SerializeVisitor& translator) const
|
||||||
StaticRequest&
|
StaticRequest&
|
||||||
DynamicRequest::get_core()
|
DynamicRequest::get_core()
|
||||||
{
|
{
|
||||||
return *_static_request;
|
return *_static_request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const StaticRequest&
|
const StaticRequest&
|
||||||
DynamicRequest::get_core() const
|
DynamicRequest::get_core() const
|
||||||
{
|
{
|
||||||
return *_static_request;
|
return *_static_request;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,11 +43,11 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
DynamicRequest(StaticRequest *core, DynamicThread* owner);
|
DynamicRequest(StaticRequest *core, DynamicThread* owner);
|
||||||
DynamicRequest(const DynamicRequest& other, DynamicThread* owner);
|
DynamicRequest(const DynamicRequest& other, DynamicThread* owner);
|
||||||
~DynamicRequest();
|
~DynamicRequest();
|
||||||
|
|
||||||
virtual bool operator==(const Request& op2) const;
|
virtual bool operator==(const Request& op2) const;
|
||||||
|
|
||||||
virtual std::vector<SubRequest*> get_subrequests();
|
virtual std::vector<SubRequest*> get_subrequests();
|
||||||
|
|
||||||
DynamicThread& get_thread();
|
DynamicThread& get_thread();
|
||||||
|
|
||||||
|
@ -57,12 +57,12 @@ namespace sgpem
|
||||||
|
|
||||||
void serialize(SerializeVisitor& translator) const;
|
void serialize(SerializeVisitor& translator) const;
|
||||||
|
|
||||||
StaticRequest& get_core();
|
StaticRequest& get_core();
|
||||||
const StaticRequest& get_core() const;
|
const StaticRequest& get_core() const;
|
||||||
|
|
||||||
// Since this method is visible only by the backend,
|
// Since this method is visible only by the backend,
|
||||||
// return directly a reference that lets us to
|
// return directly a reference that lets us to
|
||||||
// add and remove subrequests at will.
|
// add and remove subrequests at will.
|
||||||
std::vector<DynamicSubRequest*>& get_dynamic_subrequests();
|
std::vector<DynamicSubRequest*>& get_dynamic_subrequests();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -36,7 +36,7 @@ DynamicResource::DynamicResource(StaticResource *core) :
|
||||||
bool
|
bool
|
||||||
DynamicResource::operator==(const Resource& op2) const
|
DynamicResource::operator==(const Resource& op2) const
|
||||||
{
|
{
|
||||||
assert(dynamic_cast<const DynamicResource*>(&op2) != NULL);
|
assert(dynamic_cast<const DynamicResource*>(&op2) != NULL);
|
||||||
return _static_resource == dynamic_cast<const DynamicResource&>(op2)._static_resource;
|
return _static_resource == dynamic_cast<const DynamicResource&>(op2)._static_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,12 +62,12 @@ DynamicResource::serialize(SerializeVisitor& translator) const
|
||||||
StaticResource&
|
StaticResource&
|
||||||
DynamicResource::get_core()
|
DynamicResource::get_core()
|
||||||
{
|
{
|
||||||
return *_static_resource;
|
return *_static_resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const StaticResource&
|
const StaticResource&
|
||||||
DynamicResource::get_core() const
|
DynamicResource::get_core() const
|
||||||
{
|
{
|
||||||
return *_static_resource;
|
return *_static_resource;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,15 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
DynamicResource(StaticResource *core);
|
DynamicResource(StaticResource *core);
|
||||||
|
|
||||||
virtual bool operator==(const Resource& op2) const;
|
virtual bool operator==(const Resource& op2) const;
|
||||||
|
|
||||||
Glib::ustring get_name() const;
|
Glib::ustring get_name() const;
|
||||||
unsigned int get_places() const;
|
unsigned int get_places() const;
|
||||||
|
|
||||||
void serialize(SerializeVisitor& translator) const;
|
void serialize(SerializeVisitor& translator) const;
|
||||||
|
|
||||||
StaticResource& get_core();
|
StaticResource& get_core();
|
||||||
const StaticResource& get_core() const;
|
const StaticResource& get_core() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
memory::smart_ptr<StaticResource> _static_resource;
|
memory::smart_ptr<StaticResource> _static_resource;
|
||||||
|
|
|
@ -28,13 +28,13 @@ using namespace sgpem;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
DynamicSchedulable::DynamicSchedulable()
|
DynamicSchedulable::DynamicSchedulable()
|
||||||
: _priority_push(0)
|
: _priority_push(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
DynamicSchedulable::operator==(const Schedulable& op2) const
|
DynamicSchedulable::operator==(const Schedulable& op2) const
|
||||||
{
|
{
|
||||||
assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
|
assert(dynamic_cast<const DynamicSchedulable*>(&op2) != NULL);
|
||||||
return &get_core() == &(dynamic_cast<const DynamicSchedulable&>(op2).get_core());
|
return &get_core() == &(dynamic_cast<const DynamicSchedulable&>(op2).get_core());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,41 +31,40 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
|
DynamicSubRequest::DynamicSubRequest(StaticSubRequest* core,
|
||||||
DynamicRequest* owner) :
|
DynamicRequest* owner) :
|
||||||
_static_subrequest(core), _owner(owner),
|
_static_subrequest(core), _owner(owner),
|
||||||
_queue_position(-1), _ran_for(0), _state(Request::state_future)
|
_queue_position(-1), _ran_for(0), _state(Request::state_future)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other,
|
DynamicSubRequest::DynamicSubRequest(const DynamicSubRequest& other,
|
||||||
DynamicRequest* owner) :
|
DynamicRequest* owner) :
|
||||||
_static_subrequest(other._static_subrequest), _owner(owner),
|
_static_subrequest(other._static_subrequest), _owner(owner),
|
||||||
_queue_position(other._queue_position), _ran_for(other._ran_for),
|
_queue_position(other._queue_position), _ran_for(other._ran_for),
|
||||||
_state(other._state)
|
_state(other._state)
|
||||||
{
|
{
|
||||||
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
|
||||||
DynamicSubRequest::operator==(const SubRequest& op2) const
|
DynamicSubRequest::operator==(const SubRequest& op2) const
|
||||||
{
|
{
|
||||||
assert(dynamic_cast<const DynamicSubRequest*>(&op2) != NULL);
|
assert(dynamic_cast<const DynamicSubRequest*>(&op2) != NULL);
|
||||||
return _static_subrequest == dynamic_cast<const DynamicSubRequest&>(op2)._static_subrequest;
|
return _static_subrequest == dynamic_cast<const DynamicSubRequest&>(op2)._static_subrequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,42 +98,42 @@ DynamicSubRequest::set_queue_position(int position)
|
||||||
DynamicRequest&
|
DynamicRequest&
|
||||||
DynamicSubRequest::get_request()
|
DynamicSubRequest::get_request()
|
||||||
{
|
{
|
||||||
return *_owner;
|
return *_owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicSubRequest::state
|
DynamicSubRequest::state
|
||||||
DynamicSubRequest::get_state() const
|
DynamicSubRequest::get_state() const
|
||||||
{
|
{
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DynamicSubRequest::state
|
DynamicSubRequest::state
|
||||||
DynamicSubRequest::set_state(state new_state)
|
DynamicSubRequest::set_state(state new_state)
|
||||||
{
|
{
|
||||||
state temp = _state;
|
state temp = _state;
|
||||||
_state = new_state;
|
_state = new_state;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
DynamicSubRequest::get_remaining_time() const
|
DynamicSubRequest::get_remaining_time() const
|
||||||
{
|
{
|
||||||
return _static_subrequest->get_length() - _ran_for;
|
return _static_subrequest->get_length() - _ran_for;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
DynamicSubRequest::decrease_remaining_time()
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,12 +147,12 @@ DynamicSubRequest::serialize(SerializeVisitor& translator) const
|
||||||
StaticSubRequest&
|
StaticSubRequest&
|
||||||
DynamicSubRequest::get_core()
|
DynamicSubRequest::get_core()
|
||||||
{
|
{
|
||||||
return *_static_subrequest;
|
return *_static_subrequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const StaticSubRequest&
|
const StaticSubRequest&
|
||||||
DynamicSubRequest::get_core() const
|
DynamicSubRequest::get_core() const
|
||||||
{
|
{
|
||||||
return *_static_subrequest;
|
return *_static_subrequest;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,20 +34,20 @@
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
class DynamicSubRequest;
|
class DynamicSubRequest;
|
||||||
class SerializeVisitor;
|
class SerializeVisitor;
|
||||||
class Resource;
|
class Resource;
|
||||||
class StaticSubRequest;
|
class StaticSubRequest;
|
||||||
|
|
||||||
class SG_DLLLOCAL DynamicSubRequest : public SubRequest
|
class SG_DLLLOCAL DynamicSubRequest : public SubRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DynamicSubRequest(StaticSubRequest* core,
|
DynamicSubRequest(StaticSubRequest* core,
|
||||||
DynamicRequest* owner);
|
DynamicRequest* owner);
|
||||||
DynamicSubRequest(const DynamicSubRequest& other, DynamicRequest* owner);
|
DynamicSubRequest(const DynamicSubRequest& other, DynamicRequest* owner);
|
||||||
|
|
||||||
virtual ~DynamicSubRequest();
|
virtual ~DynamicSubRequest();
|
||||||
|
|
||||||
virtual bool operator==(const SubRequest& op2) const;
|
virtual bool operator==(const SubRequest& op2) const;
|
||||||
|
|
||||||
resource_key_t get_resource_key() const;
|
resource_key_t get_resource_key() const;
|
||||||
|
|
||||||
|
@ -56,28 +56,28 @@ namespace sgpem
|
||||||
int get_queue_position() const;
|
int get_queue_position() const;
|
||||||
void set_queue_position(int position);
|
void set_queue_position(int position);
|
||||||
|
|
||||||
virtual DynamicRequest& get_request();
|
virtual DynamicRequest& get_request();
|
||||||
|
|
||||||
state get_state() const;
|
state get_state() const;
|
||||||
state set_state(state new_state);
|
state set_state(state new_state);
|
||||||
|
|
||||||
unsigned int get_remaining_time() const;
|
unsigned int get_remaining_time() const;
|
||||||
unsigned int decrease_remaining_time();
|
unsigned int decrease_remaining_time();
|
||||||
|
|
||||||
void serialize(SerializeVisitor& translator) const;
|
void serialize(SerializeVisitor& translator) const;
|
||||||
|
|
||||||
StaticSubRequest& get_core();
|
StaticSubRequest& get_core();
|
||||||
const StaticSubRequest& get_core() const;
|
const StaticSubRequest& get_core() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Undefined
|
// Undefined
|
||||||
DynamicSubRequest(const DynamicSubRequest&);
|
DynamicSubRequest(const DynamicSubRequest&);
|
||||||
|
|
||||||
memory::smart_ptr<StaticSubRequest> _static_subrequest;
|
memory::smart_ptr<StaticSubRequest> _static_subrequest;
|
||||||
DynamicRequest* _owner;
|
DynamicRequest* _owner;
|
||||||
int _queue_position;
|
int _queue_position;
|
||||||
unsigned int _ran_for;
|
unsigned int _ran_for;
|
||||||
state _state;
|
state _state;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,16 +35,16 @@ using namespace std;
|
||||||
|
|
||||||
|
|
||||||
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
|
DynamicThread::DynamicThread(StaticThread* core, DynamicProcess* parent)
|
||||||
: DynamicSchedulable(), _core(core), _state(state_future), _parent(parent),
|
: DynamicSchedulable(), _core(core), _state(state_future), _parent(parent),
|
||||||
_ran_for(0), _last_acquisition(-1), _last_release(-1)
|
_ran_for(0), _last_acquisition(-1), _last_release(-1)
|
||||||
{
|
{
|
||||||
assert(core != NULL);
|
assert(core != NULL);
|
||||||
assert(parent != NULL);
|
assert(parent != 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<DynamicThread*>& siblings = parent->get_dynamic_threads();
|
std::vector<DynamicThread*>& siblings = parent->get_dynamic_threads();
|
||||||
siblings.push_back(this);
|
siblings.push_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
|
DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent) :
|
||||||
|
@ -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
|
||||||
|
@ -70,8 +70,8 @@ DynamicThread::DynamicThread(const DynamicThread &other, DynamicProcess* parent)
|
||||||
|
|
||||||
DynamicThread::~DynamicThread()
|
DynamicThread::~DynamicThread()
|
||||||
{
|
{
|
||||||
for_each(_dynamic_requests.begin(), _dynamic_requests.end(),
|
for_each(_dynamic_requests.begin(), _dynamic_requests.end(),
|
||||||
memory::deletor<DynamicRequest>());
|
memory::deletor<DynamicRequest>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,20 +112,20 @@ DynamicThread::serialize(SerializeVisitor& translator) const
|
||||||
StaticThread&
|
StaticThread&
|
||||||
DynamicThread::get_core()
|
DynamicThread::get_core()
|
||||||
{
|
{
|
||||||
return *_core;
|
return *_core;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StaticThread&
|
const StaticThread&
|
||||||
DynamicThread::get_core() const
|
DynamicThread::get_core() const
|
||||||
{
|
{
|
||||||
return *_core;
|
return *_core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<DynamicRequest*>&
|
std::vector<DynamicRequest*>&
|
||||||
DynamicThread::get_dynamic_requests()
|
DynamicThread::get_dynamic_requests()
|
||||||
{
|
{
|
||||||
return _dynamic_requests;
|
return _dynamic_requests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,10 +138,10 @@ DynamicThread::get_elapsed_time() const
|
||||||
void
|
void
|
||||||
DynamicThread::decrease_remaining_time()
|
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++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -58,11 +58,11 @@ namespace sgpem
|
||||||
class SG_DLLEXPORT Environment
|
class SG_DLLEXPORT Environment
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef SubRequest::resource_key_t resource_key_t;
|
typedef SubRequest::resource_key_t resource_key_t;
|
||||||
|
|
||||||
typedef std::vector<Process*> Processes;
|
typedef std::vector<Process*> Processes;
|
||||||
typedef std::map<resource_key_t, Resource*> Resources;
|
typedef std::map<resource_key_t, Resource*> Resources;
|
||||||
typedef std::vector<SubRequest*> SubRequestQueue;
|
typedef std::vector<SubRequest*> SubRequestQueue;
|
||||||
|
|
||||||
/// \brief Returns an indexed set of snapshots of the processes
|
/// \brief Returns an indexed set of snapshots of the processes
|
||||||
/// Returns a standard vector of Process objects describing
|
/// Returns a standard vector of Process objects describing
|
||||||
|
@ -72,7 +72,7 @@ namespace sgpem
|
||||||
/// \return a constant set of snapshots of processes
|
/// \return a constant set of snapshots of processes
|
||||||
|
|
||||||
virtual const Processes&
|
virtual const Processes&
|
||||||
get_processes() const = 0;
|
get_processes() const = 0;
|
||||||
|
|
||||||
|
|
||||||
/// \brief Returns an indexed set of snapshots of the resources
|
/// \brief Returns an indexed set of snapshots of the resources
|
||||||
|
@ -90,7 +90,7 @@ namespace sgpem
|
||||||
/// \return an indexed constant set of snapshot of resources.
|
/// \return an indexed constant set of snapshot of resources.
|
||||||
|
|
||||||
virtual const Resources&
|
virtual const Resources&
|
||||||
get_resources() const = 0;
|
get_resources() const = 0;
|
||||||
|
|
||||||
|
|
||||||
/// \brief Returns a snapshot of the current request queue for a resource.
|
/// \brief Returns a snapshot of the current request queue for a resource.
|
||||||
|
@ -101,7 +101,7 @@ namespace sgpem
|
||||||
/// \return the current ready requests queue (constant).
|
/// \return the current ready requests queue (constant).
|
||||||
|
|
||||||
virtual const SubRequestQueue&
|
virtual const SubRequestQueue&
|
||||||
get_request_queue(resource_key_t resource_key) const = 0;
|
get_request_queue(resource_key_t resource_key) const = 0;
|
||||||
|
|
||||||
|
|
||||||
/// \brief Returns a snapshot of the current scheduler's ready queue.
|
/// \brief Returns a snapshot of the current scheduler's ready queue.
|
||||||
|
@ -112,7 +112,7 @@ namespace sgpem
|
||||||
/// \return the current ready queue (constant).
|
/// \return the current ready queue (constant).
|
||||||
|
|
||||||
virtual const ReadyQueue&
|
virtual const ReadyQueue&
|
||||||
get_sorted_queue() const = 0;
|
get_sorted_queue() const = 0;
|
||||||
|
|
||||||
|
|
||||||
/// \brief The standard virtual destructor.
|
/// \brief The standard virtual destructor.
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace sgpem
|
||||||
{
|
{
|
||||||
|
|
||||||
GlobalPreferencesSerializer::GlobalPreferencesSerializer(GlobalPreferences &gp)
|
GlobalPreferencesSerializer::GlobalPreferencesSerializer(GlobalPreferences &gp)
|
||||||
: _globalPreferences(gp)
|
: _globalPreferences(gp)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -30,40 +30,38 @@ using namespace std;
|
||||||
|
|
||||||
|
|
||||||
History::History()
|
History::History()
|
||||||
: _notify(true)
|
: _notify(true)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
History::~History()
|
History::~History()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
History::attach(HistoryObserver& observer)
|
History::attach(HistoryObserver& observer)
|
||||||
{
|
{
|
||||||
_observers.push_back(&observer);
|
_observers.push_back(&observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
History::detach(const HistoryObserver& observer)
|
History::detach(const HistoryObserver& observer)
|
||||||
{
|
{
|
||||||
_observers.erase(std::find(_observers.begin(),
|
_observers.erase(std::find(_observers.begin(),
|
||||||
_observers.end(),
|
_observers.end(),
|
||||||
&observer));
|
&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;
|
||||||
|
|
|
@ -45,64 +45,64 @@ namespace sgpem
|
||||||
*/
|
*/
|
||||||
class History;
|
class History;
|
||||||
|
|
||||||
// Forward declarations:
|
// Forward declarations:
|
||||||
class HistoryObserver;
|
class HistoryObserver;
|
||||||
class Resource;
|
class Resource;
|
||||||
class Process;
|
class Process;
|
||||||
class Thread;
|
class Thread;
|
||||||
class Request;
|
class Request;
|
||||||
class SubRequest;
|
class SubRequest;
|
||||||
|
|
||||||
class SG_DLLEXPORT History
|
class SG_DLLEXPORT History
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef unsigned int size_t;
|
typedef unsigned int size_t;
|
||||||
typedef unsigned int time_t;
|
typedef unsigned int time_t;
|
||||||
typedef unsigned int position;
|
typedef unsigned int position;
|
||||||
typedef int prio_t;
|
typedef int prio_t;
|
||||||
|
|
||||||
typedef Environment::resource_key_t resource_key_t;
|
typedef Environment::resource_key_t resource_key_t;
|
||||||
typedef const std::pair<resource_key_t, Resource*> ResourcePair;
|
typedef const std::pair<resource_key_t, Resource*> ResourcePair;
|
||||||
|
|
||||||
History();
|
History();
|
||||||
virtual ~History() = 0;
|
virtual ~History() = 0;
|
||||||
|
|
||||||
virtual size_t get_size() const = 0;
|
virtual size_t get_size() const = 0;
|
||||||
virtual const Environment& get_last_environment() const = 0;
|
virtual const Environment& get_last_environment() const = 0;
|
||||||
virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0;
|
virtual const Environment& get_environment_at(position index) const throw(std::out_of_range) = 0;
|
||||||
|
|
||||||
virtual void remove(resource_key_t resource_key) = 0;
|
virtual void remove(resource_key_t resource_key) = 0;
|
||||||
virtual void remove(Process& process) = 0;
|
virtual void remove(Process& process) = 0;
|
||||||
virtual void remove(Thread& thread) = 0;
|
virtual void remove(Thread& thread) = 0;
|
||||||
virtual void remove(Request& request) = 0;
|
virtual void remove(Request& request) = 0;
|
||||||
virtual void remove(SubRequest& subrequest) = 0;
|
virtual void remove(SubRequest& subrequest) = 0;
|
||||||
|
|
||||||
|
|
||||||
virtual ResourcePair add_resource(const Glib::ustring& name,
|
virtual ResourcePair add_resource(const Glib::ustring& name,
|
||||||
bool preemptable = false,
|
bool preemptable = false,
|
||||||
size_t places = 1,
|
size_t places = 1,
|
||||||
size_t availability = 0) = 0;
|
size_t availability = 0) = 0;
|
||||||
|
|
||||||
virtual Process& add_process(const Glib::ustring& name,
|
virtual Process& add_process(const Glib::ustring& name,
|
||||||
time_t arrival_time,
|
time_t arrival_time,
|
||||||
prio_t base_priority = 0) = 0;
|
prio_t base_priority = 0) = 0;
|
||||||
|
|
||||||
virtual Thread& add_thread(const Glib::ustring& name,
|
virtual Thread& add_thread(const Glib::ustring& name,
|
||||||
Process& parent,
|
Process& parent,
|
||||||
time_t cpu_time,
|
time_t cpu_time,
|
||||||
time_t arrival_time = 0,
|
time_t arrival_time = 0,
|
||||||
prio_t base_priority = 0) = 0;
|
prio_t base_priority = 0) = 0;
|
||||||
|
|
||||||
virtual Request& add_request(Thread& owner,
|
virtual Request& add_request(Thread& owner,
|
||||||
time_t instant) = 0;
|
time_t instant) = 0;
|
||||||
|
|
||||||
virtual SubRequest& add_subrequest(Request& request,
|
virtual SubRequest& add_subrequest(Request& request,
|
||||||
resource_key_t resource_key,
|
resource_key_t resource_key,
|
||||||
time_t duration) = 0;
|
time_t duration) = 0;
|
||||||
|
|
||||||
|
|
||||||
virtual void attach(HistoryObserver& observer);
|
virtual void attach(HistoryObserver& observer);
|
||||||
virtual void detach(const HistoryObserver& observer);
|
virtual void detach(const HistoryObserver& observer);
|
||||||
|
|
||||||
/** \brief Enable/disable notifications to registered observers
|
/** \brief Enable/disable notifications to registered observers
|
||||||
*
|
*
|
||||||
|
@ -114,16 +114,17 @@ namespace sgpem
|
||||||
*/
|
*/
|
||||||
virtual bool set_notify_enabled(bool enabled = true);
|
virtual bool set_notify_enabled(bool enabled = true);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::vector<HistoryObserver*> RegisteredObservers;
|
typedef std::vector<HistoryObserver*> RegisteredObservers;
|
||||||
RegisteredObservers _observers;
|
RegisteredObservers _observers;
|
||||||
|
|
||||||
virtual void notify_change();
|
virtual void notify_change();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _notify;
|
bool _notify;
|
||||||
|
|
||||||
}; //~ class History
|
}
|
||||||
|
; //~ class History
|
||||||
|
|
||||||
}//~ namespace sgpem
|
}//~ namespace sgpem
|
||||||
|
|
||||||
|
|
|
@ -25,16 +25,17 @@
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
class History;
|
class History;
|
||||||
class HistoryObserver;
|
class HistoryObserver;
|
||||||
|
|
||||||
class SG_DLLEXPORT HistoryObserver
|
class SG_DLLEXPORT HistoryObserver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -37,32 +37,32 @@ 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();
|
||||||
|
|
||||||
_resources.insert(env.get_resources().find(key)->second);
|
_resources.insert(env.get_resources().find(key)->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,5 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
InvalidPluginException::InvalidPluginException(const std::string& what) :
|
InvalidPluginException::InvalidPluginException(const std::string& what) :
|
||||||
std::runtime_error(what)
|
std::runtime_error(what)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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,32 +72,32 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -25,26 +25,26 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
|
Module::Module(const Glib::ustring& identifier) throw(InvalidPluginException) :
|
||||||
Glib::Module(identifier),
|
Glib::Module(identifier),
|
||||||
_enabled(false),
|
_enabled(false),
|
||||||
_id(identifier),
|
_id(identifier),
|
||||||
on_init_ptr(NULL),
|
on_init_ptr(NULL),
|
||||||
on_exit_ptr(NULL),
|
on_exit_ptr(NULL),
|
||||||
describe_ptr(NULL),
|
describe_ptr(NULL),
|
||||||
get_name_ptr(NULL),
|
get_name_ptr(NULL),
|
||||||
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) &&
|
||||||
get_symbol(prefix + "get_author", (void*&) get_author_ptr) &&
|
get_symbol(prefix + "get_author", (void*&) get_author_ptr) &&
|
||||||
get_symbol(prefix + "get_version", (void*&) get_version_ptr)))
|
get_symbol(prefix + "get_version", (void*&) get_version_ptr)))
|
||||||
throw InvalidPluginException("incomplete/wrong exported interface");
|
throw InvalidPluginException("incomplete/wrong exported interface");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,13 @@ extern "C"
|
||||||
SG_DLLEXPORT void sgpem__Plugin__on_init();
|
SG_DLLEXPORT void sgpem__Plugin__on_init();
|
||||||
|
|
||||||
SG_DLLEXPORT void sgpem__Plugin__on_exit();
|
SG_DLLEXPORT void sgpem__Plugin__on_exit();
|
||||||
SG_DLLEXPORT const char* sgpem__Plugin__describe();
|
SG_DLLEXPORT const char* sgpem__Plugin__describe();
|
||||||
SG_DLLEXPORT const char* sgpem__Plugin__get_name();
|
SG_DLLEXPORT const char* sgpem__Plugin__get_name();
|
||||||
SG_DLLEXPORT const char* sgpem__Plugin__get_author();
|
SG_DLLEXPORT const char* sgpem__Plugin__get_author();
|
||||||
SG_DLLEXPORT float sgpem__Plugin__get_version();
|
SG_DLLEXPORT float sgpem__Plugin__get_version();
|
||||||
|
|
||||||
// To know why SG_DLLEXPORT must go *before* the return
|
// To know why SG_DLLEXPORT must go *before* the return
|
||||||
// value, see http://gcc.gnu.org/ml/gcc-help/2005-04/msg00340.html
|
// value, see http://gcc.gnu.org/ml/gcc-help/2005-04/msg00340.html
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ PluginManager::rescan_dirs()
|
||||||
Module* module = NULL;
|
Module* module = NULL;
|
||||||
|
|
||||||
for_each(_modules.begin(), _modules.end(),
|
for_each(_modules.begin(), _modules.end(),
|
||||||
memory::deletor<Module>());
|
memory::deletor<Module>());
|
||||||
_modules.clear();
|
_modules.clear();
|
||||||
|
|
||||||
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
GlobalPreferences& prefs = GlobalPreferences::get_instance();
|
||||||
|
@ -59,29 +59,29 @@ 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);
|
||||||
|
|
||||||
std::cerr << "Attempting to load module at path " << module_path << std::endl;
|
std::cerr << "Attempting to load module at path " << module_path << std::endl;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
module = new Module(module_path);
|
module = new Module(module_path);
|
||||||
_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ namespace sgpem
|
||||||
|
|
||||||
std::vector<Module*> _modules;
|
std::vector<Module*> _modules;
|
||||||
|
|
||||||
}; //~ class PluginManager
|
}
|
||||||
|
; //~ class PluginManager
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
|
|
@ -27,48 +27,48 @@ 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.
|
||||||
// Once we've done the check once, we
|
// Once we've done the check once, we
|
||||||
// can assume it's safe to use "[]";
|
// can assume it's safe to use "[]";
|
||||||
// this for performance reasons.
|
// this for performance reasons.
|
||||||
Thread* temp = _scheds.at(a);
|
Thread* temp = _scheds.at(a);
|
||||||
_scheds[a] = _scheds.at(b);
|
_scheds[a] = _scheds.at(b);
|
||||||
_scheds[b] = temp;
|
_scheds[b] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReadyQueue::size_t
|
ReadyQueue::size_t
|
||||||
ReadyQueue::size() const
|
ReadyQueue::size() const
|
||||||
{
|
{
|
||||||
return _scheds.size();
|
return _scheds.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ReadyQueue::append(Thread& thread)
|
ReadyQueue::append(Thread& thread)
|
||||||
{
|
{
|
||||||
_scheds.push_back(&thread);
|
_scheds.push_back(&thread);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -28,25 +28,25 @@
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
class ReadyQueue;
|
class ReadyQueue;
|
||||||
class Thread;
|
class Thread;
|
||||||
|
|
||||||
class SG_DLLEXPORT ReadyQueue
|
class SG_DLLEXPORT ReadyQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef unsigned int position;
|
typedef unsigned int position;
|
||||||
typedef unsigned int size_t;
|
typedef unsigned int size_t;
|
||||||
|
|
||||||
void swap(position a, position b) throw (std::out_of_range);
|
void swap(position a, position b) throw (std::out_of_range);
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
Thread& get_item_at(position index) throw (std::out_of_range);
|
Thread& get_item_at(position index) throw (std::out_of_range);
|
||||||
const Thread& get_item_at(position index) const throw (std::out_of_range);
|
const Thread& get_item_at(position index) const throw (std::out_of_range);
|
||||||
void append(Thread& schedulable);
|
void append(Thread& schedulable);
|
||||||
void erase_first();
|
void erase_first();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::vector<Thread*> Threads;
|
typedef std::vector<Thread*> Threads;
|
||||||
Threads _scheds;
|
Threads _scheds;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace sgpem
|
||||||
state_allocated = 1 << 1,
|
state_allocated = 1 << 1,
|
||||||
state_future = 1 << 2,
|
state_future = 1 << 2,
|
||||||
state_exhausted = 1 << 3,
|
state_exhausted = 1 << 3,
|
||||||
state_allocable = 1 << 4
|
state_allocable = 1 << 4
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~Request();
|
virtual ~Request();
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
virtual ~Resource();
|
virtual ~Resource();
|
||||||
|
|
||||||
virtual bool operator==(const Resource& op2) const = 0;
|
virtual bool operator==(const Resource& op2) const = 0;
|
||||||
|
|
||||||
virtual Glib::ustring get_name() const = 0;
|
virtual Glib::ustring get_name() const = 0;
|
||||||
virtual unsigned int get_places() const = 0;
|
virtual unsigned int get_places() const = 0;
|
||||||
|
|
|
@ -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,18 +106,19 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,13 +54,13 @@ namespace sgpem
|
||||||
|
|
||||||
const Managers& get_registered() const;
|
const Managers& get_registered() const;
|
||||||
|
|
||||||
void register_manager(ResourcePolicyManager* manager);
|
void register_manager(ResourcePolicyManager* manager);
|
||||||
|
|
||||||
void unregister_manager(ResourcePolicyManager* manager);
|
void unregister_manager(ResourcePolicyManager* manager);
|
||||||
|
|
||||||
ResourcePolicy& get_current_policy(History* history) throw(std::runtime_error);
|
ResourcePolicy& get_current_policy(History* history) throw(std::runtime_error);
|
||||||
|
|
||||||
void activate_policy(History* history, ResourcePolicy* policy);
|
void activate_policy(History* history, ResourcePolicy* policy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ResourcePoliciesGatekeeper(); //private constructor.
|
ResourcePoliciesGatekeeper(); //private constructor.
|
||||||
|
@ -70,7 +70,7 @@ namespace sgpem
|
||||||
void deactivate_policies(const ResourcePolicyManager& manager);
|
void deactivate_policies(const ResourcePolicyManager& manager);
|
||||||
|
|
||||||
std::vector<ResourcePolicyManager*> _registered;
|
std::vector<ResourcePolicyManager*> _registered;
|
||||||
std::map<History*, ResourcePolicy*> _active_policies;
|
std::map<History*, ResourcePolicy*> _active_policies;
|
||||||
};
|
};
|
||||||
|
|
||||||
}//~ namespace sgpem
|
}//~ namespace sgpem
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace sgpem
|
||||||
|
|
||||||
virtual ~Schedulable() = 0;
|
virtual ~Schedulable() = 0;
|
||||||
|
|
||||||
virtual bool operator==(const Schedulable& op2) const = 0;
|
virtual bool operator==(const Schedulable& op2) const = 0;
|
||||||
|
|
||||||
virtual Glib::ustring get_name() const = 0;
|
virtual Glib::ustring get_name() const = 0;
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -69,13 +69,13 @@ namespace sgpem
|
||||||
Resets the simulation to the initial state.
|
Resets the simulation to the initial state.
|
||||||
*/
|
*/
|
||||||
void reset_status();
|
void reset_status();
|
||||||
/**
|
/**
|
||||||
Generates a new ReadyQueue representing the status of the processes
|
Generates a new ReadyQueue representing the status of the processes
|
||||||
at the simulation instant next to the current one, and extends the History by
|
at the simulation instant next to the current one, and extends the History by
|
||||||
one instant with it.
|
one instant with it.
|
||||||
|
|
||||||
\return false If the simulation has ended, true otherwise
|
\return false If the simulation has ended, true otherwise
|
||||||
*/
|
*/
|
||||||
bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException);
|
bool step_forward(History& history, CPUPolicy& cpu_policy) throw(UserInterruptException);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,6 +25,5 @@
|
||||||
using namespace sgpem;
|
using namespace sgpem;
|
||||||
|
|
||||||
SerializerError::SerializerError(const std::string& what) :
|
SerializerError::SerializerError(const std::string& what) :
|
||||||
std::runtime_error(what)
|
std::runtime_error(what)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,7 @@ template class SG_DLLEXPORT Singleton<ConcreteSimulation>;
|
||||||
|
|
||||||
|
|
||||||
Simulation::~Simulation()
|
Simulation::~Simulation()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
Simulation&
|
Simulation&
|
||||||
Simulation::get_instance()
|
Simulation::get_instance()
|
||||||
|
|
|
@ -23,7 +23,7 @@ using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
StaticProcess::StaticProcess(const Glib::ustring& name, const unsigned int& arrival, const int& priority)
|
StaticProcess::StaticProcess(const Glib::ustring& name, const unsigned int& arrival, const int& priority)
|
||||||
: StaticSchedulable(name, priority), _start_time(arrival)
|
: StaticSchedulable(name, priority), _start_time(arrival)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,24 +34,24 @@ StaticProcess::~StaticProcess()
|
||||||
unsigned int
|
unsigned int
|
||||||
StaticProcess::get_arrival_time() const
|
StaticProcess::get_arrival_time() const
|
||||||
{
|
{
|
||||||
return _start_time;
|
return _start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
StaticProcess::get_total_cpu_time() const
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<StaticThread*>&
|
std::vector<StaticThread*>&
|
||||||
StaticProcess::get_threads()
|
StaticProcess::get_threads()
|
||||||
{
|
{
|
||||||
return _threads;
|
return _threads;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,17 @@ namespace sgpem
|
||||||
/** \brief Destructor. */
|
/** \brief Destructor. */
|
||||||
virtual ~StaticProcess();
|
virtual ~StaticProcess();
|
||||||
|
|
||||||
virtual unsigned int get_total_cpu_time() const;
|
virtual unsigned int get_total_cpu_time() const;
|
||||||
virtual unsigned int get_arrival_time() const;
|
virtual unsigned int get_arrival_time() const;
|
||||||
|
|
||||||
// Does the job also of add_thread() and remove_thread(). :-)
|
// Does the job also of add_thread() and remove_thread(). :-)
|
||||||
// Since we're touching backend internals, we can do this safely
|
// Since we're touching backend internals, we can do this safely
|
||||||
// (because we know what we're doing, isn't it?)
|
// (because we know what we're doing, isn't it?)
|
||||||
virtual std::vector<StaticThread*>& get_threads();
|
virtual std::vector<StaticThread*>& get_threads();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int _start_time;
|
unsigned int _start_time;
|
||||||
std::vector<StaticThread*> _threads;
|
std::vector<StaticThread*> _threads;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,14 +31,14 @@ StaticRequest::StaticRequest(StaticThread* thread,
|
||||||
_thread(thread), _instant(instant)
|
_thread(thread), _instant(instant)
|
||||||
{
|
{
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
_thread->get_requests().push_back(this);
|
_thread->get_requests().push_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticRequest::~StaticRequest()
|
StaticRequest::~StaticRequest()
|
||||||
{
|
{
|
||||||
typedef std::vector<StaticRequest*> Requests;
|
typedef std::vector<StaticRequest*> Requests;
|
||||||
Requests& siblings = _thread->get_requests();
|
Requests& siblings = _thread->get_requests();
|
||||||
siblings.erase(find(siblings.begin(), siblings.end(), this));
|
siblings.erase(find(siblings.begin(), siblings.end(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
|
|
|
@ -29,23 +29,23 @@ using namespace std;
|
||||||
|
|
||||||
StaticThread::StaticThread(const Glib::ustring& name,
|
StaticThread::StaticThread(const Glib::ustring& name,
|
||||||
StaticProcess& process,
|
StaticProcess& process,
|
||||||
unsigned int cpu_time,
|
unsigned int cpu_time,
|
||||||
unsigned int arrival_time,
|
unsigned int arrival_time,
|
||||||
int base_priority) :
|
int base_priority) :
|
||||||
StaticSchedulable(name, base_priority),
|
StaticSchedulable(name, base_priority),
|
||||||
_start_time_delta(arrival_time),
|
_start_time_delta(arrival_time),
|
||||||
_required_cpu_time(cpu_time),
|
_required_cpu_time(cpu_time),
|
||||||
_process(&process)
|
_process(&process)
|
||||||
{
|
{
|
||||||
process.get_threads().push_back(this);
|
process.get_threads().push_back(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StaticThread::~StaticThread()
|
StaticThread::~StaticThread()
|
||||||
{
|
{
|
||||||
typedef std::vector<StaticThread*> Threads;
|
typedef std::vector<StaticThread*> Threads;
|
||||||
Threads& siblings = _process->get_threads();
|
Threads& siblings = _process->get_threads();
|
||||||
siblings.erase(find(siblings.begin(), siblings.end(), this));
|
siblings.erase(find(siblings.begin(), siblings.end(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,5 +70,5 @@ StaticThread::get_process()
|
||||||
std::vector<StaticRequest*>&
|
std::vector<StaticRequest*>&
|
||||||
StaticThread::get_requests()
|
StaticThread::get_requests()
|
||||||
{
|
{
|
||||||
return _static_requests;
|
return _static_requests;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,11 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
StaticThread(const Glib::ustring& name,
|
StaticThread(const Glib::ustring& name,
|
||||||
StaticProcess& process,
|
StaticProcess& process,
|
||||||
unsigned int cpu_time,
|
unsigned int cpu_time,
|
||||||
unsigned int arrival_time = 0,
|
unsigned int arrival_time = 0,
|
||||||
int base_priority = 0);
|
int base_priority = 0);
|
||||||
|
|
||||||
virtual ~StaticThread();
|
virtual ~StaticThread();
|
||||||
|
|
||||||
virtual unsigned int get_total_cpu_time() const;
|
virtual unsigned int get_total_cpu_time() const;
|
||||||
|
|
||||||
|
@ -54,11 +54,11 @@ namespace sgpem
|
||||||
|
|
||||||
virtual StaticProcess& get_process();
|
virtual StaticProcess& get_process();
|
||||||
|
|
||||||
// Caller can use directly the vector instead that
|
// Caller can use directly the vector instead that
|
||||||
// the "remove_request()" and "add_request()" method
|
// the "remove_request()" and "add_request()" method
|
||||||
// of the design. Since this class is internal to the
|
// of the design. Since this class is internal to the
|
||||||
// backend anyway, this is okay.
|
// backend anyway, this is okay.
|
||||||
virtual std::vector<StaticRequest*>& get_requests();
|
virtual std::vector<StaticRequest*>& get_requests();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StaticThread(const StaticThread&);
|
StaticThread(const StaticThread&);
|
||||||
|
|
|
@ -29,210 +29,210 @@ using Glib::ustring;
|
||||||
namespace sgpem
|
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 digits = "0123456789";
|
|
||||||
|
|
||||||
// the string can't be empty
|
|
||||||
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//checks if the string contains only digits
|
|
||||||
if (str.find_first_not_of(allvalid) < str.length())
|
|
||||||
return false;
|
|
||||||
if (str.substr(1).find_first_not_of(digits) < str.length() - 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
num = 0;
|
|
||||||
int multiplier = 1, val;
|
|
||||||
int start; //the position of the biggest digit
|
|
||||||
if (str[0] == '-')
|
|
||||||
start = 1;
|
|
||||||
else
|
|
||||||
start = 0;
|
|
||||||
for (int pos = str.length() - 1; pos >= start ; pos--)
|
|
||||||
{
|
{
|
||||||
val = str[pos] - 48; //the INTEGER value of the digit
|
static const ustring allvalid = "0123456789-";
|
||||||
num += val * multiplier;
|
static const ustring digits = "0123456789";
|
||||||
multiplier *= 10;
|
|
||||||
}
|
|
||||||
//if there is the minus then multiply for -1
|
|
||||||
if (start == 1)
|
|
||||||
num *= -1;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
// the string can't be empty
|
||||||
T
|
if (str.length() == 0 || (str.length() == 1 && str[0] == '-'))
|
||||||
string_to(const ustring& str) throw(domain_error)
|
return false;
|
||||||
{
|
|
||||||
if(tokenize(str).size() != 1)
|
|
||||||
throw domain_error(_("too few or too many tokens"));
|
|
||||||
|
|
||||||
istringstream iss(str);
|
//checks if the string contains only digits
|
||||||
|
if (str.find_first_not_of(allvalid) < str.length())
|
||||||
|
return false;
|
||||||
|
if (str.substr(1).find_first_not_of(digits) < str.length() - 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
num = 0;
|
||||||
|
int multiplier = 1, val;
|
||||||
T value;
|
int start; //the position of the biggest digit
|
||||||
|
if (str[0] == '-')
|
||||||
try
|
start = 1;
|
||||||
{
|
|
||||||
iss >> value;
|
|
||||||
}
|
|
||||||
catch(ios_base::failure e)
|
|
||||||
{
|
|
||||||
throw domain_error(e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable exceptions, otherwise peek() will throw them!
|
|
||||||
// how useless!!!
|
|
||||||
iss.exceptions(ios_base::goodbit);
|
|
||||||
|
|
||||||
if(iss.peek() != istringstream::traits_type::eof())
|
|
||||||
throw domain_error(_("incorrect number format"));
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <>
|
|
||||||
SG_DLLEXPORT bool
|
|
||||||
string_to<bool>(const Glib::ustring& str) throw(domain_error)
|
|
||||||
{
|
|
||||||
if(tokenize(str).size() != 1)
|
|
||||||
throw domain_error(_("too few or too many tokens"));
|
|
||||||
|
|
||||||
istringstream iss(str);
|
|
||||||
|
|
||||||
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
|
||||||
|
|
||||||
bool value;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
iss >> boolalpha >> value;
|
|
||||||
}
|
|
||||||
catch(ios_base::failure e)
|
|
||||||
{
|
|
||||||
throw domain_error(e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
// disable exceptions, otherwise peek() will throw them!
|
|
||||||
// how useless!!!
|
|
||||||
iss.exceptions(ios_base::goodbit);
|
|
||||||
|
|
||||||
if(iss.peek() != istringstream::traits_type::eof())
|
|
||||||
throw domain_error(_("incorrect boolean"));
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
\brief A function that converts an integer value to an Unicode string
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
int_to_string(const int& num, ustring& str)
|
|
||||||
{
|
|
||||||
if (num == 0)
|
|
||||||
{
|
|
||||||
str = '0';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = "";
|
|
||||||
int val = num;
|
|
||||||
bool negative = (val < 0) ? true : false;
|
|
||||||
if (negative) val *= -1;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
str = char(val % 10 + 48) + str;
|
|
||||||
if (val > 1 && val / 10 != 0)
|
|
||||||
val /= 10;
|
|
||||||
else
|
else
|
||||||
break;
|
start = 0;
|
||||||
|
for (int pos = str.length() - 1; pos >= start ; pos--)
|
||||||
|
{
|
||||||
|
val = str[pos] - 48; //the INTEGER value of the digit
|
||||||
|
num += val * multiplier;
|
||||||
|
multiplier *= 10;
|
||||||
|
}
|
||||||
|
//if there is the minus then multiply for -1
|
||||||
|
if (start == 1)
|
||||||
|
num *= -1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
if (negative)
|
|
||||||
str = '-' + str;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
template <typename T>
|
||||||
float_to_string(const float& f, Glib::ustring& str)
|
T
|
||||||
{
|
string_to(const ustring& str) throw(domain_error)
|
||||||
stringstream ss;
|
{
|
||||||
ss << f;
|
if (tokenize(str).size() != 1)
|
||||||
char p[20];
|
throw domain_error(_("too few or too many tokens"));
|
||||||
ss.getline(p, 20);
|
|
||||||
str = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
istringstream iss(str);
|
||||||
string_to_float(const Glib::ustring& str, float& f)
|
|
||||||
{
|
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
stringstream ss;
|
|
||||||
ss << str;
|
T value;
|
||||||
ss >> f;
|
|
||||||
}
|
try
|
||||||
|
{
|
||||||
|
iss >> value;
|
||||||
|
}
|
||||||
|
catch (ios_base::failure e)
|
||||||
|
{
|
||||||
|
throw domain_error(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
// disable exceptions, otherwise peek() will throw them!
|
||||||
|
// how useless!!!
|
||||||
|
iss.exceptions(ios_base::goodbit);
|
||||||
|
|
||||||
|
if (iss.peek() != istringstream::traits_type::eof())
|
||||||
|
throw domain_error(_("incorrect number format"));
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
SG_DLLEXPORT bool
|
||||||
|
string_to<bool>(const Glib::ustring& str) throw(domain_error)
|
||||||
|
{
|
||||||
|
if (tokenize(str).size() != 1)
|
||||||
|
throw domain_error(_("too few or too many tokens"));
|
||||||
|
|
||||||
|
istringstream iss(str);
|
||||||
|
|
||||||
|
iss.exceptions(ios_base::failbit | ios_base::badbit);
|
||||||
|
|
||||||
|
bool value;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
iss >> boolalpha >> value;
|
||||||
|
}
|
||||||
|
catch (ios_base::failure e)
|
||||||
|
{
|
||||||
|
throw domain_error(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
// disable exceptions, otherwise peek() will throw them!
|
||||||
|
// how useless!!!
|
||||||
|
iss.exceptions(ios_base::goodbit);
|
||||||
|
|
||||||
|
if (iss.peek() != istringstream::traits_type::eof())
|
||||||
|
throw domain_error(_("incorrect boolean"));
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
\brief A function that converts an integer value to an Unicode string
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
int_to_string(const int& num, ustring& str)
|
||||||
|
{
|
||||||
|
if (num == 0)
|
||||||
|
{
|
||||||
|
str = '0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = "";
|
||||||
|
int val = num;
|
||||||
|
bool negative = (val < 0) ? true : false;
|
||||||
|
if (negative) val *= -1;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
str = char(val % 10 + 48) + str;
|
||||||
|
if (val > 1 && val / 10 != 0)
|
||||||
|
val /= 10;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (negative)
|
||||||
|
str = '-' + str;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
float_to_string(const float& f, Glib::ustring& str)
|
||||||
|
{
|
||||||
|
stringstream ss;
|
||||||
|
ss << f;
|
||||||
|
char p[20];
|
||||||
|
ss.getline(p, 20);
|
||||||
|
str = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
string_to_float(const Glib::ustring& str, float& f)
|
||||||
|
{
|
||||||
|
stringstream ss;
|
||||||
|
ss << str;
|
||||||
|
ss >> f;
|
||||||
|
}
|
||||||
|
|
||||||
// helper function for tokenize()
|
// 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)
|
|
||||||
tokens.push_back(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tokens
|
|
||||||
tokenize(const ustring& str)
|
|
||||||
{
|
|
||||||
istringstream iss(str);
|
|
||||||
Tokens tokens;
|
|
||||||
|
|
||||||
while(iss)
|
|
||||||
{
|
{
|
||||||
ustring token;
|
if (token.size() > 0)
|
||||||
iss >> token;
|
tokens.push_back(token);
|
||||||
|
|
||||||
ustring::size_type index;
|
|
||||||
|
|
||||||
// for the SET command, parse the assigment symbol as
|
|
||||||
// a separate token
|
|
||||||
do
|
|
||||||
{
|
|
||||||
index = token.find('=');
|
|
||||||
|
|
||||||
if(index != ustring::npos)
|
|
||||||
{
|
|
||||||
add_token(tokens, token.substr(0, index));
|
|
||||||
add_token(tokens, "=");
|
|
||||||
|
|
||||||
// the second argument can safely be out of range
|
|
||||||
token = token.substr(index + 1, token.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while(index != ustring::npos);
|
|
||||||
|
|
||||||
add_token(tokens, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokens;
|
Tokens
|
||||||
}
|
tokenize(const ustring& str)
|
||||||
|
{
|
||||||
|
istringstream iss(str);
|
||||||
|
Tokens tokens;
|
||||||
|
|
||||||
|
while (iss)
|
||||||
|
{
|
||||||
|
ustring token;
|
||||||
|
iss >> token;
|
||||||
|
|
||||||
|
ustring::size_type index;
|
||||||
|
|
||||||
|
// for the SET command, parse the assigment symbol as
|
||||||
|
// a separate token
|
||||||
|
do
|
||||||
|
{
|
||||||
|
index = token.find('=');
|
||||||
|
|
||||||
|
if (index != ustring::npos)
|
||||||
|
{
|
||||||
|
add_token(tokens, token.substr(0, index));
|
||||||
|
add_token(tokens, "=");
|
||||||
|
|
||||||
|
// the second argument can safely be out of range
|
||||||
|
token = token.substr(index + 1, token.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (index != ustring::npos);
|
||||||
|
|
||||||
|
add_token(tokens, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,24 +34,24 @@ namespace sgpem
|
||||||
class SG_DLLEXPORT SubRequest
|
class SG_DLLEXPORT SubRequest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef int resource_key_t;
|
typedef int resource_key_t;
|
||||||
typedef Request::state state;
|
typedef Request::state state;
|
||||||
|
|
||||||
virtual ~SubRequest();
|
virtual ~SubRequest();
|
||||||
|
|
||||||
virtual bool operator==(const SubRequest& op2) const = 0;
|
virtual bool operator==(const SubRequest& op2) const = 0;
|
||||||
|
|
||||||
virtual resource_key_t get_resource_key() const = 0;
|
virtual resource_key_t get_resource_key() const = 0;
|
||||||
|
|
||||||
virtual unsigned int get_length() const = 0;
|
virtual unsigned int get_length() const = 0;
|
||||||
|
|
||||||
virtual int get_queue_position() const = 0;
|
virtual int get_queue_position() const = 0;
|
||||||
|
|
||||||
virtual state get_state() const = 0;
|
virtual state get_state() const = 0;
|
||||||
|
|
||||||
virtual unsigned int get_remaining_time() const = 0;
|
virtual unsigned int get_remaining_time() const = 0;
|
||||||
|
|
||||||
virtual Request& get_request() = 0;
|
virtual Request& get_request() = 0;
|
||||||
|
|
||||||
virtual void serialize(SerializeVisitor& translator) const = 0;
|
virtual void serialize(SerializeVisitor& translator) const = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace sgpem
|
||||||
public:
|
public:
|
||||||
virtual ~Thread();
|
virtual ~Thread();
|
||||||
|
|
||||||
virtual Process& get_process() = 0;
|
virtual Process& get_process() = 0;
|
||||||
virtual std::vector<Request*> get_requests() = 0;
|
virtual std::vector<Request*> get_requests() = 0;
|
||||||
virtual void serialize(SerializeVisitor& translator) const = 0;
|
virtual void serialize(SerializeVisitor& translator) const = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,9 +26,8 @@ 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,16 +157,16 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_restore(cr);
|
cairo_restore(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)
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
CairoWidget::CairoWidget()
|
CairoWidget::CairoWidget()
|
||||||
: Glib::ObjectBase("sgpem_CairoWidget"),
|
: Glib::ObjectBase("sgpem_CairoWidget"),
|
||||||
Gtk::Widget(), _h(1), _buf(NULL)
|
Gtk::Widget(), _h(1), _buf(NULL)
|
||||||
{
|
{
|
||||||
set_flags(Gtk::NO_WINDOW);
|
set_flags(Gtk::NO_WINDOW);
|
||||||
// Register this observer:
|
// Register this observer:
|
||||||
|
@ -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();
|
||||||
|
@ -97,32 +97,32 @@ CairoWidget::on_realize()
|
||||||
GdkWindowAttr attributes;
|
GdkWindowAttr attributes;
|
||||||
memset(&attributes, 0, sizeof(attributes));
|
memset(&attributes, 0, sizeof(attributes));
|
||||||
|
|
||||||
Gtk::Allocation alloc = get_allocation();
|
Gtk::Allocation alloc = get_allocation();
|
||||||
|
|
||||||
attributes.x = alloc.get_x();
|
attributes.x = alloc.get_x();
|
||||||
attributes.y = alloc.get_y();
|
attributes.y = alloc.get_y();
|
||||||
attributes.width = alloc.get_width();
|
attributes.width = alloc.get_width();
|
||||||
attributes.height = alloc.get_height();
|
attributes.height = alloc.get_height();
|
||||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||||
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
|
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
|
||||||
attributes.window_type = GDK_WINDOW_CHILD;
|
attributes.window_type = GDK_WINDOW_CHILD;
|
||||||
attributes.visual = get_visual()->gobj();
|
attributes.visual = get_visual()->gobj();
|
||||||
attributes.colormap = get_colormap()->gobj();
|
attributes.colormap = get_colormap()->gobj();
|
||||||
|
|
||||||
static const gint attributes_mask = Gdk::WA_X | Gdk::WA_Y | Gdk::WA_WMCLASS
|
static const gint attributes_mask = Gdk::WA_X | Gdk::WA_Y | Gdk::WA_WMCLASS
|
||||||
| Gdk::WA_VISUAL | Gdk::WA_COLORMAP;
|
| Gdk::WA_VISUAL | Gdk::WA_COLORMAP;
|
||||||
|
|
||||||
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
|
||||||
&attributes,
|
&attributes,
|
||||||
attributes_mask);
|
attributes_mask);
|
||||||
|
|
||||||
unset_flags(Gtk::NO_WINDOW);
|
unset_flags(Gtk::NO_WINDOW);
|
||||||
set_window(window);
|
set_window(window);
|
||||||
window->set_user_data(gobj());
|
window->set_user_data(gobj());
|
||||||
|
|
||||||
// Not sure if the following line is needed:
|
// Not sure if the following line is needed:
|
||||||
gtk_style_attach(get_style()->gobj(), window->gobj());
|
gtk_style_attach(get_style()->gobj(), window->gobj());
|
||||||
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
get_style()->set_background(window, Gtk::STATE_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -130,26 +130,26 @@ CairoWidget::on_size_request(Gtk::Requisition* requisition)
|
||||||
{
|
{
|
||||||
// FIXME: take correct measures, consider also using a viewport(?)
|
// FIXME: take correct measures, consider also using a viewport(?)
|
||||||
*requisition = Gtk::Requisition();
|
*requisition = Gtk::Requisition();
|
||||||
requisition->width = get_allocation().get_width();
|
requisition->width = get_allocation().get_width();
|
||||||
requisition->height = _h;
|
requisition->height = _h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CairoWidget::on_size_allocate(const Gtk::Allocation& allocation)
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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,
|
||||||
|
|
|
@ -40,8 +40,8 @@ namespace sgpem
|
||||||
void update(const History& history);
|
void update(const History& history);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void on_realize();
|
virtual void on_realize();
|
||||||
virtual void on_size_allocate(const Gtk::Allocation& allocation);
|
virtual void on_size_allocate(const Gtk::Allocation& allocation);
|
||||||
virtual void on_size_request(Gtk::Requisition* requisition);
|
virtual void on_size_request(Gtk::Requisition* requisition);
|
||||||
virtual bool on_expose_event(GdkEventExpose* event);
|
virtual bool on_expose_event(GdkEventExpose* event);
|
||||||
virtual bool on_button_press_event(GdkEventButton* event);
|
virtual bool on_button_press_event(GdkEventButton* event);
|
||||||
|
|
|
@ -48,56 +48,55 @@ test_me()
|
||||||
|
|
||||||
|
|
||||||
GuiBuilder::GuiBuilder(const std::string& gladefile)
|
GuiBuilder::GuiBuilder(const std::string& gladefile)
|
||||||
: _refXml(Xml::create(gladefile))
|
: _refXml(Xml::create(gladefile))
|
||||||
{
|
{
|
||||||
using namespace Gtk;
|
using namespace Gtk;
|
||||||
|
|
||||||
Window& main_window = get_initial_window();
|
Window& main_window = get_initial_window();
|
||||||
|
|
||||||
// Connect extra signals (decide where to do this...
|
// Connect extra signals (decide where to do this...
|
||||||
// here -- ugly -- derive widgets and then use
|
// here -- ugly -- derive widgets and then use
|
||||||
// Glade::Xml::get_widget_derived -- better --)
|
// Glade::Xml::get_widget_derived -- better --)
|
||||||
MenuItem* file_quit = NULL;
|
MenuItem* file_quit = NULL;
|
||||||
_refXml->get_widget("MenuItem.File.Quit", file_quit);
|
_refXml->get_widget("MenuItem.File.Quit", file_quit);
|
||||||
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
|
file_quit->signal_activate().connect(sigc::ptr_fun(&Main::quit));
|
||||||
|
|
||||||
// About dialog
|
// About dialog
|
||||||
MenuItem* help_about = NULL;
|
MenuItem* help_about = NULL;
|
||||||
_refXml->get_widget("MenuItem.Help.About", help_about);
|
_refXml->get_widget("MenuItem.Help.About", help_about);
|
||||||
AboutDialog* about_dialog = NULL;
|
AboutDialog* about_dialog = NULL;
|
||||||
_refXml->get_widget("AboutDialog", about_dialog);
|
_refXml->get_widget("AboutDialog", about_dialog);
|
||||||
//help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
//help_about->signal_activate().connect(sigc::mem_fun(*about_dialog, &Window::show));
|
||||||
help_about->signal_activate().connect(sigc::ptr_fun(test_me));
|
help_about->signal_activate().connect(sigc::ptr_fun(test_me));
|
||||||
|
|
||||||
// Temporary code to test the Schedulables custom widget
|
// Temporary code to test the Schedulables custom widget
|
||||||
Expander* scheds_expander = NULL;
|
Expander* scheds_expander = NULL;
|
||||||
_refXml->get_widget("SchedulablesExpander", scheds_expander);
|
_refXml->get_widget("SchedulablesExpander", scheds_expander);
|
||||||
SchedulablesWidget* scheds_widget = manage(new SchedulablesWidget());
|
SchedulablesWidget* scheds_widget = manage(new SchedulablesWidget());
|
||||||
scheds_expander->add(*scheds_widget);
|
scheds_expander->add(*scheds_widget);
|
||||||
// we have to remember to manually show custom added widgets:
|
// we have to remember to manually show custom added widgets:
|
||||||
scheds_widget->show();
|
scheds_widget->show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GuiBuilder::~GuiBuilder()
|
GuiBuilder::~GuiBuilder()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Gtk::Window&
|
Gtk::Window&
|
||||||
GuiBuilder::get_initial_window() const
|
GuiBuilder::get_initial_window() const
|
||||||
{
|
{
|
||||||
Gtk::Window* main_window = NULL;
|
Gtk::Window* main_window = NULL;
|
||||||
_refXml->get_widget("MainWindow", main_window);
|
_refXml->get_widget("MainWindow", main_window);
|
||||||
return *main_window;
|
return *main_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
GuiBuilder::open_file(const std::string& filename)
|
GuiBuilder::open_file(const std::string& filename)
|
||||||
{
|
{
|
||||||
// FIXME: to be written.
|
// FIXME: to be written.
|
||||||
// Debug line (erase me when done):
|
// Debug line (erase me when done):
|
||||||
std::cout << _("Filename to open: ") << filename << std::endl;
|
std::cout << _("Filename to open: ") << filename << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,20 +31,21 @@
|
||||||
/** \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
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GuiBuilder(const std::string& gladefile = GLADEDIR "/main-window.glade");
|
GuiBuilder(const std::string& gladefile = GLADEDIR "/main-window.glade");
|
||||||
~GuiBuilder();
|
~GuiBuilder();
|
||||||
|
|
||||||
Gtk::Window& get_initial_window() const;
|
Gtk::Window& get_initial_window() const;
|
||||||
void open_file(const std::string& filename);
|
void open_file(const std::string& filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Glib::RefPtr<Gnome::Glade::Xml> _refXml;
|
Glib::RefPtr<Gnome::Glade::Xml> _refXml;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
||||||
|
|
|
@ -63,98 +63,98 @@ parse_options(int argc, char** argv)
|
||||||
no_gui.set_long_name("no-gui");
|
no_gui.set_long_name("no-gui");
|
||||||
policies_dir.set_long_name("policies-dir");
|
policies_dir.set_long_name("policies-dir");
|
||||||
modules_dir.set_long_name("modules_dir");
|
modules_dir.set_long_name("modules_dir");
|
||||||
filename.set_long_name(G_OPTION_REMAINING);
|
filename.set_long_name(G_OPTION_REMAINING);
|
||||||
|
|
||||||
no_gui.set_description(_("starts the program in command line mode"));
|
no_gui.set_description(_("starts the program in command line mode"));
|
||||||
policies_dir.set_description(_("adds this directory to the default modules search path"));
|
policies_dir.set_description(_("adds this directory to the default modules search path"));
|
||||||
modules_dir.set_description(_("adds this directory to default plugin search path"));
|
modules_dir.set_description(_("adds this directory to default plugin search path"));
|
||||||
filename.set_description(_("a list of savefiles; only the first will be opened"));
|
filename.set_description(_("a list of savefiles; only the first will be opened"));
|
||||||
|
|
||||||
// Places where araguments will be saved
|
// Places where araguments will be saved
|
||||||
bool no_gui_enabled = false;
|
bool no_gui_enabled = false;
|
||||||
OptionGroup::vecustrings policies_dir_val;
|
OptionGroup::vecustrings policies_dir_val;
|
||||||
OptionGroup::vecustrings modules_dir_val;
|
OptionGroup::vecustrings modules_dir_val;
|
||||||
OptionGroup::vecstrings fnames;
|
OptionGroup::vecstrings fnames;
|
||||||
|
|
||||||
no_gui.set_flags(OptionEntry::FLAG_NO_ARG);
|
no_gui.set_flags(OptionEntry::FLAG_NO_ARG);
|
||||||
filename.set_flags(OptionEntry::FLAG_FILENAME | OptionEntry::FLAG_OPTIONAL_ARG);
|
filename.set_flags(OptionEntry::FLAG_FILENAME | OptionEntry::FLAG_OPTIONAL_ARG);
|
||||||
|
|
||||||
// Create the only group
|
// Create the only group
|
||||||
OptionGroup group("options", "options");
|
OptionGroup group("options", "options");
|
||||||
|
|
||||||
group.add_entry(no_gui, no_gui_enabled);
|
group.add_entry(no_gui, no_gui_enabled);
|
||||||
group.add_entry(policies_dir, policies_dir_val);
|
group.add_entry(policies_dir, policies_dir_val);
|
||||||
group.add_entry(modules_dir, modules_dir_val);
|
group.add_entry(modules_dir, modules_dir_val);
|
||||||
group.add_entry_filename(filename, fnames);
|
group.add_entry_filename(filename, fnames);
|
||||||
|
|
||||||
// Create context
|
// Create context
|
||||||
OptionContext context(_("SGPEMv2, a graphical simulator for process "
|
OptionContext context(_("SGPEMv2, a graphical simulator for process "
|
||||||
"scheduling in a multitasking computer"));
|
"scheduling in a multitasking computer"));
|
||||||
|
|
||||||
context.set_main_group(group);
|
context.set_main_group(group);
|
||||||
context.set_help_enabled(true);
|
context.set_help_enabled(true);
|
||||||
context.set_ignore_unknown_options(false);
|
context.set_ignore_unknown_options(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Parse options, initialising the Gtk::Main at the same time
|
// Parse options, initialising the Gtk::Main at the same time
|
||||||
Gtk::Main main_loop(argc, argv, context);
|
Gtk::Main main_loop(argc, argv, context);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
// Now that GlobalPreferences has been initialized properly,
|
// Now that GlobalPreferences has been initialized properly,
|
||||||
// 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
|
||||||
// of sgpemv2
|
// of sgpemv2
|
||||||
TextSimulation sim;
|
TextSimulation sim;
|
||||||
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);
|
||||||
std::cout << std::endl << "% ";
|
std::cout << std::endl << "% ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,12 @@ using namespace sgpem;
|
||||||
|
|
||||||
|
|
||||||
SchedulablesWidget::SchedulablesWidget()
|
SchedulablesWidget::SchedulablesWidget()
|
||||||
: Glib::ObjectBase("sgpem_SchedulablesWidget"), CairoWidget()
|
: Glib::ObjectBase("sgpem_SchedulablesWidget"), CairoWidget()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SchedulablesWidget::~SchedulablesWidget()
|
SchedulablesWidget::~SchedulablesWidget()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -27,11 +27,11 @@
|
||||||
namespace memory
|
namespace memory
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct deletor : public std::unary_function<void, T*>
|
struct deletor : public std::unary_function<void, T*>
|
||||||
{
|
{
|
||||||
inline void operator()(T* o) { delete o; }
|
inline void operator()(T* o) { delete o; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} //~ namespace memory
|
} //~ namespace memory
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,90 +24,90 @@
|
||||||
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)
|
||||||
{
|
{
|
||||||
smart_ptr<ReadyQueue> sl = get_simulation_status_at(time);
|
smart_ptr<ReadyQueue> sl = get_simulation_status_at(time);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
bool invalid = sl == smart_ptr<ReadyQueue>();
|
bool invalid = sl == smart_ptr<ReadyQueue>();
|
||||||
for (uint i = 0; !found && !invalid && i < sl->size(); i++)
|
for (uint i = 0; !found && !invalid && i < sl->size(); i++)
|
||||||
{
|
{
|
||||||
const DynamicSchedulable* ss = sl->get_item_at(i);
|
const DynamicSchedulable* ss = sl->get_item_at(i);
|
||||||
if ((bool)ss && ss->get_state() == DynamicSchedulable::state_running)
|
if ((bool)ss && ss->get_state() == DynamicSchedulable::state_running)
|
||||||
{
|
{
|
||||||
scheduled_at = smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(ss)));
|
scheduled_at = smart_ptr<DynamicSchedulable>(new DynamicSchedulable(*(ss)));
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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>
|
||||||
(
|
(
|
||||||
new ReadyQueue
|
new ReadyQueue
|
||||||
(
|
(
|
||||||
*(_slice->get_simulation_status())
|
*(_slice->get_simulation_status())
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
|
|
@ -52,58 +52,58 @@
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
|
|
||||||
/** an History stub, should only save the last state included.
|
/** an History stub, should only save the last state included.
|
||||||
|
*/
|
||||||
|
class History : public ObservedSubject
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
/** Returns the DynamicSchedulable of the schedulable
|
||||||
|
* which was running at the time, if any.
|
||||||
*/
|
*/
|
||||||
class History : public ObservedSubject
|
memory::smart_ptr<sgpem::DynamicSchedulable>
|
||||||
{
|
get_scheduled_at(int time) const;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns the DynamicSchedulable of the schedulable
|
/** Returns the last recorded instant, but may raise an error.
|
||||||
* which was running at the time, if any.
|
*/
|
||||||
*/
|
memory::smart_ptr<sgpem::ReadyQueue>
|
||||||
memory::smart_ptr<sgpem::DynamicSchedulable>
|
get_simulation_status_at(int time) const;
|
||||||
get_scheduled_at(int time) const;
|
|
||||||
|
|
||||||
|
|
||||||
/** Returns the last recorded instant, but may raise an error.
|
/** Returns the total time recorded.
|
||||||
*/
|
*/
|
||||||
memory::smart_ptr<sgpem::ReadyQueue>
|
int
|
||||||
get_simulation_status_at(int time) const;
|
get_current_time() const;
|
||||||
|
|
||||||
|
|
||||||
/** Returns the total time recorded.
|
/** Extends the recorded history by one unit, overwriting the old value
|
||||||
*/
|
*/
|
||||||
int
|
void
|
||||||
get_current_time() const;
|
enqueue_slice(const sgpem::ReadyQueue& status);
|
||||||
|
|
||||||
|
|
||||||
/** Extends the recorded history by one unit, overwriting the old value
|
/** STUB: THIS FEATURE IS NOT AVAILABLE
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
enqueue_slice(const sgpem::ReadyQueue& status);
|
truncate_at(int instant);
|
||||||
|
|
||||||
|
|
||||||
/** STUB: THIS FEATURE IS NOT AVAILABLE
|
/** Returns the singleton instance.
|
||||||
*/
|
*/
|
||||||
void
|
static History&
|
||||||
truncate_at(int instant);
|
get_instance();
|
||||||
|
|
||||||
|
|
||||||
/** Returns the singleton instance.
|
private:
|
||||||
*/
|
History();
|
||||||
static History&
|
|
||||||
get_instance();
|
|
||||||
|
|
||||||
|
static History * _instance;
|
||||||
private:
|
int _total_time_elapsed;
|
||||||
History();
|
memory::smart_ptr<Slice> _slice;
|
||||||
|
};
|
||||||
static History * _instance;
|
|
||||||
int _total_time_elapsed;
|
|
||||||
memory::smart_ptr<Slice> _slice;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
} //~ namespace sgpem
|
} //~ namespace sgpem
|
||||||
|
|
|
@ -28,24 +28,24 @@ PolicyManager::PolicyManager()
|
||||||
PolicyManager&
|
PolicyManager&
|
||||||
PolicyManager::get_registered_manager()
|
PolicyManager::get_registered_manager()
|
||||||
{
|
{
|
||||||
if (_registered == NULL)
|
if (_registered == NULL)
|
||||||
_registered = new PolicyManager();
|
_registered = new PolicyManager();
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,29 +45,29 @@
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
/** A policyManager stub, provides access to the PRRPolicy.
|
/** A policyManager stub, provides access to the PRRPolicy.
|
||||||
*/
|
*/
|
||||||
class PolicyManager
|
class PolicyManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PolicyManager();
|
PolicyManager();
|
||||||
|
|
||||||
static PolicyManager&
|
static PolicyManager&
|
||||||
get_registered_manager();
|
get_registered_manager();
|
||||||
|
|
||||||
virtual Policy&
|
virtual Policy&
|
||||||
get_policy();
|
get_policy();
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
init();
|
init();
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
~PolicyManager();
|
~PolicyManager();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static PolicyManager* _registered;
|
static PolicyManager* _registered;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,97 +24,97 @@ using namespace sgpem;
|
||||||
|
|
||||||
PRRPolicy::PRRPolicy()
|
PRRPolicy::PRRPolicy()
|
||||||
{
|
{
|
||||||
_instance = this;
|
_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRRPolicy::PRRPolicy(int quantum)
|
PRRPolicy::PRRPolicy(int quantum)
|
||||||
: _quantum(quantum)
|
: _quantum(quantum)
|
||||||
{
|
{
|
||||||
_instance = this;
|
_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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++)
|
||||||
for (uint i = 0; i < local_sl->size() - 1; i++)
|
for (uint i = 0; i < local_sl->size() - 1; i++)
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
local_sl->get_item_at(i)->get_schedulable()->get_priority() >
|
local_sl->get_item_at(i)->get_schedulable()->get_priority() >
|
||||||
local_sl->get_item_at(i + 1)->get_schedulable()->get_priority()
|
local_sl->get_item_at(i + 1)->get_schedulable()->get_priority()
|
||||||
)
|
)
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
Policy*
|
Policy*
|
||||||
|
|
|
@ -48,81 +48,81 @@
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
{
|
{
|
||||||
/** An hard-coded Priority Round Robin policy
|
/** An hard-coded Priority Round Robin policy
|
||||||
* It's actually called PRRPolicy, altough my personal taste would have suggested
|
* It's actually called PRRPolicy, altough my personal taste would have suggested
|
||||||
* naming it
|
* naming it
|
||||||
* Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy,
|
* Prioriy-Reliant Roughly-Realized Recently-Reimplemented Round-Robin Policy,
|
||||||
* i.e. PRRRRRRR-Policy.
|
* i.e. PRRRRRRR-Policy.
|
||||||
* it adds a new constructor taking the quantum size (time slice)
|
* it adds a new constructor taking the quantum size (time slice)
|
||||||
*/
|
*/
|
||||||
class PRRPolicy : public Policy
|
class PRRPolicy : public Policy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PRRPolicy();
|
PRRPolicy();
|
||||||
|
|
||||||
PRRPolicy(int quantum);
|
PRRPolicy(int quantum);
|
||||||
|
|
||||||
static Policy&
|
static Policy&
|
||||||
get_instance();
|
get_instance();
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
~PRRPolicy();
|
~PRRPolicy();
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
configure()
|
configure()
|
||||||
throw(UserInterruptException);
|
throw(UserInterruptException);
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
sort_queue() const
|
sort_queue() const
|
||||||
throw(UserInterruptException);
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
activate();
|
activate();
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
deactivate();
|
deactivate();
|
||||||
|
|
||||||
|
|
||||||
virtual int
|
virtual int
|
||||||
get_id() const;
|
get_id() const;
|
||||||
|
|
||||||
virtual sgpem::policy_sorts_type
|
virtual sgpem::policy_sorts_type
|
||||||
wants() const
|
wants() const
|
||||||
throw(UserInterruptException);
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
|
||||||
virtual Glib::ustring
|
virtual Glib::ustring
|
||||||
get_name() const;
|
get_name() const;
|
||||||
|
|
||||||
virtual Glib::ustring
|
virtual Glib::ustring
|
||||||
get_description() const;
|
get_description() const;
|
||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
is_pre_emptive() const
|
is_pre_emptive() const
|
||||||
throw(UserInterruptException);
|
throw(UserInterruptException);
|
||||||
|
|
||||||
virtual int
|
virtual int
|
||||||
get_time_slice() const
|
get_time_slice() const
|
||||||
throw(UserInterruptException);
|
throw(UserInterruptException);
|
||||||
|
|
||||||
|
|
||||||
virtual PolicyParameters&
|
virtual PolicyParameters&
|
||||||
get_parameters();
|
get_parameters();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
PolicyParameters _parameters;
|
PolicyParameters _parameters;
|
||||||
int _id;
|
int _id;
|
||||||
int _quantum;
|
int _quantum;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static Policy* _instance;
|
static Policy* _instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,23 +43,23 @@ 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;
|
||||||
cout << "This test add modules directories (mod1 mod2 ...) and modules directories (mod1 mod2 ...)" << endl
|
cout << "This test add modules directories (mod1 mod2 ...) and modules directories (mod1 mod2 ...)" << endl
|
||||||
<< "to GlobalPreferences, write it to the configuration file " << gp.get_config_filename()
|
<< "to GlobalPreferences, write it to the configuration file " << gp.get_config_filename()
|
||||||
<< ", 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;
|
||||||
|
|
|
@ -42,13 +42,13 @@ 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)
|
||||||
{
|
{
|
||||||
cout << "Observer.update() : " << ++_i << endl;
|
cout << "Observer.update() : " << ++_i << endl;
|
||||||
}
|
}
|
||||||
unsigned int _i;
|
unsigned int _i;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProcessCreationData
|
struct ProcessCreationData
|
||||||
|
@ -96,16 +96,16 @@ 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,16 +119,16 @@ 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";
|
||||||
|
@ -178,95 +178,95 @@ main(int argc, char** argv)
|
||||||
info << "Attached to the history\n";
|
info << "Attached to the history\n";
|
||||||
|
|
||||||
const ProcessCreationData processes[2] =
|
const ProcessCreationData processes[2] =
|
||||||
{
|
{
|
||||||
{ "p1", 0, 3 },
|
{ "p1", 0, 3 },
|
||||||
{ "p2", 3, 1 }
|
{ "p2", 3, 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
DynamicProcess& p1 = h.add_process(processes[0].name,
|
DynamicProcess& p1 = h.add_process(processes[0].name,
|
||||||
processes[0].arrival_time,
|
processes[0].arrival_time,
|
||||||
processes[0].base_priority);
|
processes[0].base_priority);
|
||||||
|
|
||||||
DynamicProcess& p2 = h.add_process(processes[1].name,
|
DynamicProcess& p2 = h.add_process(processes[1].name,
|
||||||
processes[1].arrival_time,
|
processes[1].arrival_time,
|
||||||
processes[1].base_priority);
|
processes[1].base_priority);
|
||||||
|
|
||||||
const ThreadCreationData threads[4] =
|
const ThreadCreationData threads[4] =
|
||||||
{
|
{
|
||||||
{ "p2_1", &p2, 3, 0, 0 },
|
{ "p2_1", &p2, 3, 0, 0 },
|
||||||
{ "p1_1", &p1, 2, 0, 2 },
|
{ "p1_1", &p1, 2, 0, 2 },
|
||||||
{ "p1_2", &p1, 1, 1, 0 },
|
{ "p1_2", &p1, 1, 1, 0 },
|
||||||
{ "p2_2", &p2, 5, 3, 1 }
|
{ "p2_2", &p2, 5, 3, 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
DynamicThread& p2_1 = h.add_thread(threads[0].name,
|
DynamicThread& p2_1 = h.add_thread(threads[0].name,
|
||||||
*threads[0].parent,
|
*threads[0].parent,
|
||||||
threads[0].cpu_time,
|
threads[0].cpu_time,
|
||||||
threads[0].arrival_time,
|
threads[0].arrival_time,
|
||||||
threads[0].base_priority);
|
threads[0].base_priority);
|
||||||
|
|
||||||
DynamicThread& p1_1 = h.add_thread(threads[1].name,
|
DynamicThread& p1_1 = h.add_thread(threads[1].name,
|
||||||
*threads[1].parent,
|
*threads[1].parent,
|
||||||
threads[1].cpu_time,
|
threads[1].cpu_time,
|
||||||
threads[1].arrival_time,
|
threads[1].arrival_time,
|
||||||
threads[1].base_priority);
|
threads[1].base_priority);
|
||||||
|
|
||||||
DynamicThread& p1_2 = h.add_thread(threads[2].name,
|
DynamicThread& p1_2 = h.add_thread(threads[2].name,
|
||||||
*threads[2].parent,
|
*threads[2].parent,
|
||||||
threads[2].cpu_time,
|
threads[2].cpu_time,
|
||||||
threads[2].arrival_time,
|
threads[2].arrival_time,
|
||||||
threads[2].base_priority);
|
threads[2].base_priority);
|
||||||
|
|
||||||
DynamicThread& p2_2 = h.add_thread(threads[3].name,
|
DynamicThread& p2_2 = h.add_thread(threads[3].name,
|
||||||
*threads[3].parent,
|
*threads[3].parent,
|
||||||
threads[3].cpu_time,
|
threads[3].cpu_time,
|
||||||
threads[3].arrival_time,
|
threads[3].arrival_time,
|
||||||
threads[3].base_priority);
|
threads[3].base_priority);
|
||||||
|
|
||||||
const ResourceCreationData resources[2] =
|
const ResourceCreationData resources[2] =
|
||||||
{
|
{
|
||||||
{ "res1", true, 2, 0 },
|
{ "res1", true, 2, 0 },
|
||||||
{ "res2", false, 1, 0 }
|
{ "res2", false, 1, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const History::ResourcePair res1 = h.add_resource(resources[0].name,
|
const History::ResourcePair res1 = h.add_resource(resources[0].name,
|
||||||
resources[0].preemptable,
|
resources[0].preemptable,
|
||||||
resources[0].places,
|
resources[0].places,
|
||||||
resources[0].availability);
|
resources[0].availability);
|
||||||
|
|
||||||
const History::ResourcePair res2 = h.add_resource(resources[1].name,
|
const History::ResourcePair res2 = h.add_resource(resources[1].name,
|
||||||
resources[1].preemptable,
|
resources[1].preemptable,
|
||||||
resources[1].places,
|
resources[1].places,
|
||||||
resources[1].availability);
|
resources[1].availability);
|
||||||
|
|
||||||
const RequestCreationData requests[2] =
|
const RequestCreationData requests[2] =
|
||||||
{
|
{
|
||||||
{ &p1_2, 0 },
|
{ &p1_2, 0 },
|
||||||
{ &p2_1, 1 }
|
{ &p2_1, 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
DynamicRequest& req1 = h.add_request(*requests[0].owner, requests[0].instant);
|
DynamicRequest& req1 = h.add_request(*requests[0].owner, requests[0].instant);
|
||||||
|
|
||||||
DynamicRequest& req2 = h.add_request(*requests[1].owner, requests[1].instant);
|
DynamicRequest& req2 = h.add_request(*requests[1].owner, requests[1].instant);
|
||||||
|
|
||||||
const SubRequestCreationData subrequests[3] =
|
const SubRequestCreationData subrequests[3] =
|
||||||
{
|
{
|
||||||
{ &req1, res1.first, 1 },
|
{ &req1, res1.first, 1 },
|
||||||
{ &req2, res2.first, 2 },
|
{ &req2, res2.first, 2 },
|
||||||
{ &req2, res1.first, 1 }
|
{ &req2, res1.first, 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const DynamicSubRequest& sreq1 = h.add_subrequest(*subrequests[0].request,
|
const DynamicSubRequest& sreq1 = h.add_subrequest(*subrequests[0].request,
|
||||||
subrequests[0].resource_key,
|
subrequests[0].resource_key,
|
||||||
subrequests[0].duration);
|
subrequests[0].duration);
|
||||||
|
|
||||||
const DynamicSubRequest& sreq2 = h.add_subrequest(*subrequests[1].request,
|
const DynamicSubRequest& sreq2 = h.add_subrequest(*subrequests[1].request,
|
||||||
subrequests[1].resource_key,
|
subrequests[1].resource_key,
|
||||||
subrequests[1].duration);
|
subrequests[1].duration);
|
||||||
|
|
||||||
const DynamicSubRequest& sreq3 = h.add_subrequest(*subrequests[2].request,
|
const DynamicSubRequest& sreq3 = h.add_subrequest(*subrequests[2].request,
|
||||||
subrequests[2].resource_key,
|
subrequests[2].resource_key,
|
||||||
subrequests[2].duration);
|
subrequests[2].duration);
|
||||||
|
|
||||||
info << "Done adding required data by using the History factory interface\n";
|
info << "Done adding required data by using the History factory interface\n";
|
||||||
|
|
||||||
|
@ -290,11 +290,11 @@ main(int argc, char** argv)
|
||||||
// for(ReqIterator it = res1_queue.begin(); it != res1_queue.end(); ++it)
|
// for(ReqIterator it = res1_queue.begin(); it != res1_queue.end(); ++it)
|
||||||
// {
|
// {
|
||||||
// if(!res1_req1_match && *it == &req1)
|
// if(!res1_req1_match && *it == &req1)
|
||||||
// res1_req1_match = true;
|
// res1_req1_match = true;
|
||||||
// else if(!res1_req2_match && *it == &req2)
|
// else if(!res1_req2_match && *it == &req2)
|
||||||
// res1_req2_match == true;
|
// res1_req2_match == true;
|
||||||
// else
|
// else
|
||||||
// bad_match = true;
|
// bad_match = true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if(!res2_req1_match && *res2_queue.begin() == &req1)
|
// if(!res2_req1_match && *res2_queue.begin() == &req1)
|
||||||
|
@ -309,7 +309,7 @@ main(int argc, char** argv)
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// test << "FAIL";
|
// test << "FAIL";
|
||||||
test << endl;
|
test << endl;
|
||||||
|
|
||||||
|
|
||||||
ConcreteEnvironment* environment1 = new ConcreteEnvironment(environment);
|
ConcreteEnvironment* environment1 = new ConcreteEnvironment(environment);
|
||||||
|
@ -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,9 +362,9 @@ 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";
|
||||||
else
|
else
|
||||||
test << "FAIL";
|
test << "FAIL";
|
||||||
|
@ -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,56 +465,56 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
||||||
test << endl;
|
test << endl;
|
||||||
|
|
||||||
|
|
||||||
test << "Checking whether ConcreteHistory throws an exception if we try to use ";
|
test << "Checking whether ConcreteHistory throws an exception if we try to use ";
|
||||||
|
@ -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";
|
||||||
|
|
|
@ -31,31 +31,32 @@
|
||||||
// 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;
|
||||||
cout << "total number of parameters must be odd."
|
cout << "total number of parameters must be odd."
|
||||||
<< endl << endl;
|
<< endl << endl;
|
||||||
cout << "This test create a KeyFile object, fill it with all key/value pairs," << endl
|
cout << "This test create a KeyFile object, fill it with all key/value pairs," << endl
|
||||||
<< "write it to the file \"filename\", read it into a new KeyFile object" << endl
|
<< "write it to the file \"filename\", read it into a new KeyFile object" << endl
|
||||||
<< "and compare all readed values against original values." << endl << endl
|
<< "and compare all readed values against original values." << endl << endl
|
||||||
<< "If all key/values match the program print \"Test was successful\" and return 0." << endl
|
<< "If all key/values match the program print \"Test was successful\" and return 0." << endl
|
||||||
<< "If some key/values doesn't match the program print \"Test failed\" and return 1."
|
<< "If some key/values doesn't match the program print \"Test failed\" and return 1."
|
||||||
<< endl << endl;
|
<< endl << endl;
|
||||||
cout << "If there isn't any parameter or bad number of parameters return 2."
|
cout << "If there isn't any parameter or bad number of parameters return 2."
|
||||||
<< endl << endl;
|
<< endl << endl;
|
||||||
cout << "NOTE: 1) Test fails with invalid filenames or duplicated key in input."
|
cout << "NOTE: 1) Test fails with invalid filenames or duplicated key in input."
|
||||||
<< endl;
|
<< endl;
|
||||||
cout << " 2) File \"filename\" remains in current directory after test execution."
|
cout << " 2) File \"filename\" remains in current directory after test execution."
|
||||||
<< endl << endl;
|
<< endl << endl;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue