sgpemv2/plugins/xmlsave/src/xml_visitor.cc

151 lines
4.1 KiB
C++
Raw Normal View History

// 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"
#include "backend/string_utils.hh"
#include "backend/resource.hh"
#include "backend/process.hh"
#include "backend/thread.hh"
#include "backend/request.hh"
#include "backend/sub_request.hh"
#include "backend/serializer_error.hh"
using namespace sgpem;
/*
#include <iostream>
using namespace std;
*/
XMLVisitor::XMLVisitor(xmlNodePtr current)
: _current(current)
{
}
XMLVisitor::~XMLVisitor()
{
}
void XMLVisitor::from_resource(const Resource& obj)
{
}
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)
{
}
void XMLVisitor::from_subrequest(const SubRequest& obj)
{
}
void XMLVisitor::from_resource(xmlNodePtr parent, const Resource& obj)
{
}
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)
{
from_thread(threads_node, *(*iter));
iter++;
}
}
else
{
throw SerializerError("Error trying to add process to empty XML node.");
}
}
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() ???
xmlNodePtr thread_node = xmlNewChild(_current, NULL, (const xmlChar *) "thread", NULL);
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());
}
else
{
throw SerializerError("Error trying to add thread to empty XML node.");
}
}
void XMLVisitor::from_request(xmlNodePtr parent, const Request& obj)
{
}
void XMLVisitor::from_subrequest(xmlNodePtr parent, const SubRequest& obj)
{
}