sgpemv2/plugins/xmlsave/src/xml_serializer_factory.cc

177 lines
3.9 KiB
C++
Raw Normal View History

// src/xml_serializer_factory.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_serializer_factory.hh"
#include "string_utils.hh"
// #include "environment.hh"
#include "history.hh"
#include "resource.hh"
// #include "backend/process.hh"
#include "backend/serializer_error.hh"
using namespace sgpem;
#include <iostream>
using namespace std;
XMLSerializerFactory::XMLSerializerFactory(History& hist)
: _hist(&hist)
{
}
XMLSerializerFactory::~XMLSerializerFactory()
{
}
History* XMLSerializerFactory::get_history()
{
return _hist;
}
void
XMLSerializerFactory::factory_method(const Glib::ustring& class_name, Parameters& parameters)
{
if(class_name == "Resource")
{
create_resource(parameters);
}
else if(class_name == "Process")
{
}
else if(class_name == "Thread")
{
}
else if(class_name == "Request")
{
}
else if(class_name == "SubRequest")
{
}
}
XMLSerializerFactory::ResourcePair
XMLSerializerFactory::create_resource(Parameters& parameters)
{
// if(_hist!=NULL)
{
Glib::ustring name;
Glib::ustring key("0");
int arrival_time=0;
int how_many=1;
bool preemptable=false;
Parameters::iterator pos;
// read "name" property
pos = parameters.find(Glib::ustring("name"));
if (pos != parameters.end()) {
name = pos->second;
}
// read "key" property
pos = parameters.find(Glib::ustring("key"));
if (pos != parameters.end()) {
key = pos->second;
}
// read "preemptable" property
pos = parameters.find(Glib::ustring("preemptable"));
if (pos != parameters.end()) {
preemptable = (pos->second == "true");
}
// read "arrival-time" property
pos = parameters.find(Glib::ustring("arrival-time"));
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()) {
string_to_int(pos->second, how_many);
}
History::ResourcePair respair = _hist->add_resource(name, preemptable, how_many, arrival_time);
return respair;
}
}
Process&
XMLSerializerFactory::create_process(Parameters& parameters)
{
// if(_hist!=NULL)
{
Glib::ustring name;
int arrival_time=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);
}
return _hist->add_process(Glib::ustring(name, arrival_time, priority);;
}
}
Thread&
XMLSerializerFactory::create_thread(Parameters& parameters)
{
}
Request&
XMLSerializerFactory::create_request(Parameters& parameters)
{
}
Subrequest&
XMLSerializerFactory::create_subrequest(Parameters& parameters)
{
}
/* comment */