2006-07-08 07:54:21 +02:00
|
|
|
// src/backend/serialize_visitor.cc - Copyright 2005, 2006, University
|
|
|
|
// of Padova, dept. of Pure and Applied
|
|
|
|
// Mathematics
|
|
|
|
//
|
|
|
|
// This file is part of SGPEMv2.
|
|
|
|
//
|
|
|
|
// This is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// SGPEMv2 is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with SGPEMv2; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
#include "xml_visitor.hh"
|
|
|
|
|
2006-07-15 03:28:35 +02:00
|
|
|
#include "gettext.h"
|
|
|
|
|
|
|
|
#include "environment.hh"
|
|
|
|
#include "history.hh"
|
2006-07-11 02:06:40 +02:00
|
|
|
#include "process.hh"
|
|
|
|
#include "request.hh"
|
2006-07-15 03:28:35 +02:00
|
|
|
#include "resource.hh"
|
2006-07-11 02:06:40 +02:00
|
|
|
#include "serializer_error.hh"
|
2006-07-15 03:28:35 +02:00
|
|
|
#include "string_utils.hh"
|
|
|
|
#include "sub_request.hh"
|
|
|
|
#include "thread.hh"
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
using namespace sgpem;
|
|
|
|
|
|
|
|
|
|
|
|
XMLVisitor::XMLVisitor(xmlNodePtr current)
|
|
|
|
: _current(current)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLVisitor::~XMLVisitor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void XMLVisitor::from_resource(const Resource& obj)
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(
|
|
|
|
_("XMLVisitor: unsupported method from_resource(const Resource& obj)")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_history(const History& obj)
|
|
|
|
{
|
|
|
|
from_history(_current, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_environment(const Environment& obj)
|
|
|
|
{
|
|
|
|
from_environment(_current, obj);
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_process(const Process& obj)
|
|
|
|
{
|
|
|
|
from_process(_current, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_thread(const Thread& obj)
|
|
|
|
{
|
|
|
|
from_thread(_current, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_request(const Request& obj)
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
from_request(_current, obj);
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_subrequest(const SubRequest& obj)
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
from_subrequest(_current, obj);
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
2006-07-11 02:06:40 +02:00
|
|
|
void XMLVisitor::from_resource(const Resource& obj, const Glib::ustring& key)
|
|
|
|
{
|
|
|
|
from_resource(_current, obj, key);
|
|
|
|
}
|
|
|
|
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
|
2006-07-11 02:06:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2006-07-15 03:28:35 +02:00
|
|
|
|
|
|
|
void XMLVisitor::from_history(xmlNodePtr parent, const History& hist)
|
|
|
|
{
|
|
|
|
if(parent!=NULL)
|
|
|
|
{
|
|
|
|
from_environment(parent, hist.get_last_environment());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw SerializerError(_("Error trying to add data to empty XML node."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
if(parent==NULL)
|
|
|
|
{
|
|
|
|
throw SerializerError(_("Error trying to add data to empty XML node."));
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//Enclosing block - save resources
|
|
|
|
//
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
//XMLVisitor xvisit(resources_node);
|
|
|
|
Glib::ustring key;
|
|
|
|
int_to_string((int)(*iter).first, key);
|
|
|
|
//xvisit.from_resource(*((*iter).second), key);
|
|
|
|
from_resource(resources_node, *((*iter).second), key);
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
//Enclosing block - save schedulables
|
|
|
|
//
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// XMLVisitor xvisit(schedulables_node);
|
|
|
|
// xvisit.from_process(*(*iter));
|
|
|
|
from_process(schedulables_node, *(*iter));
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
2006-07-15 03:28:35 +02:00
|
|
|
|
2006-07-11 02:06:40 +02:00
|
|
|
|
|
|
|
void XMLVisitor::from_resource(xmlNodePtr parent, const Resource& obj, const Glib::ustring& key)
|
|
|
|
{
|
|
|
|
if(parent!=NULL)
|
|
|
|
{
|
2006-07-15 13:29:20 +02:00
|
|
|
Glib::ustring id = "reskey" + key;
|
2006-07-11 02:06:40 +02:00
|
|
|
Glib::ustring strPreemptible("false"); // fixed??
|
|
|
|
Glib::ustring strArrivalTime("0"); // fixed??
|
|
|
|
Glib::ustring strPlaces;
|
|
|
|
int_to_string((int)obj.get_places(), strPlaces);
|
|
|
|
|
|
|
|
xmlNodePtr process_node = xmlNewChild(parent, NULL, (const xmlChar *) "resource", NULL);
|
|
|
|
xmlNewProp(process_node, (const xmlChar *) "name", (const xmlChar *) obj.get_name().c_str());
|
2006-07-15 13:29:20 +02:00
|
|
|
xmlNewProp(process_node, (const xmlChar *) "id", (const xmlChar *) id.c_str());
|
2006-07-11 02:06:40 +02:00
|
|
|
xmlNewProp(process_node, (const xmlChar *) "arrival-time", (const xmlChar *) strArrivalTime.c_str());
|
|
|
|
xmlNewProp(process_node, (const xmlChar *) "how-many", (const xmlChar *) strPlaces.c_str());
|
|
|
|
xmlNewProp(process_node, (const xmlChar *) "pre-emptible", (const xmlChar *) strPreemptible.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(_("Error trying to add resource to empty XML node."));
|
2006-07-11 02:06:40 +02:00
|
|
|
}
|
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj)
|
|
|
|
{
|
|
|
|
if(parent!=NULL)
|
|
|
|
{
|
|
|
|
Glib::ustring strPriority;
|
|
|
|
Glib::ustring strArrivalTime;
|
|
|
|
int_to_string(obj.get_base_priority(), strPriority);
|
|
|
|
int_to_string(obj.get_arrival_time(), strArrivalTime);
|
|
|
|
|
|
|
|
xmlNodePtr process_node = xmlNewChild(parent, NULL, (const xmlChar *) "process", NULL);
|
|
|
|
xmlNewProp(process_node, (const xmlChar *) "name", (const xmlChar *) obj.get_name().c_str());
|
|
|
|
xmlNewProp(process_node, (const xmlChar *) "priority", (const xmlChar *) strPriority.c_str());
|
|
|
|
xmlNewProp(process_node, (const xmlChar *) "arrival-time", (const xmlChar *) strArrivalTime.c_str());
|
|
|
|
|
|
|
|
// make a threads subnode
|
|
|
|
xmlNodePtr threads_node = xmlNewChild(process_node, NULL, (const xmlChar *) "threads", NULL);
|
|
|
|
|
|
|
|
// iterate on threads
|
|
|
|
typedef std::vector<Thread*> Threads;
|
|
|
|
typedef std::vector<Thread*>::const_iterator thr_iterator;
|
|
|
|
const Threads& tvect = ((Process&)obj).get_threads();
|
|
|
|
thr_iterator iter = tvect.begin();
|
|
|
|
thr_iterator end = tvect.end();
|
|
|
|
while(iter!=end)
|
|
|
|
{
|
2006-07-11 02:06:40 +02:00
|
|
|
const Thread* t = *iter;
|
|
|
|
|
2006-07-08 07:54:21 +02:00
|
|
|
from_thread(threads_node, *(*iter));
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(_("Error trying to add process to empty XML node."));
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj)
|
|
|
|
{
|
|
|
|
if(parent!=NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring strPriority;
|
|
|
|
Glib::ustring strArrivalTime;
|
|
|
|
Glib::ustring strLastsTime;
|
|
|
|
int_to_string(obj.get_base_priority(), strPriority);
|
|
|
|
int_to_string(obj.get_arrival_time(), strArrivalTime);
|
|
|
|
int_to_string(obj.get_elapsed_time(), strLastsTime);
|
|
|
|
// get_elapsed_time() or get_total_cpu_time() ???
|
2006-07-11 02:06:40 +02:00
|
|
|
xmlNodePtr thread_node = xmlNewChild(parent, NULL, (const xmlChar *) "thread", NULL);
|
2006-07-08 07:54:21 +02:00
|
|
|
xmlNewProp(thread_node, (const xmlChar *) "name", (const xmlChar *) obj.get_name().c_str());
|
|
|
|
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());
|
2006-07-11 02:06:40 +02:00
|
|
|
|
|
|
|
// make a requests subnode
|
|
|
|
xmlNodePtr requests_node = xmlNewChild(thread_node, NULL, (const xmlChar *) "requests", NULL);
|
|
|
|
// iterate on requests
|
|
|
|
typedef std::vector<Request*> Requests;
|
|
|
|
typedef std::vector<Request*>::const_iterator req_iterator;
|
|
|
|
const Requests& rvect = ((Thread&)obj).get_requests();
|
|
|
|
req_iterator iter = rvect.begin();
|
|
|
|
req_iterator end = rvect.end();
|
|
|
|
while(iter!=end)
|
|
|
|
{
|
|
|
|
const Request* r = *iter;
|
|
|
|
|
|
|
|
from_request(requests_node, *(*iter));
|
|
|
|
iter++;
|
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(_("Error trying to add thread to empty XML node."));
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj)
|
|
|
|
{
|
2006-07-11 02:06:40 +02:00
|
|
|
if(parent!=NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring strArrivalTime;
|
|
|
|
int_to_string(obj.get_instant(), strArrivalTime);
|
|
|
|
|
|
|
|
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
|
|
|
|
typedef std::vector<SubRequest*> SubRequests;
|
|
|
|
typedef std::vector<SubRequest*>::const_iterator subreq_iterator;
|
|
|
|
const SubRequests& srvect = ((Request&)obj).get_subrequests();
|
|
|
|
subreq_iterator iter = srvect.begin();
|
|
|
|
subreq_iterator end = srvect.end();
|
|
|
|
while(iter!=end)
|
|
|
|
{
|
|
|
|
const SubRequest* sr = *iter;
|
|
|
|
from_subrequest(request_node, *(*iter));
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(_("Error trying to add request to empty XML node."));
|
2006-07-11 02:06:40 +02:00
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XMLVisitor::from_subrequest(xmlNodePtr parent, const SubRequest& obj)
|
|
|
|
{
|
2006-07-11 02:06:40 +02:00
|
|
|
if(parent!=NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring strResource;
|
|
|
|
Glib::ustring strHowMany;
|
|
|
|
Glib::ustring strLastsFor;
|
|
|
|
int_to_string(obj.get_resource_key(), strResource);
|
|
|
|
int_to_string(obj.get_places(), strHowMany);
|
|
|
|
int_to_string(obj.get_length(), strLastsFor);
|
|
|
|
|
|
|
|
xmlNodePtr subrequest_node = xmlNewChild(parent, NULL, (const xmlChar *) "subrequest", NULL);
|
|
|
|
xmlNewProp(subrequest_node, (const xmlChar *) "resource", (const xmlChar *) strResource.c_str());
|
|
|
|
xmlNewProp(subrequest_node, (const xmlChar *) "how-many", (const xmlChar *) strHowMany.c_str());
|
|
|
|
xmlNewProp(subrequest_node, (const xmlChar *) "lasts-for", (const xmlChar *) strLastsFor.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(_("Error trying to add subrequest to empty XML node."));
|
2006-07-11 02:06:40 +02:00
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|