- partial update of serializer
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@756 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
09268f7fd4
commit
8894e31222
|
@ -47,7 +47,7 @@ void fillHistory(History &hist)
|
||||||
cout << "resource name: " << respair.second->get_name() << " key: " << respair.first << " places: " << respair.second->get_places() << endl;
|
cout << "resource name: " << respair.second->get_name() << " key: " << respair.first << " places: " << respair.second->get_places() << endl;
|
||||||
|
|
||||||
// add a process - name, arrival time, priority
|
// add a process - name, arrival time, priority
|
||||||
Process& p1 = hist.add_process(Glib::ustring("Process 1"), 5, 2); // name, arrival time, priority
|
Process& p1 = hist.add_process(Glib::ustring("Process 1"), 0, 2); // name, arrival time, priority
|
||||||
// and print his values
|
// and print his values
|
||||||
cout << "process name: " << p1.get_name() << " arrival_time: " << p1.get_arrival_time() << " base_priority: " << p1.get_base_priority() << endl;
|
cout << "process name: " << p1.get_name() << " arrival_time: " << p1.get_arrival_time() << " base_priority: " << p1.get_base_priority() << endl;
|
||||||
|
|
||||||
|
@ -62,12 +62,17 @@ void fillHistory(History &hist)
|
||||||
cout << "process name: " << p3.get_name() << " arrival_time: " << p3.get_arrival_time() << " base_priority: " << p3.get_base_priority() << endl;
|
cout << "process name: " << p3.get_name() << " arrival_time: " << p3.get_arrival_time() << " base_priority: " << p3.get_base_priority() << endl;
|
||||||
|
|
||||||
// add a thread - name, parent, cpu time, arrival time, priority
|
// add a thread - name, parent, cpu time, arrival time, priority
|
||||||
Thread& p1_t1 = hist.add_thread(Glib::ustring("Process 1 - Thread 1"), p1, 3, 2, 6);
|
Thread& p1_t1 = hist.add_thread(Glib::ustring("Process 1 - Thread 1"), p1, 8, 2, 6);
|
||||||
// and print his values
|
// and print his values
|
||||||
cout << "thread name: " << p1_t1.get_name() << " total_cpu_time: " << p1_t1.get_total_cpu_time() << " arrival_time: " << p1_t1.get_arrival_time() << " base_priority: " << p1_t1.get_base_priority() << endl;
|
cout << "thread name: " << p1_t1.get_name() << " total_cpu_time: " << p1_t1.get_total_cpu_time() << " arrival_time: " << p1_t1.get_arrival_time() << " base_priority: " << p1_t1.get_base_priority() << endl;
|
||||||
|
|
||||||
|
// add a thread - name, parent, cpu time, arrival time, priority
|
||||||
|
Thread& p1_t2 = hist.add_thread(Glib::ustring("Process 1 - Thread 2"), p1, 3, 3, 5);
|
||||||
|
// and print his values
|
||||||
|
cout << "thread name: " << p1_t2.get_name() << " total_cpu_time: " << p1_t2.get_total_cpu_time() << " arrival_time: " << p1_t2.get_arrival_time() << " base_priority: " << p1_t2.get_base_priority() << endl;
|
||||||
|
|
||||||
// add a request - Thread, time
|
// add a request - Thread, time
|
||||||
Request& req1 = hist.add_request(p1_t1, 7);
|
Request& req1 = hist.add_request(p1_t1, 3);
|
||||||
// and print his values
|
// and print his values
|
||||||
cout << "request arrival_time: " << req1.get_instant() << endl;
|
cout << "request arrival_time: " << req1.get_instant() << endl;
|
||||||
|
|
||||||
|
@ -79,8 +84,14 @@ void fillHistory(History &hist)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void showHistory(const History &hist)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void dumpEnvironment(const Environment& env)
|
void dumpEnvironment(const Environment& env)
|
||||||
{
|
{
|
||||||
|
cout << "dump environment start " <<endl;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -89,7 +100,7 @@ void dumpEnvironment(const Environment& env)
|
||||||
while(iter!=end)
|
while(iter!=end)
|
||||||
{
|
{
|
||||||
Process* p = (*iter);
|
Process* p = (*iter);
|
||||||
cout << "process name: " << p->get_name() << " arrival_time: " << p->get_arrival_time() << " base_priority: " << p->get_base_priority() << endl;
|
cout << " process name: " << p->get_name() << " arrival_time: " << p->get_arrival_time() << " base_priority: " << p->get_base_priority() << endl;
|
||||||
iter++;
|
iter++;
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,13 +112,43 @@ void dumpEnvironment(const Environment& env)
|
||||||
while(iter1!=end1)
|
while(iter1!=end1)
|
||||||
{
|
{
|
||||||
|
|
||||||
Thread* p = (*iter1);
|
Thread* t = (*iter1);
|
||||||
cout << "Thread name: " << p->get_name() << " arrival_time: " << p->get_arrival_time() << " base_priority: " << p->get_base_priority() << endl;
|
cout << " thread name: " << t->get_name() << " 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)
|
||||||
|
{
|
||||||
|
|
||||||
|
Request* r = (*iter2);
|
||||||
|
cout << " request arrival_time: " << r->get_instant() << endl;
|
||||||
|
|
||||||
|
typedef std::vector<SubRequest*> SubRequests;
|
||||||
|
typedef std::vector<SubRequest*>::const_iterator subreq_iterator;
|
||||||
|
const SubRequests& srvect = r->get_subrequests();
|
||||||
|
subreq_iterator iter3 = srvect.begin();
|
||||||
|
subreq_iterator end3 = srvect.end();
|
||||||
|
while(iter3!=end3)
|
||||||
|
{
|
||||||
|
|
||||||
|
SubRequest* sr = (*iter3);
|
||||||
|
cout << " sub request resource_key: " << sr->get_resource_key() << " places: " << sr->get_places() << " length: " << sr->get_length() << endl;
|
||||||
|
iter3++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
iter2++;
|
||||||
|
}
|
||||||
|
|
||||||
iter1++;
|
iter1++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
cout << "dump environment end " << endl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,14 +159,21 @@ main(int argc, char** argv)
|
||||||
|
|
||||||
ConcreteHistory hist;
|
ConcreteHistory hist;
|
||||||
|
|
||||||
|
cout << "fill history " << endl;
|
||||||
fillHistory(hist);
|
fillHistory(hist);
|
||||||
|
|
||||||
|
cout << "history " << endl;
|
||||||
const Environment& env = hist.get_last_environment();
|
const Environment& env = hist.get_last_environment();
|
||||||
dumpEnvironment(env);
|
dumpEnvironment(env);
|
||||||
|
|
||||||
XMLSerializer xmlser;
|
XMLSerializer xmlser;
|
||||||
xmlser.save_snapshot(Glib::ustring("xml-visit.xml"), hist);
|
xmlser.save_snapshot(Glib::ustring("xml-visit.xml"), hist);
|
||||||
|
|
||||||
|
ConcreteHistory hist2;
|
||||||
|
xmlser.restore_snapshot(Glib::ustring("xml-visit.xml"), hist2);
|
||||||
|
|
||||||
|
cout << "history2 - copy of history " << endl;
|
||||||
|
dumpEnvironment(hist2.get_last_environment());
|
||||||
|
|
||||||
// typedef std::vector<Process*> Processes;
|
// typedef std::vector<Process*> Processes;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -198,6 +198,25 @@ void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const Histor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XMLSerializer::clear_history(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)
|
||||||
|
{
|
||||||
|
xvisit.from_process(*(*iter));
|
||||||
|
pvect.
|
||||||
|
iter = pvect.begin();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact)
|
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -211,13 +230,13 @@ void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact)
|
||||||
throw SerializerError("Reading Error: xml doc is empty.");
|
throw SerializerError("Reading Error: xml doc is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "ROOT: " << root->name << endl;
|
// cout << "ROOT: " << root->name << endl;
|
||||||
|
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
cur = root->children;
|
cur = root->children;
|
||||||
while(cur!=NULL)
|
while(cur!=NULL)
|
||||||
{
|
{
|
||||||
cout << "NODE: " << cur->name << endl;
|
// cout << "NODE: " << cur->name << endl;
|
||||||
|
|
||||||
Glib::ustring name((const char *)cur->name);
|
Glib::ustring name((const char *)cur->name);
|
||||||
if(name=="resources")
|
if(name=="resources")
|
||||||
|
@ -239,25 +258,25 @@ XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
|
||||||
|
|
||||||
XMLSerializerFactory::Parameters* par=new XMLSerializerFactory::Parameters();
|
XMLSerializerFactory::Parameters* par=new XMLSerializerFactory::Parameters();
|
||||||
while (prop != NULL) {
|
while (prop != NULL) {
|
||||||
// cout << "PROP: " << prop->name;
|
// // cout << "PROP: " << prop->name;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
// cout << " VALUE: " << key;
|
// // cout << " VALUE: " << key;
|
||||||
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);
|
||||||
// c.insert(typename Cont::value_type(new_key, pos->second));
|
// c.insert(typename Cont::value_type(new_key, pos->second));
|
||||||
cout << " pair PROP: " << key_value.first << " VALUE: " << key_value.second << endl;
|
// cout << " pair PROP: " << key_value.first << " VALUE: " << key_value.second << endl;
|
||||||
|
|
||||||
xmlFree(key);
|
xmlFree(key);
|
||||||
}
|
}
|
||||||
else
|
// else
|
||||||
cout << " !VALUE IS NULL! ";
|
// cout << " !VALUE IS NULL! ";
|
||||||
}
|
}
|
||||||
cout << endl;
|
// cout << endl;
|
||||||
prop = prop->next;
|
prop = prop->next;
|
||||||
}
|
}
|
||||||
return par;
|
return par;
|
||||||
|
@ -272,7 +291,7 @@ void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFacto
|
||||||
Glib::ustring node_name((const char *)cur->name);
|
Glib::ustring node_name((const char *)cur->name);
|
||||||
if(node_name=="resource")
|
if(node_name=="resource")
|
||||||
{
|
{
|
||||||
cout << "NODE: " << cur->name << endl;
|
// cout << "read_resources NODE: " << cur->name << endl;
|
||||||
|
|
||||||
xmlAttrPtr prop = cur->properties;
|
xmlAttrPtr prop = cur->properties;
|
||||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||||
|
@ -288,34 +307,118 @@ void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFacto
|
||||||
}
|
}
|
||||||
void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact)
|
void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact)
|
||||||
{
|
{
|
||||||
|
if(schedulables_node==NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
cur = schedulables_node->children;
|
cur = schedulables_node->children;
|
||||||
while(cur!=NULL)
|
while(cur!=NULL)
|
||||||
{
|
{
|
||||||
cout << "NODE: " << cur->name << endl;
|
Glib::ustring node_name((const char *)cur->name);
|
||||||
|
if(node_name=="process")
|
||||||
|
{
|
||||||
|
// cout << "read_schedulables NODE: " << cur->name << endl;
|
||||||
|
|
||||||
xmlAttrPtr prop = cur->properties;
|
xmlAttrPtr prop = cur->properties;
|
||||||
while (prop != NULL) {
|
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||||
cout << "PROP: " << prop->name;
|
if(par!=NULL)
|
||||||
|
{
|
||||||
if(prop->children && xmlNodeIsText(prop->children)){
|
fact.factory_method(Glib::ustring("Process"), *par);
|
||||||
xmlChar *key = xmlNodeGetContent (prop->children);
|
|
||||||
// xmlChar *key = xmlNodeListGetString(doc, prop->children, 1);
|
|
||||||
if(key!=NULL)
|
|
||||||
{
|
|
||||||
cout << " VALUE: " << key;
|
|
||||||
xmlFree(key);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cout << " !VALUE IS NULL! ";
|
|
||||||
}
|
}
|
||||||
cout << endl;
|
// pass the "threads node"
|
||||||
prop = prop->next;
|
read_threads(cur->children, fact);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = cur->next;
|
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")
|
||||||
|
{
|
||||||
|
// cout << "read_threads NODE: " << cur->name << endl;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// cout << "read_requests NULL" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlNodePtr cur;
|
||||||
|
cur = requests_node->children;
|
||||||
|
while(cur!=NULL)
|
||||||
|
{
|
||||||
|
Glib::ustring node_name((const char *)cur->name);
|
||||||
|
if(node_name=="request")
|
||||||
|
{
|
||||||
|
// cout << "read_requests NODE: " << cur->name << endl;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
// cout << "read_subrequest NULL" << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlNodePtr cur;
|
||||||
|
cur = subrequest_node;
|
||||||
|
while(cur!=NULL)
|
||||||
|
{
|
||||||
|
Glib::ustring node_name((const char *)cur->name);
|
||||||
|
if(node_name=="subrequest")
|
||||||
|
{
|
||||||
|
// cout << "read_subrequest NODE: " << cur->name << endl;
|
||||||
|
|
||||||
|
xmlAttrPtr prop = cur->properties;
|
||||||
|
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||||
|
if(par!=NULL)
|
||||||
|
{
|
||||||
|
fact.factory_method(Glib::ustring("SubRequest"), *par);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* comment */
|
/* comment */
|
||||||
|
|
|
@ -52,9 +52,13 @@ namespace sgpem
|
||||||
void fill_resources(xmlNodePtr resources_node, const History& hist);
|
void fill_resources(xmlNodePtr resources_node, const History& hist);
|
||||||
void fill_schedulables(xmlNodePtr schedulables_node, const History& hist);
|
void fill_schedulables(xmlNodePtr schedulables_node, const History& hist);
|
||||||
|
|
||||||
|
void clear_history(History& hist);
|
||||||
void read_doc(xmlDocPtr doc, XMLSerializerFactory& fact);
|
void read_doc(xmlDocPtr doc, XMLSerializerFactory& fact);
|
||||||
void read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact);
|
void read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact);
|
||||||
void read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
void read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||||
|
void read_threads(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||||
|
void read_requests(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||||
|
void read_subrequests(xmlNodePtr schedulables_node, XMLSerializerFactory& fact);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,19 +58,27 @@ XMLSerializerFactory::factory_method(const Glib::ustring& class_name, 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
|
||||||
|
{
|
||||||
|
throw SerializerError("Factory for Unknown class: " + class_name + " doesn't exists.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLSerializerFactory::ResourcePair
|
History::ResourcePair
|
||||||
XMLSerializerFactory::create_resource(Parameters& parameters)
|
XMLSerializerFactory::create_resource(Parameters& parameters)
|
||||||
{
|
{
|
||||||
// if(_hist!=NULL)
|
// if(_hist!=NULL)
|
||||||
|
@ -81,6 +89,7 @@ XMLSerializerFactory::create_resource(Parameters& parameters)
|
||||||
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;
|
||||||
Parameters::iterator pos;
|
Parameters::iterator pos;
|
||||||
|
|
||||||
// read "name" property
|
// read "name" property
|
||||||
|
@ -93,6 +102,7 @@ XMLSerializerFactory::create_resource(Parameters& parameters)
|
||||||
pos = parameters.find(Glib::ustring("key"));
|
pos = parameters.find(Glib::ustring("key"));
|
||||||
if (pos != parameters.end()) {
|
if (pos != parameters.end()) {
|
||||||
key = pos->second;
|
key = pos->second;
|
||||||
|
string_to_int(key, old_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read "preemptable" property
|
// read "preemptable" property
|
||||||
|
@ -115,6 +125,7 @@ XMLSerializerFactory::create_resource(Parameters& parameters)
|
||||||
|
|
||||||
|
|
||||||
History::ResourcePair respair = _hist->add_resource(name, preemptable, how_many, arrival_time);
|
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));
|
||||||
|
|
||||||
return respair;
|
return respair;
|
||||||
}
|
}
|
||||||
|
@ -150,24 +161,115 @@ XMLSerializerFactory::create_process(Parameters& parameters)
|
||||||
string_to_int(pos->second, priority);
|
string_to_int(pos->second, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_last_process = &_hist->add_process(name, arrival_time, priority);
|
||||||
return _hist->add_process(Glib::ustring(name, arrival_time, priority);;
|
return *_last_process;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Thread&
|
Thread&
|
||||||
XMLSerializerFactory::create_thread(Parameters& parameters)
|
XMLSerializerFactory::create_thread(Parameters& parameters)
|
||||||
{
|
{
|
||||||
|
// if(_hist!=NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
Glib::ustring name;
|
||||||
|
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()) {
|
||||||
|
name = pos->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read "arrival-time" property
|
||||||
|
pos = parameters.find(Glib::ustring("arrival-time"));
|
||||||
|
if (pos != parameters.end()) {
|
||||||
|
string_to_int(pos->second, arrival_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read "priority" property
|
||||||
|
pos = parameters.find(Glib::ustring("priority"));
|
||||||
|
if (pos != parameters.end()) {
|
||||||
|
string_to_int(pos->second, priority);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read "priority" property
|
||||||
|
pos = parameters.find(Glib::ustring("lasts-for"));
|
||||||
|
if (pos != parameters.end()) {
|
||||||
|
string_to_int(pos->second, lasts_for);
|
||||||
|
}
|
||||||
|
|
||||||
|
_last_thread = &_hist->add_thread(name, *_last_process, lasts_for, arrival_time, priority);
|
||||||
|
return *_last_thread;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Request&
|
Request&
|
||||||
XMLSerializerFactory::create_request(Parameters& parameters)
|
XMLSerializerFactory::create_request(Parameters& parameters)
|
||||||
{
|
{
|
||||||
|
// if(_hist!=NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
int arrival_time=0;
|
||||||
|
Parameters::iterator pos;
|
||||||
|
|
||||||
|
// read "arrival-time" property
|
||||||
|
pos = parameters.find(Glib::ustring("arrival-time"));
|
||||||
|
if (pos != parameters.end()) {
|
||||||
|
string_to_int(pos->second, arrival_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
_last_request = &_hist->add_request(*_last_thread, arrival_time);
|
||||||
|
return *_last_request;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Subrequest&
|
SubRequest&
|
||||||
XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
||||||
{
|
{
|
||||||
|
// if(_hist!=NULL)
|
||||||
|
{
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
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()) {
|
||||||
|
//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()) {
|
||||||
|
string_to_int(pos->second, places);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read "priority" property
|
||||||
|
pos = parameters.find(Glib::ustring("lasts-for"));
|
||||||
|
if (pos != parameters.end()) {
|
||||||
|
string_to_int(pos->second, lasts_for);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _hist->add_subrequest(*_last_request, new_key, (History::time_t)lasts_for, (History::size_t)places);
|
||||||
|
}
|
||||||
|
// add a sub request - Request, resource_key, duration, places
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#define XML_SERIALIZER_FACTORY_HH 1
|
#define XML_SERIALIZER_FACTORY_HH 1
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
// #include "history.hh"
|
#include "history.hh"
|
||||||
#include "environment.hh"
|
#include "environment.hh"
|
||||||
|
|
||||||
#include <glibmm/ustring.h>
|
#include <glibmm/ustring.h>
|
||||||
|
@ -35,7 +35,7 @@ namespace sgpem
|
||||||
class Process;
|
class Process;
|
||||||
class Thread;
|
class Thread;
|
||||||
class Request;
|
class Request;
|
||||||
class Subrequest;
|
class SubRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace sgpem
|
namespace sgpem
|
||||||
|
@ -51,20 +51,35 @@ namespace sgpem
|
||||||
History* get_history();
|
History* get_history();
|
||||||
|
|
||||||
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;
|
||||||
//typedef const std::map<const Glib::ustring&, const Glib::ustring&> Parameters;
|
//NOUSE typedef const std::map<const Glib::ustring&, const Glib::ustring&> Parameters;
|
||||||
|
// associate old keys with new ones
|
||||||
typedef std::map<Glib::ustring, Glib::ustring> Parameters;
|
typedef std::map<Glib::ustring, Glib::ustring> Parameters;
|
||||||
|
|
||||||
|
// associate old keys with new ones
|
||||||
|
//typedef pair<resource_key_t, resource_key_t> TempPair;
|
||||||
|
typedef std::map<resource_key_t, resource_key_t> TempMap;
|
||||||
|
|
||||||
void factory_method(const Glib::ustring& class_name, Parameters& parameters);
|
void factory_method(const Glib::ustring& class_name, Parameters& parameters);
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
ResourcePair create_resource(Parameters& parameters);
|
History::ResourcePair create_resource(Parameters& parameters);
|
||||||
Process& create_process(Parameters& parameters);
|
Process& create_process(Parameters& parameters);
|
||||||
Thread& create_thread(Parameters& parameters);
|
Thread& create_thread(Parameters& parameters);
|
||||||
Request& create_request(Parameters& parameters);
|
Request& create_request(Parameters& parameters);
|
||||||
Subrequest& create_subrequest(Parameters& parameters);
|
SubRequest& create_subrequest(Parameters& parameters);
|
||||||
|
|
||||||
|
// history object to add to resources processes etc...
|
||||||
History* _hist;
|
History* _hist;
|
||||||
|
|
||||||
|
// memory of last objects to link to
|
||||||
|
Process* _last_process;
|
||||||
|
Thread* _last_thread;
|
||||||
|
Request* _last_request;
|
||||||
|
|
||||||
|
// take association with old keys an new keys
|
||||||
|
// to reslove sub requests
|
||||||
|
TempMap _temp_map;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj)
|
||||||
while(iter!=end)
|
while(iter!=end)
|
||||||
{
|
{
|
||||||
const SubRequest* sr = *iter;
|
const SubRequest* sr = *iter;
|
||||||
cout << "SUB REQUEST: " << sr->get_resource_key() << " places: " << sr->get_places() << " length: " << sr->get_length() << endl;
|
// cout << "SUB REQUEST: " << sr->get_resource_key() << " places: " << sr->get_places() << " length: " << sr->get_length() << endl;
|
||||||
from_subrequest(request_node, *(*iter));
|
from_subrequest(request_node, *(*iter));
|
||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue