- 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
108 changed files with 3196 additions and 3180 deletions
|
@ -26,29 +26,29 @@
|
|||
using namespace sgpem;
|
||||
|
||||
// Is this OK? If not, we must use a function with a local static variable...
|
||||
PythonCPUPolicyManager* _policy_manager = NULL;
|
||||
PythonCPUPolicyManager* _policy_manager = NULL;
|
||||
|
||||
void
|
||||
void
|
||||
sgpem__Plugin__on_init()
|
||||
{
|
||||
if(_policy_manager == NULL)
|
||||
if (_policy_manager == NULL)
|
||||
_policy_manager = new sgpem::PythonCPUPolicyManager();
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
sgpem__Plugin__on_exit()
|
||||
{
|
||||
delete _policy_manager;
|
||||
_policy_manager = NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
const char*
|
||||
sgpem__Plugin__describe()
|
||||
{
|
||||
return "This plugin manages policies written in the Python scripting language";
|
||||
}
|
||||
|
||||
const char*
|
||||
const char*
|
||||
sgpem__Plugin__get_name()
|
||||
{
|
||||
return "Pyloader";
|
||||
|
|
|
@ -39,9 +39,9 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
|
|||
PyObject* pUserCPUPolicyModule = PyImport_Import(pLoadmeStr);
|
||||
Py_DECREF(pLoadmeStr);
|
||||
|
||||
if(pUserCPUPolicyModule == NULL)
|
||||
if (pUserCPUPolicyModule == NULL)
|
||||
throw MalformedPolicyException(get_exception_information().c_str());
|
||||
|
||||
|
||||
// Dictionary with defined ``symbols'' for .pyc file
|
||||
_upolicy_dict = PyModule_GetDict(pUserCPUPolicyModule);
|
||||
assert(_upolicy_dict);
|
||||
|
@ -66,24 +66,24 @@ PythonCPUPolicy::PythonCPUPolicy(const char* name) throw(MalformedPolicyExceptio
|
|||
PyTuple_SetItem(pAdapterCtorParam, 0, pCPUPolicyClass);
|
||||
_adapter = PyInstance_New(pAdapterClass, pAdapterCtorParam, NULL);
|
||||
Py_DECREF(pAdapterCtorParam);
|
||||
|
||||
|
||||
Py_DECREF(pScriptAdapterModule);
|
||||
|
||||
if(_adapter == NULL)
|
||||
|
||||
if (_adapter == NULL)
|
||||
throw MalformedPolicyException(get_exception_information().c_str());
|
||||
|
||||
|
||||
// And now, who's your daddy, huh?
|
||||
}
|
||||
|
||||
|
||||
PythonCPUPolicy::~PythonCPUPolicy()
|
||||
{
|
||||
if(_adapter) Py_DECREF(_adapter);
|
||||
if (_adapter) Py_DECREF(_adapter);
|
||||
|
||||
// We keep this alive until dtor time, because
|
||||
// the user may have defined some static global-space
|
||||
// variables and they make use of them.
|
||||
if(_upolicy_dict) Py_DECREF(_upolicy_dict);
|
||||
if (_upolicy_dict) Py_DECREF(_upolicy_dict);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,7 +122,7 @@ PythonCPUPolicy::sort_queue() const throw(UserInterruptException)
|
|||
PyObject* retval = PyObject_CallMethod(_adapter, "async_sort_queue", NULL);
|
||||
|
||||
// Do minimal debugging
|
||||
if(!retval) PyErr_Print();
|
||||
if (!retval) PyErr_Print();
|
||||
else Py_DECREF(retval);
|
||||
|
||||
wait_unlock();
|
||||
|
@ -163,9 +163,9 @@ int
|
|||
PythonCPUPolicy::get_time_slice() const throw(UserInterruptException)
|
||||
{
|
||||
PyObject* retval = PyObject_CallMethod(_adapter, "async_get_time_slice", NULL);
|
||||
|
||||
|
||||
// Do minimal debugging
|
||||
if(!retval) PyErr_Print();
|
||||
if (!retval) PyErr_Print();
|
||||
else Py_DECREF(retval);
|
||||
|
||||
wait_unlock();
|
||||
|
@ -193,13 +193,13 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
|
|||
Py_UNBLOCK_THREADS;
|
||||
usleep(WAIT_FOR); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
|
||||
Py_BLOCK_THREADS;
|
||||
|
||||
|
||||
PyObject* retval = PyObject_CallMethod(_adapter, "mutex_test_lock", NULL);
|
||||
assert(retval);
|
||||
still_locked = PyObject_IsTrue(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);
|
||||
// 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 "
|
||||
"taking too long to terminate."));
|
||||
"taking too long to terminate."));
|
||||
}
|
||||
}
|
||||
while(still_locked);
|
||||
while (still_locked);
|
||||
|
||||
// What we should really do here:
|
||||
/* do {
|
||||
|
@ -234,9 +234,9 @@ PythonCPUPolicy::wait_unlock() const throw(UserInterruptException)
|
|||
string
|
||||
PythonCPUPolicy::get_exception_information()
|
||||
{
|
||||
if(PyErr_Occurred() == NULL)
|
||||
if (PyErr_Occurred() == NULL)
|
||||
return _("no error");
|
||||
|
||||
|
||||
PyObject* pType = NULL;
|
||||
PyObject* pValue = NULL;
|
||||
PyObject* pTraceback = NULL;
|
||||
|
@ -245,7 +245,7 @@ PythonCPUPolicy::get_exception_information()
|
|||
|
||||
string msg;
|
||||
|
||||
if(pValue != NULL)
|
||||
if (pValue != NULL)
|
||||
{
|
||||
PyObject* pValueStr = PyObject_Str(pValue);
|
||||
|
||||
|
@ -256,9 +256,9 @@ PythonCPUPolicy::get_exception_information()
|
|||
else
|
||||
msg = string(_("no available information for this error"));
|
||||
|
||||
if(pType != NULL) Py_DECREF(pType);
|
||||
if(pValue != NULL) Py_DECREF(pValue);
|
||||
if(pTraceback != NULL) Py_DECREF(pTraceback);
|
||||
if (pType != NULL) Py_DECREF(pType);
|
||||
if (pValue != NULL) Py_DECREF(pValue);
|
||||
if (pTraceback != NULL) Py_DECREF(pTraceback);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ PythonCPUPolicyManager::~PythonCPUPolicyManager()
|
|||
void
|
||||
PythonCPUPolicyManager::init()
|
||||
{
|
||||
if(_initialized)
|
||||
if (_initialized)
|
||||
// No-op
|
||||
return;
|
||||
|
||||
|
@ -114,35 +114,35 @@ PythonCPUPolicyManager::collect_policies()
|
|||
GlobalPreferences::dir_iterator dir_it = prefs.policies_dir_begin();
|
||||
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());
|
||||
|
||||
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... ";
|
||||
|
||||
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
|
||||
std::string policy_name = (*file_it).substr(0, (*file_it).size() - 3);
|
||||
|
||||
try
|
||||
{
|
||||
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
|
||||
{
|
||||
PythonCPUPolicy *pypolicy = new PythonCPUPolicy(policy_name.c_str());
|
||||
|
||||
_policies.push_back(pypolicy);
|
||||
}
|
||||
catch(MalformedPolicyException e)
|
||||
{
|
||||
std::cerr << "POLICY LOAD ERROR: " << e.what() << endl;
|
||||
}
|
||||
_policies.push_back(pypolicy);
|
||||
}
|
||||
catch (MalformedPolicyException e)
|
||||
{
|
||||
std::cerr << "POLICY LOAD ERROR: " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
cout << "no" << endl;
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace sgpem
|
|||
/** The selected and active PyhonCPUPolicy object. */
|
||||
void collect_policies();
|
||||
|
||||
private:
|
||||
private:
|
||||
PythonCPUPolicyManager(const PythonCPUPolicyManager&);
|
||||
PythonCPUPolicyManager& operator=(const PythonCPUPolicyManager&);
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ using namespace std;
|
|||
static CPUPolicy*
|
||||
find_pol_by_name(const vector<CPUPolicy*>& pols, const Glib::ustring& name)
|
||||
{
|
||||
vector<CPUPolicy*>::const_iterator it = pols.begin();
|
||||
for( ; it != pols.end(); it++)
|
||||
if((*it)->get_name() == name)
|
||||
return *it;
|
||||
return NULL;
|
||||
vector<CPUPolicy*>::const_iterator it = pols.begin();
|
||||
for ( ; it != pols.end(); it++)
|
||||
if ((*it)->get_name() == name)
|
||||
return *it;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -58,7 +58,7 @@ main(int argc, char** argv)
|
|||
{
|
||||
int successes = 0;
|
||||
|
||||
if(argc != 2)
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "[EE] Usage:\n\t" << argv[0] <<
|
||||
" path/to/uninstalled/test/policies" << std::endl;
|
||||
|
@ -72,29 +72,29 @@ main(int argc, char** argv)
|
|||
PythonCPUPolicyManager polman;
|
||||
polman.init();
|
||||
|
||||
Simulation& sim = Simulation::get_instance();
|
||||
History& his = sim.get_history();
|
||||
CPUPoliciesGatekeeper& pgk = CPUPoliciesGatekeeper::get_instance();
|
||||
Simulation& sim = Simulation::get_instance();
|
||||
History& his = sim.get_history();
|
||||
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
|
||||
cout << "These are the policies I found:" << endl;
|
||||
vector<CPUPolicy*>::const_iterator it = policies.begin();
|
||||
for(; it != policies.end(); it++)
|
||||
cout << "\t * " << (*it)->get_name() << endl;
|
||||
// Print out avail policies
|
||||
cout << "These are the policies I found:" << endl;
|
||||
vector<CPUPolicy*>::const_iterator it = policies.begin();
|
||||
for (; it != policies.end(); it++)
|
||||
cout << "\t * " << (*it)->get_name() << endl;
|
||||
|
||||
try
|
||||
{
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_configure");
|
||||
assert(pol != NULL);
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_configure");
|
||||
assert(pol != NULL);
|
||||
|
||||
// FIXME : Maybe activating a policy only to configure it is an overkill?
|
||||
// Who gives a fuck about it?
|
||||
// FIXME : Maybe activating a policy only to configure it is an overkill?
|
||||
// Who gives a fuck about it?
|
||||
pgk.activate_policy(&his, pol);
|
||||
pol->configure();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
catch (UserInterruptException e)
|
||||
{
|
||||
cout << "configure: Caught UserInterruptException" << endl;
|
||||
successes++;
|
||||
|
@ -103,12 +103,12 @@ main(int argc, char** argv)
|
|||
|
||||
try
|
||||
{
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
|
||||
assert(pol != NULL);
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_is_preemptive");
|
||||
assert(pol != NULL);
|
||||
pgk.activate_policy(&his, pol);
|
||||
pol->is_pre_emptive();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
catch (UserInterruptException e)
|
||||
{
|
||||
cout << "is_preemptive: Caught UserInterruptException" << endl;
|
||||
successes++;
|
||||
|
@ -117,12 +117,12 @@ main(int argc, char** argv)
|
|||
|
||||
try
|
||||
{
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
||||
assert(pol != NULL);
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
||||
assert(pol != NULL);
|
||||
pgk.activate_policy(&his, pol);
|
||||
pol->get_time_slice();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
catch (UserInterruptException e)
|
||||
{
|
||||
cout << "get_time_slice: Caught UserInterruptException" << endl;
|
||||
successes++;
|
||||
|
@ -132,12 +132,12 @@ main(int argc, char** argv)
|
|||
|
||||
try
|
||||
{
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
||||
assert(pol != NULL);
|
||||
CPUPolicy* pol = find_pol_by_name(policies, "python_loader_get_time_slice");
|
||||
assert(pol != NULL);
|
||||
pgk.activate_policy(&his, pol);
|
||||
pol->sort_queue();
|
||||
}
|
||||
catch(UserInterruptException e)
|
||||
catch (UserInterruptException e)
|
||||
{
|
||||
cout << "sort_queue: Caught UserInterruptException" << endl;
|
||||
successes++;
|
||||
|
|
|
@ -27,27 +27,27 @@ using namespace sgpem;
|
|||
|
||||
sgpem::XMLSerializer* _serializer = NULL;
|
||||
|
||||
void
|
||||
void
|
||||
sgpem__Plugin__on_init()
|
||||
{
|
||||
if(_serializer == NULL)
|
||||
if (_serializer == NULL)
|
||||
_serializer = new sgpem::XMLSerializer();
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
sgpem__Plugin__on_exit()
|
||||
{
|
||||
delete _serializer;
|
||||
_serializer = NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
const char*
|
||||
sgpem__Plugin__describe()
|
||||
{
|
||||
return "This plugin saves the simulation to an XML file";
|
||||
}
|
||||
|
||||
const char*
|
||||
const char*
|
||||
sgpem__Plugin__get_name()
|
||||
{
|
||||
return "XmlSave";
|
||||
|
|
|
@ -42,7 +42,7 @@ using namespace std;
|
|||
|
||||
/*
|
||||
* This program tests the XML serialization via the XMLSerializer class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
@ -62,13 +62,13 @@ main(int argc, char** argv)
|
|||
{
|
||||
// output file name
|
||||
Glib::ustring outfile("xml-visit.xml");
|
||||
|
||||
|
||||
// string stream to compare print dump of environment
|
||||
ostringstream os1;
|
||||
ostringstream os2;
|
||||
ostringstream os3;
|
||||
ostringstream os4;
|
||||
|
||||
|
||||
ConcreteHistory hist;
|
||||
cout << "create ConcreteHistory hist" << endl;
|
||||
|
||||
|
@ -90,38 +90,38 @@ main(int argc, char** argv)
|
|||
// add something other to history
|
||||
addSomethingHistory(hist);
|
||||
cout << "add other data to hist" << endl;
|
||||
|
||||
|
||||
// print on a string stream os2
|
||||
dumpEnvironment(hist.get_last_environment(), os2);
|
||||
os2 << ends; // null terminated string
|
||||
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;
|
||||
xmlser.restore_snapshot(outfile, hist2);
|
||||
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);
|
||||
os3 << ends; // null terminated string
|
||||
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);
|
||||
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);
|
||||
os4 << ends; // null terminated string
|
||||
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;
|
||||
if(os1.str()!=os2.str()
|
||||
&& os1.str()==os3.str()
|
||||
&& os1.str()==os4.str())
|
||||
if (os1.str() != os2.str()
|
||||
&& os1.str() == os3.str()
|
||||
&& os1.str() == os4.str())
|
||||
{
|
||||
cout << "test successful" << endl;
|
||||
ret = 0;
|
||||
|
@ -131,7 +131,7 @@ main(int argc, char** argv)
|
|||
cout << "test failed" << endl;
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,10 +145,10 @@ void fillHistory(History &hist)
|
|||
History::ResourcePair respair0 = hist.add_resource(Glib::ustring("Resource 0"), false, 1, 2);
|
||||
// add a resource - name, preemptable, places, availability
|
||||
History::ResourcePair respair00 = hist.add_resource(Glib::ustring("Resource 00"), false, 1, 2);
|
||||
|
||||
|
||||
// add a resource - name, preemptable, places, availability
|
||||
History::ResourcePair respair = hist.add_resource(Glib::ustring("Resource 1"), false, 1, 2);
|
||||
|
||||
|
||||
// add a resource - name, preemptable, places, availability
|
||||
History::ResourcePair respair2 = hist.add_resource(Glib::ustring("Invalid? Resource <n> 1"), false, 1, 2);
|
||||
// and print his values
|
||||
|
@ -201,32 +201,32 @@ void addSomethingHistory(History &hist)
|
|||
// print entire environment into the passed ostream
|
||||
void dumpEnvironment(const Environment& env, ostream &os)
|
||||
{
|
||||
os << "dump environment start " <<endl;
|
||||
os << "dump environment start " << endl;
|
||||
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
res_iterator riter = rvect.begin();
|
||||
while(riter!=rvect.end())
|
||||
while (riter != rvect.end())
|
||||
{
|
||||
Resource* r = (*riter).second;
|
||||
os << " resource name: " << r->get_name()
|
||||
/* << " key: " << (*riter).first */
|
||||
<< " places: " << r->get_places() << endl;
|
||||
/* << " key: " << (*riter).first */
|
||||
<< " places: " << r->get_places() << endl;
|
||||
riter++;
|
||||
}
|
||||
|
||||
|
||||
const Environment::Processes& pvect = env.get_processes();
|
||||
typedef std::vector<Process*>::const_iterator proc_iterator;
|
||||
|
||||
proc_iterator iter = pvect.begin();
|
||||
proc_iterator end = pvect.end();
|
||||
while(iter!=end)
|
||||
while (iter != end)
|
||||
{
|
||||
Process* p = (*iter);
|
||||
os << " process name: " << p->get_name()
|
||||
<< " arrival_time: " << p->get_arrival_time()
|
||||
<< " base_priority: " << p->get_base_priority() << endl;
|
||||
<< " arrival_time: " << p->get_arrival_time()
|
||||
<< " base_priority: " << p->get_base_priority() << endl;
|
||||
iter++;
|
||||
|
||||
typedef std::vector<Thread*> Threads;
|
||||
|
@ -234,20 +234,20 @@ void dumpEnvironment(const Environment& env, ostream &os)
|
|||
const Threads& tvect = p->get_threads();
|
||||
thr_iterator iter1 = tvect.begin();
|
||||
thr_iterator end1 = tvect.end();
|
||||
while(iter1!=end1)
|
||||
while (iter1 != end1)
|
||||
{
|
||||
|
||||
Thread* t = (*iter1);
|
||||
os << " thread name: " << t->get_name()
|
||||
<< " arrival_time: " << t->get_arrival_time()
|
||||
<< " base_priority: " << t->get_base_priority() << endl;
|
||||
<< " arrival_time: " << t->get_arrival_time()
|
||||
<< " base_priority: " << t->get_base_priority() << endl;
|
||||
|
||||
typedef std::vector<Request*> Requests;
|
||||
typedef std::vector<Request*>::const_iterator req_iterator;
|
||||
const Requests& rvect = t->get_requests();
|
||||
req_iterator iter2 = rvect.begin();
|
||||
req_iterator end2 = rvect.end();
|
||||
while(iter2!=end2)
|
||||
while (iter2 != end2)
|
||||
{
|
||||
|
||||
Request* r = (*iter2);
|
||||
|
@ -258,14 +258,15 @@ void dumpEnvironment(const Environment& env, ostream &os)
|
|||
const SubRequests& srvect = r->get_subrequests();
|
||||
subreq_iterator iter3 = srvect.begin();
|
||||
subreq_iterator end3 = srvect.end();
|
||||
while(iter3!=end3)
|
||||
while (iter3 != end3)
|
||||
{
|
||||
|
||||
SubRequest* sr = (*iter3);
|
||||
os << " sub request: " /* << " resource_key: " << 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,10 @@
|
|||
using namespace sgpem;
|
||||
|
||||
XMLSerializer::~XMLSerializer()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
XMLSerializer::XMLSerializer()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
@ -45,13 +43,14 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
|
|||
/* COMPAT: Do not genrate nodes for formatting spaces */
|
||||
LIBXML_TEST_VERSION
|
||||
xmlKeepBlanksDefault(0);
|
||||
|
||||
|
||||
xmlDocPtr doc;
|
||||
doc = xmlNewDoc((const xmlChar *)"1.0");
|
||||
if(doc!=NULL){
|
||||
if (doc != NULL)
|
||||
{
|
||||
fill_doc(doc, hist);
|
||||
int nwritten = xmlSaveFormatFile (filename.c_str(), doc, 1);
|
||||
if(nwritten<0)
|
||||
if (nwritten < 0)
|
||||
{
|
||||
throw SerializerError("Error writing xml doc to output stream.");
|
||||
}
|
||||
|
@ -60,48 +59,49 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
|
|||
{
|
||||
throw SerializerError("Internal Error creating xml doc.");
|
||||
}
|
||||
|
||||
|
||||
/* Clean up everything else before quitting. */
|
||||
xmlCleanupParser();
|
||||
}
|
||||
|
||||
void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError)
|
||||
{
|
||||
// TODO - all to do!!
|
||||
// DEBUG - remove me when finished
|
||||
// TODO - all to do!!
|
||||
// DEBUG - remove me when finished
|
||||
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
xmlDocPtr doc;
|
||||
|
||||
LIBXML_TEST_VERSION
|
||||
xmlKeepBlanksDefault(0);
|
||||
xmlDocPtr doc;
|
||||
|
||||
/*
|
||||
* build an XML tree from a the file;
|
||||
*/
|
||||
doc = xmlParseFile(filename.c_str());
|
||||
if (doc == NULL) {
|
||||
xmlCleanupParser();
|
||||
throw SerializerError("Parsing Error: doc is invalid.");
|
||||
}
|
||||
LIBXML_TEST_VERSION
|
||||
xmlKeepBlanksDefault(0);
|
||||
|
||||
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. */
|
||||
/*
|
||||
* build an XML tree from a the file;
|
||||
*/
|
||||
doc = xmlParseFile(filename.c_str());
|
||||
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();
|
||||
|
||||
#else
|
||||
/*
|
||||
* the library has been compiled without some of the old interfaces
|
||||
*/
|
||||
#error Compilation of LIBXML with SAX1 support must be enabled
|
||||
/*
|
||||
* the library has been compiled without some of the old interfaces
|
||||
*/
|
||||
#error Compilation of LIBXML with SAX1 support must be enabled
|
||||
#endif /* LIBXML_SAX1_ENABLED */
|
||||
}
|
||||
|
||||
|
@ -112,57 +112,57 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
|
|||
|
||||
const Glib::ustring XMLSerializer::get_filename_extension()
|
||||
{
|
||||
return Glib::ustring("xsgp");
|
||||
return Glib::ustring("xsgp");
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
xmlNodePtr root_node = NULL;/* node pointers */
|
||||
/*
|
||||
* Creates a new document, a node and set it as a root node
|
||||
*/
|
||||
root_node = xmlNewNode(NULL, (const xmlChar *) "sgpem");
|
||||
xmlDocSetRootElement(doc, root_node);
|
||||
xmlNodePtr root_node = NULL;/* node pointers */
|
||||
/*
|
||||
* Creates a new document, a node and set it as a root node
|
||||
*/
|
||||
root_node = xmlNewNode(NULL, (const xmlChar *) "sgpem");
|
||||
xmlDocSetRootElement(doc, root_node);
|
||||
|
||||
/*
|
||||
* Creates a DTD declaration. Isn't mandatory.
|
||||
*/
|
||||
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
|
||||
/*
|
||||
* Creates a DTD declaration. Isn't mandatory.
|
||||
*/
|
||||
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
|
||||
|
||||
XMLVisitor xvisit(root_node);
|
||||
xvisit.from_history(hist);
|
||||
/*
|
||||
//
|
||||
// xmlNewChild() creates a new node, which is "attached" as child node
|
||||
// of root_node node.
|
||||
//
|
||||
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
|
||||
//
|
||||
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
|
||||
XMLVisitor xvisit(root_node);
|
||||
xvisit.from_history(hist);
|
||||
/*
|
||||
//
|
||||
// xmlNewChild() creates a new node, which is "attached" as child node
|
||||
// of root_node node.
|
||||
//
|
||||
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
|
||||
//
|
||||
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
|
||||
|
||||
fill_resources(resources_node, hist);
|
||||
fill_schedulables(schedulables_node, hist);
|
||||
*/
|
||||
fill_resources(resources_node, hist);
|
||||
fill_schedulables(schedulables_node, hist);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
void XMLSerializer::fill_resources(xmlNodePtr resources_node, const History& hist)
|
||||
{
|
||||
|
||||
|
||||
|
||||
const Environment& env = hist.get_last_environment();
|
||||
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
|
||||
res_iterator iter = rvect.begin();
|
||||
res_iterator end = rvect.end();
|
||||
while(iter!=end)
|
||||
|
@ -177,13 +177,13 @@ void XMLSerializer::fill_resources(xmlNodePtr resources_node, const History& his
|
|||
|
||||
void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const History& hist)
|
||||
{
|
||||
|
||||
|
||||
|
||||
const Environment& env = hist.get_last_environment();
|
||||
|
||||
const Environment::Processes& pvect = env.get_processes();
|
||||
typedef std::vector<Process*>::const_iterator proc_iterator;
|
||||
|
||||
|
||||
proc_iterator iter = pvect.begin();
|
||||
proc_iterator end = pvect.end();
|
||||
while(iter!=end)
|
||||
|
@ -198,71 +198,74 @@ void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const Histor
|
|||
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();
|
||||
typedef std::vector<Process*>::const_iterator proc_iterator;
|
||||
|
||||
proc_iterator iter = pvect.begin();
|
||||
while(iter!=pvect.end())
|
||||
{
|
||||
hist.remove(*(*iter));
|
||||
iter = pvect.begin();
|
||||
}
|
||||
const Environment::Processes& pvect = env.get_processes();
|
||||
typedef std::vector<Process*>::const_iterator proc_iterator;
|
||||
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
res_iterator riter = rvect.begin();
|
||||
while(riter!=rvect.end())
|
||||
{
|
||||
hist.remove((*riter).first);
|
||||
riter = rvect.begin();
|
||||
}
|
||||
proc_iterator iter = pvect.begin();
|
||||
while (iter != pvect.end())
|
||||
{
|
||||
hist.remove(*(*iter));
|
||||
iter = pvect.begin();
|
||||
}
|
||||
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
res_iterator riter = rvect.begin();
|
||||
while (riter != rvect.end())
|
||||
{
|
||||
hist.remove((*riter).first);
|
||||
riter = rvect.begin();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError)
|
||||
{
|
||||
/*
|
||||
* Check the document is of the right kind
|
||||
*/
|
||||
xmlNodePtr root;
|
||||
root = xmlDocGetRootElement(doc);
|
||||
if (root == NULL) {
|
||||
xmlFreeDoc(doc);
|
||||
xmlCleanupParser();
|
||||
throw SerializerError("Reading Error: xml doc is empty.");
|
||||
}
|
||||
/*
|
||||
* Check the document is of the right kind
|
||||
*/
|
||||
xmlNodePtr root;
|
||||
root = xmlDocGetRootElement(doc);
|
||||
if (root == NULL)
|
||||
{
|
||||
xmlFreeDoc(doc);
|
||||
xmlCleanupParser();
|
||||
throw SerializerError("Reading Error: xml doc is empty.");
|
||||
}
|
||||
|
||||
xmlNodePtr cur;
|
||||
cur = root->children;
|
||||
while(cur!=NULL)
|
||||
xmlNodePtr cur;
|
||||
cur = root->children;
|
||||
while (cur != NULL)
|
||||
{
|
||||
Glib::ustring name((const char *)cur->name);
|
||||
if (name == "resources")
|
||||
{
|
||||
Glib::ustring name((const char *)cur->name);
|
||||
if(name=="resources")
|
||||
{
|
||||
read_resources(cur, fact);
|
||||
}
|
||||
if(name=="schedulables")
|
||||
{
|
||||
read_schedulables(cur, fact);
|
||||
}
|
||||
cur = cur->next;
|
||||
read_resources(cur, fact);
|
||||
}
|
||||
if (name == "schedulables")
|
||||
{
|
||||
read_schedulables(cur, fact);
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
|
||||
{
|
||||
if(prop==NULL)
|
||||
if (prop == NULL)
|
||||
return NULL;
|
||||
|
||||
XMLSerializerFactory::Parameters* par=new XMLSerializerFactory::Parameters();
|
||||
while (prop != NULL) {
|
||||
if(prop->children && xmlNodeIsText(prop->children)){
|
||||
|
||||
XMLSerializerFactory::Parameters* par = new XMLSerializerFactory::Parameters();
|
||||
while (prop != NULL)
|
||||
{
|
||||
if (prop->children && xmlNodeIsText(prop->children))
|
||||
{
|
||||
xmlChar *key = xmlNodeGetContent (prop->children);
|
||||
// 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));
|
||||
par->insert(key_value);
|
||||
|
@ -276,129 +279,129 @@ XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
|
|||
|
||||
void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
xmlNodePtr cur;
|
||||
cur = resources_node->children;
|
||||
while(cur!=NULL)
|
||||
xmlNodePtr cur;
|
||||
cur = resources_node->children;
|
||||
while (cur != NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if (node_name == "resource")
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="resource")
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||
if (par != NULL)
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
{
|
||||
fact.factory_method(Glib::ustring("Resource"), *par);
|
||||
}
|
||||
// fact.create_resource(*par);
|
||||
fact.factory_method(Glib::ustring("Resource"), *par);
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
// fact.create_resource(*par);
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
if(schedulables_node==NULL)
|
||||
return;
|
||||
|
||||
xmlNodePtr cur;
|
||||
cur = schedulables_node->children;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="process")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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);
|
||||
}
|
||||
if (schedulables_node == NULL)
|
||||
return;
|
||||
|
||||
cur = cur->next;
|
||||
xmlNodePtr cur;
|
||||
cur = schedulables_node->children;
|
||||
while (cur != NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if (node_name == "process")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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);
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLSerializer::read_threads(xmlNodePtr threads_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
if(threads_node==NULL)
|
||||
return;
|
||||
|
||||
xmlNodePtr cur;
|
||||
cur = threads_node->children;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="thread")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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);
|
||||
}
|
||||
if (threads_node == NULL)
|
||||
return;
|
||||
|
||||
cur = cur->next;
|
||||
xmlNodePtr cur;
|
||||
cur = threads_node->children;
|
||||
while (cur != NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if (node_name == "thread")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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);
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
if(requests_node==NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
xmlNodePtr cur;
|
||||
cur = requests_node->children;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="request")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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);
|
||||
}
|
||||
if (requests_node == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
xmlNodePtr cur;
|
||||
cur = requests_node->children;
|
||||
while (cur != NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if (node_name == "request")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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);
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLSerializer::read_subrequests(xmlNodePtr subrequest_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
if(subrequest_node==NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
xmlNodePtr cur;
|
||||
cur = subrequest_node;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="subrequest")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
{
|
||||
fact.factory_method(Glib::ustring("SubRequest"), *par);
|
||||
}
|
||||
}
|
||||
if (subrequest_node == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
xmlNodePtr cur;
|
||||
cur = subrequest_node;
|
||||
while (cur != NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if (node_name == "subrequest")
|
||||
{
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par = read_properties(prop);
|
||||
if (par != NULL)
|
||||
{
|
||||
fact.factory_method(Glib::ustring("SubRequest"), *par);
|
||||
}
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* comment */
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace sgpem
|
|||
then calls fill_resources and fill_schedulables to fill all with data.
|
||||
*/
|
||||
void fill_doc(xmlDocPtr doc, const History& hist);
|
||||
|
||||
|
||||
/**
|
||||
\brief Take a resources node and fill it with the data
|
||||
|
||||
|
@ -100,7 +100,7 @@ namespace sgpem
|
|||
Uses an XMLVisitor object to do the task.
|
||||
*/
|
||||
// void fill_resources(xmlNodePtr resources_node, const History& hist);
|
||||
|
||||
|
||||
/**
|
||||
\brief Take a schedulables node and fill it with the data
|
||||
|
||||
|
@ -125,7 +125,7 @@ namespace sgpem
|
|||
rebuild the correct image using the XMLSerializerFactory object.
|
||||
*/
|
||||
void read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError);
|
||||
|
||||
|
||||
/**
|
||||
\brief Restore all the resources from the passed xml node
|
||||
|
||||
|
@ -134,7 +134,7 @@ namespace sgpem
|
|||
object.
|
||||
*/
|
||||
void read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact);
|
||||
|
||||
|
||||
/**
|
||||
\brief Restore all the schedulables (processes) from the passed xml node
|
||||
|
||||
|
@ -143,7 +143,7 @@ namespace sgpem
|
|||
XMLSerializerFactory object.
|
||||
*/
|
||||
void read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||
|
||||
|
||||
/**
|
||||
\brief Restore all threads from the passed xml node
|
||||
|
||||
|
@ -152,7 +152,7 @@ namespace sgpem
|
|||
XMLSerializerFactory object.
|
||||
*/
|
||||
void read_threads(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||
|
||||
|
||||
/**
|
||||
\brief Restore all the requests from the passed xml node
|
||||
|
||||
|
@ -161,7 +161,7 @@ namespace sgpem
|
|||
XMLSerializerFactory object.
|
||||
*/
|
||||
void read_requests(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||
|
||||
|
||||
/**
|
||||
\brief Restore all the subrequests from the passed xml node
|
||||
|
||||
|
|
|
@ -35,13 +35,11 @@ using namespace std;
|
|||
|
||||
|
||||
XMLSerializerFactory::XMLSerializerFactory(History& hist)
|
||||
: _hist(&hist)
|
||||
{
|
||||
}
|
||||
: _hist(&hist)
|
||||
{}
|
||||
|
||||
XMLSerializerFactory::~XMLSerializerFactory()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
History* XMLSerializerFactory::get_history()
|
||||
{
|
||||
|
@ -51,27 +49,27 @@ History* XMLSerializerFactory::get_history()
|
|||
void
|
||||
XMLSerializerFactory::factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializerError)
|
||||
{
|
||||
if(class_name == "Resource")
|
||||
if (class_name == "Resource")
|
||||
{
|
||||
create_resource(parameters);
|
||||
}
|
||||
else if(class_name == "Process")
|
||||
else if (class_name == "Process")
|
||||
{
|
||||
create_process(parameters);
|
||||
}
|
||||
else if(class_name == "Thread")
|
||||
else if (class_name == "Thread")
|
||||
{
|
||||
create_thread(parameters);
|
||||
}
|
||||
else if(class_name == "Request")
|
||||
else if (class_name == "Request")
|
||||
{
|
||||
create_request(parameters);
|
||||
}
|
||||
else if(class_name == "SubRequest")
|
||||
else if (class_name == "SubRequest")
|
||||
{
|
||||
create_subrequest(parameters);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
throw SerializerError("Factory for Unknown class: " + class_name + " doesn't exists.");
|
||||
}
|
||||
|
@ -85,48 +83,53 @@ XMLSerializerFactory::create_resource(Parameters& parameters)
|
|||
|
||||
Glib::ustring name;
|
||||
Glib::ustring key("0");
|
||||
int arrival_time=0;
|
||||
int how_many=1;
|
||||
bool preemptable=false;
|
||||
int arrival_time = 0;
|
||||
int how_many = 1;
|
||||
bool preemptable = false;
|
||||
int old_key;
|
||||
Parameters::iterator pos;
|
||||
|
||||
|
||||
// read "name" property
|
||||
pos = parameters.find(Glib::ustring("name"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
name = pos->second;
|
||||
}
|
||||
|
||||
// read "key" property
|
||||
pos = parameters.find(Glib::ustring("id"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
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);
|
||||
string_to_int(key, old_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// read "preemptable" property
|
||||
pos = parameters.find(Glib::ustring("preemptable"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
preemptable = (pos->second == "true");
|
||||
}
|
||||
|
||||
|
||||
// read "arrival-time" property
|
||||
pos = parameters.find(Glib::ustring("arrival-time"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, arrival_time);
|
||||
}
|
||||
|
||||
|
||||
// read "how-many" property
|
||||
pos = parameters.find(Glib::ustring("how-many"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, how_many);
|
||||
}
|
||||
|
||||
|
||||
|
||||
History::ResourcePair respair = _hist->add_resource(name, preemptable, how_many, arrival_time);
|
||||
_temp_map.insert(TempMap::value_type((resource_key_t)old_key, respair.first));
|
||||
|
||||
|
@ -142,25 +145,28 @@ XMLSerializerFactory::create_process(Parameters& parameters)
|
|||
{
|
||||
|
||||
Glib::ustring name;
|
||||
int arrival_time=0;
|
||||
int priority=1;
|
||||
int arrival_time = 0;
|
||||
int priority = 1;
|
||||
Parameters::iterator pos;
|
||||
|
||||
|
||||
// read "name" property
|
||||
pos = parameters.find(Glib::ustring("name"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
name = pos->second;
|
||||
}
|
||||
|
||||
// read "arrival-time" property
|
||||
pos = parameters.find(Glib::ustring("arrival-time"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, arrival_time);
|
||||
}
|
||||
|
||||
|
||||
// read "priority" property
|
||||
pos = parameters.find(Glib::ustring("priority"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, priority);
|
||||
}
|
||||
|
||||
|
@ -178,32 +184,36 @@ XMLSerializerFactory::create_thread(Parameters& parameters)
|
|||
{
|
||||
|
||||
Glib::ustring name;
|
||||
int arrival_time=0;
|
||||
int lasts_for=0;
|
||||
int priority=1;
|
||||
int arrival_time = 0;
|
||||
int lasts_for = 0;
|
||||
int priority = 1;
|
||||
Parameters::iterator pos;
|
||||
|
||||
|
||||
// read "name" property
|
||||
pos = parameters.find(Glib::ustring("name"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
name = pos->second;
|
||||
}
|
||||
|
||||
// read "arrival-time" property
|
||||
pos = parameters.find(Glib::ustring("arrival-delta"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, arrival_time);
|
||||
}
|
||||
|
||||
|
||||
// read "priority" property
|
||||
pos = parameters.find(Glib::ustring("priority"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, priority);
|
||||
}
|
||||
|
||||
// read "priority" property
|
||||
pos = parameters.find(Glib::ustring("lasts-for"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, lasts_for);
|
||||
}
|
||||
|
||||
|
@ -218,12 +228,13 @@ XMLSerializerFactory::create_request(Parameters& parameters)
|
|||
// if(_hist!=NULL)
|
||||
{
|
||||
|
||||
int arrival_time=0;
|
||||
int arrival_time = 0;
|
||||
Parameters::iterator pos;
|
||||
|
||||
// read "arrival-time" property
|
||||
pos = parameters.find(Glib::ustring("arrival-time"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, arrival_time);
|
||||
}
|
||||
|
||||
|
@ -238,26 +249,28 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
|||
// if(_hist!=NULL)
|
||||
{
|
||||
|
||||
int old_key=0;
|
||||
int lasts_for=0;
|
||||
int old_key = 0;
|
||||
int lasts_for = 0;
|
||||
//int places=1;
|
||||
Parameters::iterator pos;
|
||||
resource_key_t new_key = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
// read "arrival-time" property
|
||||
pos = parameters.find(Glib::ustring("resource"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, old_key);
|
||||
|
||||
|
||||
TempMap::iterator temp_pos;
|
||||
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
|
||||
new_key = temp_pos->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// read "priority" property
|
||||
//pos = parameters.find(Glib::ustring("how-many"));
|
||||
//if (pos != parameters.end()) {
|
||||
|
@ -266,7 +279,8 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
|||
|
||||
// read "priority" property
|
||||
pos = parameters.find(Glib::ustring("lasts-for"));
|
||||
if (pos != parameters.end()) {
|
||||
if (pos != parameters.end())
|
||||
{
|
||||
string_to_int(pos->second, lasts_for);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,12 @@ namespace sgpem
|
|||
{
|
||||
public:
|
||||
typedef std::map<Glib::ustring, Glib::ustring> Parameters;
|
||||
|
||||
|
||||
/**
|
||||
\brief Contructor takes an history as readed data destination
|
||||
*/
|
||||
XMLSerializerFactory(History& hist);
|
||||
|
||||
|
||||
/**
|
||||
\brief A destructor, nothing else
|
||||
*/
|
||||
|
@ -83,22 +83,22 @@ namespace sgpem
|
|||
typedef Environment::resource_key_t resource_key_t;
|
||||
// associate old keys with new ones
|
||||
typedef std::map<resource_key_t, resource_key_t> TempMap;
|
||||
|
||||
|
||||
/**
|
||||
Resource factory from given parameters
|
||||
*/
|
||||
History::ResourcePair create_resource(Parameters& parameters);
|
||||
|
||||
|
||||
/**
|
||||
Process factory from given parameters
|
||||
*/
|
||||
Process& create_process(Parameters& parameters);
|
||||
|
||||
|
||||
/**
|
||||
Thread factory from given parameters
|
||||
*/
|
||||
Thread& create_thread(Parameters& parameters);
|
||||
|
||||
|
||||
/**
|
||||
Request factory from given parameters
|
||||
*/
|
||||
|
|
|
@ -36,19 +36,17 @@ using namespace sgpem;
|
|||
|
||||
|
||||
XMLVisitor::XMLVisitor(xmlNodePtr current)
|
||||
: _current(current)
|
||||
{
|
||||
}
|
||||
: _current(current)
|
||||
{}
|
||||
|
||||
XMLVisitor::~XMLVisitor()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
void XMLVisitor::from_resource(const Resource& obj) throw(SerializerError)
|
||||
{
|
||||
throw SerializerError(
|
||||
_("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)
|
||||
{
|
||||
if(parent!=NULL)
|
||||
if (parent != NULL)
|
||||
{
|
||||
from_environment(parent, hist.get_last_environment());
|
||||
from_environment(parent, hist.get_last_environment());
|
||||
}
|
||||
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)
|
||||
{
|
||||
if(parent==NULL)
|
||||
if (parent == NULL)
|
||||
{
|
||||
throw SerializerError(_("Error trying to add data to empty XML node."));
|
||||
}
|
||||
|
@ -124,10 +122,10 @@ void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) thr
|
|||
xmlNodePtr resources_node = xmlNewChild(parent, NULL, (const xmlChar *) "resources", NULL);
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
|
||||
res_iterator iter = rvect.begin();
|
||||
res_iterator end = rvect.end();
|
||||
while(iter!=end)
|
||||
while (iter != end)
|
||||
{
|
||||
//XMLVisitor xvisit(resources_node);
|
||||
Glib::ustring key;
|
||||
|
@ -144,10 +142,10 @@ void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) thr
|
|||
xmlNodePtr schedulables_node = xmlNewChild(parent, NULL, (const xmlChar *) "schedulables", NULL);
|
||||
const Environment::Processes& pvect = env.get_processes();
|
||||
typedef std::vector<Process*>::const_iterator proc_iterator;
|
||||
|
||||
|
||||
proc_iterator iter = pvect.begin();
|
||||
proc_iterator end = pvect.end();
|
||||
while(iter!=end)
|
||||
while (iter != end)
|
||||
{
|
||||
// XMLVisitor xvisit(schedulables_node);
|
||||
// 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)
|
||||
{
|
||||
if(parent!=NULL)
|
||||
if (parent != NULL)
|
||||
{
|
||||
Glib::ustring id = "reskey" + key;
|
||||
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)
|
||||
{
|
||||
if(parent!=NULL)
|
||||
if (parent != NULL)
|
||||
{
|
||||
Glib::ustring strPriority;
|
||||
Glib::ustring strArrivalTime;
|
||||
|
@ -205,10 +203,10 @@ void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj) throw(Seria
|
|||
const Threads& tvect = ((Process&)obj).get_threads();
|
||||
thr_iterator iter = tvect.begin();
|
||||
thr_iterator end = tvect.end();
|
||||
while(iter!=end)
|
||||
while (iter != end)
|
||||
{
|
||||
const Thread* t = *iter;
|
||||
|
||||
|
||||
from_thread(threads_node, *(*iter));
|
||||
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)
|
||||
{
|
||||
if(parent!=NULL)
|
||||
if (parent != NULL)
|
||||
{
|
||||
|
||||
Glib::ustring strPriority;
|
||||
|
@ -237,7 +235,7 @@ void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(Seriali
|
|||
xmlNewProp(thread_node, (const xmlChar *) "priority", (const xmlChar *) strPriority.c_str());
|
||||
xmlNewProp(thread_node, (const xmlChar *) "arrival-delta", (const xmlChar *) strArrivalTime.c_str());
|
||||
xmlNewProp(thread_node, (const xmlChar *) "lasts-for", (const xmlChar *) strLastsTime.c_str());
|
||||
|
||||
|
||||
// make a requests subnode
|
||||
xmlNodePtr requests_node = xmlNewChild(thread_node, NULL, (const xmlChar *) "requests", NULL);
|
||||
// iterate on requests
|
||||
|
@ -246,10 +244,10 @@ void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(Seriali
|
|||
const Requests& rvect = ((Thread&)obj).get_requests();
|
||||
req_iterator iter = rvect.begin();
|
||||
req_iterator end = rvect.end();
|
||||
while(iter!=end)
|
||||
while (iter != end)
|
||||
{
|
||||
const Request* r = *iter;
|
||||
|
||||
|
||||
from_request(requests_node, *(*iter));
|
||||
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)
|
||||
{
|
||||
if(parent!=NULL)
|
||||
if (parent != NULL)
|
||||
{
|
||||
|
||||
Glib::ustring strArrivalTime;
|
||||
|
@ -271,7 +269,7 @@ void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(Seria
|
|||
|
||||
xmlNodePtr request_node = xmlNewChild(parent, NULL, (const xmlChar *) "request", NULL);
|
||||
xmlNewProp(request_node, (const xmlChar *) "arrival-time", (const xmlChar *) strArrivalTime.c_str());
|
||||
|
||||
|
||||
// make a requests subnode
|
||||
// xmlNodePtr subrequests_node = xmlNewChild(thread_node, NULL, (const xmlChar *) "requests", NULL);
|
||||
// iterate on subrequests
|
||||
|
@ -280,7 +278,7 @@ void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(Seria
|
|||
const SubRequests& srvect = ((Request&)obj).get_subrequests();
|
||||
subreq_iterator iter = srvect.begin();
|
||||
subreq_iterator end = srvect.end();
|
||||
while(iter!=end)
|
||||
while (iter != end)
|
||||
{
|
||||
const SubRequest* sr = *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)
|
||||
{
|
||||
if(parent!=NULL)
|
||||
if (parent != NULL)
|
||||
{
|
||||
|
||||
Glib::ustring strResource;
|
||||
|
|
|
@ -83,39 +83,39 @@ namespace sgpem
|
|||
Throw an exception.
|
||||
*/
|
||||
virtual void from_resource(const Resource& obj) throw(SerializerError);
|
||||
|
||||
|
||||
/**
|
||||
\brief Add output to the serializer taking data from resource and key
|
||||
BUG FIXED: This save a resource with her own associated key.
|
||||
Wrapper method: call from_resource(xmlNodePtr parent, const Resource& obj, const Glib::ustring& key);
|
||||
*/
|
||||
virtual void from_resource(const Resource& obj, const Glib::ustring& key) throw(SerializerError);
|
||||
|
||||
|
||||
/**
|
||||
\brief Add output to the serializer taking data from process
|
||||
Wrapper method: call from_process(xmlNodePtr parent, const Process& obj);
|
||||
*/
|
||||
virtual void from_process(const Process& obj) throw(SerializerError);
|
||||
|
||||
|
||||
/**
|
||||
\brief Add output to the serializer taking data from thread
|
||||
Wrapper method: call from_thread(xmlNodePtr parent, const Thread& obj);
|
||||
*/
|
||||
virtual void from_thread(const Thread& obj) throw(SerializerError);
|
||||
|
||||
|
||||
/**
|
||||
\brief Add output to the serializer taking data from request
|
||||
Wrapper method: call from_request(xmlNodePtr parent, const Request& obj);
|
||||
*/
|
||||
virtual void from_request(const Request& obj) throw(SerializerError);
|
||||
|
||||
|
||||
/**
|
||||
\brief Add output to the serializer taking data from subrequest
|
||||
Wrapper method: call from_subrequest(xmlNodePtr parent, const SubRequest& obj);
|
||||
*/
|
||||
virtual void from_subrequest(const SubRequest& obj) throw(SerializerError);
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
void from_history(xmlNodePtr parent, const History& obj) throw(SerializerError);
|
||||
void from_environment(xmlNodePtr parent, const Environment& obj) throw(SerializerError);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue