2006-09-17 03:19:52 +02:00
|
|
|
// plugins/xmlsave/src/xml_visitor.cc - Copyright 2005, 2006, University
|
2006-07-08 07:54:21 +02:00
|
|
|
// 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
|
2007-06-30 15:31:19 +02:00
|
|
|
// the Free Software Foundation; either version 3 of the License, or
|
2006-07-08 07:54:21 +02:00
|
|
|
// (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
|
2007-06-30 15:31:19 +02:00
|
|
|
// along with SGPEMv2. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
#include "xml_visitor.hh"
|
|
|
|
|
2006-07-15 03:28:35 +02:00
|
|
|
#include "gettext.h"
|
|
|
|
|
2006-09-07 02:43:00 +02:00
|
|
|
#include <sgpemv2/environment.hh>
|
|
|
|
#include <sgpemv2/history.hh>
|
|
|
|
#include <sgpemv2/process.hh>
|
|
|
|
#include <sgpemv2/request.hh>
|
|
|
|
#include <sgpemv2/resource.hh>
|
|
|
|
#include <sgpemv2/serializer_error.hh>
|
|
|
|
#include <sgpemv2/string_utils.hh>
|
|
|
|
#include <sgpemv2/sub_request.hh>
|
|
|
|
#include <sgpemv2/thread.hh>
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
using namespace sgpem;
|
|
|
|
|
|
|
|
|
|
|
|
XMLVisitor::XMLVisitor(xmlNodePtr current)
|
2006-08-09 16:38:45 +02:00
|
|
|
: _current(current)
|
2006-09-17 03:19:52 +02:00
|
|
|
{
|
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
XMLVisitor::~XMLVisitor()
|
2006-09-17 03:19:52 +02:00
|
|
|
{
|
|
|
|
}
|
2006-07-08 07:54:21 +02:00
|
|
|
|
2008-11-08 22:17:11 +01:00
|
|
|
void XMLVisitor::from_resource(const Resource& /*obj*/) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
throw SerializerError(
|
|
|
|
_("XMLVisitor: unsupported method from_resource(const Resource& obj)")
|
2006-08-09 16:38:45 +02:00
|
|
|
);
|
2006-07-15 03:28:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_history(const History& obj) throw(SerializerError)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
|
|
|
from_history(_current, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_environment(const Environment& obj) throw(SerializerError)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
|
|
|
from_environment(_current, obj);
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_process(const Process& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
|
|
|
from_process(_current, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_thread(const Thread& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
|
|
|
from_thread(_current, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_request(const Request& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
from_request(_current, obj);
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_subrequest(const SubRequest& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-07-15 03:28:35 +02:00
|
|
|
from_subrequest(_current, obj);
|
2006-07-08 07:54:21 +02:00
|
|
|
}
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_resource(const Resource& obj, const Glib::ustring& key) throw(SerializerError)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
|
|
|
from_resource(_current, obj, key);
|
|
|
|
}
|
|
|
|
|
2006-07-08 07:54:21 +02:00
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_history(xmlNodePtr parent, const History& hist) throw(SerializerError)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent != NULL)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
from_environment(parent, hist.get_last_environment());
|
2006-07-15 03:28:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw SerializerError(_("Error trying to add data to empty XML node."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_environment(xmlNodePtr parent, const Environment& env) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent == NULL)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
|
|
|
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;
|
2006-08-09 16:38:45 +02:00
|
|
|
|
2006-07-15 03:28:35 +02:00
|
|
|
res_iterator iter = rvect.begin();
|
|
|
|
res_iterator end = rvect.end();
|
2006-08-09 16:38:45 +02:00
|
|
|
while (iter != end)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
|
|
|
//XMLVisitor xvisit(resources_node);
|
|
|
|
Glib::ustring key;
|
2006-08-26 12:45:04 +02:00
|
|
|
to_string<int>(static_cast<int>((*iter).first), key);
|
2006-07-15 03:28:35 +02:00
|
|
|
//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;
|
2006-08-09 16:38:45 +02:00
|
|
|
|
2006-07-15 03:28:35 +02:00
|
|
|
proc_iterator iter = pvect.begin();
|
|
|
|
proc_iterator end = pvect.end();
|
2006-08-09 16:38:45 +02:00
|
|
|
while (iter != end)
|
2006-07-15 03:28:35 +02:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_resource(xmlNodePtr parent, const Resource& obj, const Glib::ustring& key) throw(SerializerError)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent != NULL)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
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;
|
2006-08-26 12:45:04 +02:00
|
|
|
to_string<int>(static_cast<int>(obj.get_places()), strPlaces);
|
2006-07-11 02:06:40 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_process(xmlNodePtr parent, const Process& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent != NULL)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
|
|
|
Glib::ustring strPriority;
|
|
|
|
Glib::ustring strArrivalTime;
|
2006-08-26 12:45:04 +02:00
|
|
|
to_string<int>(obj.get_base_priority(), strPriority);
|
|
|
|
to_string<int>(obj.get_arrival_time(), strArrivalTime);
|
2006-07-08 07:54:21 +02:00
|
|
|
|
|
|
|
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();
|
2006-08-09 16:38:45 +02:00
|
|
|
while (iter != end)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-07-11 02:06:40 +02:00
|
|
|
const Thread* t = *iter;
|
2008-11-08 22:17:11 +01:00
|
|
|
from_thread(threads_node, *t);
|
2006-07-08 07:54:21 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_thread(xmlNodePtr parent, const Thread& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent != NULL)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring strPriority;
|
|
|
|
Glib::ustring strArrivalTime;
|
|
|
|
Glib::ustring strLastsTime;
|
2006-08-26 12:45:04 +02:00
|
|
|
to_string<int>(obj.get_base_priority(), strPriority);
|
|
|
|
to_string<int>(obj.get_arrival_time(), strArrivalTime);
|
2006-08-29 00:29:43 +02:00
|
|
|
to_string<int>(obj.get_total_cpu_time(), strLastsTime);
|
|
|
|
|
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-08-09 16:38:45 +02:00
|
|
|
|
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();
|
2006-08-09 16:38:45 +02:00
|
|
|
while (iter != end)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
|
|
|
const Request* r = *iter;
|
2008-11-08 22:17:11 +01:00
|
|
|
from_request(requests_node, *r);
|
2006-07-11 02:06:40 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent != NULL)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring strArrivalTime;
|
2006-08-26 12:45:04 +02:00
|
|
|
to_string<int>(obj.get_instant(), strArrivalTime);
|
2006-07-11 02:06:40 +02:00
|
|
|
|
|
|
|
xmlNodePtr request_node = xmlNewChild(parent, NULL, (const xmlChar *) "request", NULL);
|
|
|
|
xmlNewProp(request_node, (const xmlChar *) "arrival-time", (const xmlChar *) strArrivalTime.c_str());
|
2006-08-09 16:38:45 +02:00
|
|
|
|
2006-07-11 02:06:40 +02:00
|
|
|
// 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();
|
2006-08-09 16:38:45 +02:00
|
|
|
while (iter != end)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
|
|
|
const SubRequest* sr = *iter;
|
2008-11-08 22:17:11 +01:00
|
|
|
from_subrequest(request_node, *sr);
|
2006-07-11 02:06:40 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-04 02:29:37 +02:00
|
|
|
void XMLVisitor::from_subrequest(xmlNodePtr parent, const SubRequest& obj) throw(SerializerError)
|
2006-07-08 07:54:21 +02:00
|
|
|
{
|
2006-08-09 16:38:45 +02:00
|
|
|
if (parent != NULL)
|
2006-07-11 02:06:40 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring strResource;
|
|
|
|
Glib::ustring strLastsFor;
|
2006-08-26 12:45:04 +02:00
|
|
|
to_string<int>(obj.get_resource_key(), strResource);
|
|
|
|
to_string<int>(obj.get_length(), strLastsFor);
|
2006-07-11 02:06:40 +02:00
|
|
|
|
|
|
|
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 *) "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
|
|
|
}
|