- Fixed compilation errors caused by latest changes to serialization code
- Setup makefile for xmlsave plugin. It still can`t be activated. why? - Added a temporary command SAVE to commandline interface to try serialization git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@826 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
574723a35b
commit
96728edfce
|
@ -181,6 +181,7 @@ src_backend_libbackend_la_SOURCES = \
|
|||
src/backend/schedulable.cc \
|
||||
src/backend/scheduler.cc \
|
||||
src/backend/serialize_visitor.cc \
|
||||
src/backend/serializers_gatekeeper.cc \
|
||||
src/backend/simulation.cc \
|
||||
src/backend/static_process.cc \
|
||||
src/backend/static_request.cc \
|
||||
|
@ -221,7 +222,8 @@ pkginclude_HEADERS += \
|
|||
src/backend/process.hh \
|
||||
src/backend/schedulable.hh \
|
||||
src/backend/scheduler.hh \
|
||||
src/backend/serialize_visitor.cc \
|
||||
src/backend/serialize_visitor.hh \
|
||||
src/backend/serializers_gatekeeper.hh \
|
||||
src/backend/simulation.hh \
|
||||
src/backend/sub_request.hh \
|
||||
src/backend/thread.hh \
|
||||
|
|
|
@ -88,9 +88,15 @@ libxmlsave_la_LDFLAGS = \
|
|||
|
||||
# Please keep this in sorted order:
|
||||
libxmlsave_la_SOURCES = \
|
||||
src/plugin.cc
|
||||
src/plugin.cc \
|
||||
src/xml_serializer.cc \
|
||||
src/xml_serializer_factory.cc \
|
||||
src/xml_visitor.cc
|
||||
|
||||
noinst_HEADERS +=
|
||||
noinst_HEADERS += \
|
||||
src/xml_serializer_factory.hh \
|
||||
src/xml_serializer.hh \
|
||||
src/xml_visitor.hh
|
||||
|
||||
# ############################################################
|
||||
#
|
||||
|
|
|
@ -21,27 +21,30 @@
|
|||
#include "config.h"
|
||||
|
||||
#include "plugin.hh"
|
||||
#include "xml_serializer.hh"
|
||||
|
||||
//static XMLSerializer* _serializer = NULL;
|
||||
using namespace sgpem;
|
||||
|
||||
sgpem::XMLSerializer* _serializer = NULL;
|
||||
|
||||
void
|
||||
sgpem__Plugin__on_init()
|
||||
{
|
||||
// if(_serializer == NULL)
|
||||
// _serializer = new sgpem::XMLSerializer();
|
||||
if(_serializer == NULL)
|
||||
_serializer = new sgpem::XMLSerializer();
|
||||
}
|
||||
|
||||
void
|
||||
sgpem__Plugin__on_exit()
|
||||
{
|
||||
// delete _serializer;
|
||||
// _serializer = NULL;
|
||||
delete _serializer;
|
||||
_serializer = NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
sgpem__Plugin__describe()
|
||||
{
|
||||
return "";
|
||||
return "This plugin saves the simulation to an XML file";
|
||||
}
|
||||
|
||||
const char*
|
||||
|
|
|
@ -22,11 +22,11 @@
|
|||
#include "xml_serializer_factory.hh"
|
||||
#include "xml_visitor.hh"
|
||||
|
||||
#include "backend/environment.hh"
|
||||
#include "backend/history.hh"
|
||||
#include "backend/process.hh"
|
||||
#include "backend/serializer_error.hh"
|
||||
#include "backend/string_utils.hh"
|
||||
#include "environment.hh"
|
||||
#include "history.hh"
|
||||
#include "process.hh"
|
||||
#include "serializer_error.hh"
|
||||
#include "string_utils.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
@ -40,7 +40,7 @@ XMLSerializer::XMLSerializer()
|
|||
|
||||
|
||||
|
||||
void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializeError)
|
||||
void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializerError)
|
||||
{
|
||||
/* COMPAT: Do not genrate nodes for formatting spaces */
|
||||
LIBXML_TEST_VERSION
|
||||
|
@ -65,7 +65,7 @@ void XMLSerializer::save_snapshot(const Glib::ustring& filename, const History&
|
|||
xmlCleanupParser();
|
||||
}
|
||||
|
||||
void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializeError)
|
||||
void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError)
|
||||
{
|
||||
// TODO - all to do!!
|
||||
// DEBUG - remove me when finished
|
||||
|
@ -101,7 +101,7 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
|
|||
/*
|
||||
* the library has been compiled without some of the old interfaces
|
||||
*/
|
||||
throw SerializerError("ERROR: Compilation with SAX1 must be enabled! (?)");
|
||||
#error Compilation of LIBXML with SAX1 support must be enabled
|
||||
#endif /* LIBXML_SAX1_ENABLED */
|
||||
}
|
||||
|
||||
|
@ -222,7 +222,7 @@ void XMLSerializer::clear_history(History& hist)
|
|||
|
||||
}
|
||||
|
||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializeError)
|
||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError)
|
||||
{
|
||||
/*
|
||||
* Check the document is of the right kind
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace sgpem
|
|||
|
||||
\throws backend::SerializerError on error
|
||||
*/
|
||||
virtual void save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializeError);
|
||||
virtual void save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializerError);
|
||||
|
||||
/**
|
||||
\brief Re-initialize system status from a saved XML snapshot
|
||||
|
@ -72,7 +72,7 @@ namespace sgpem
|
|||
|
||||
\throws backend::SerializerError
|
||||
*/
|
||||
virtual void restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializeError);
|
||||
virtual void restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError);
|
||||
|
||||
/**
|
||||
\return Constant string "xsgp"
|
||||
|
@ -124,7 +124,7 @@ namespace sgpem
|
|||
Traverse the passed (previously readed) xml document and
|
||||
rebuild the correct image using the XMLSerializerFactory object.
|
||||
*/
|
||||
void read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializeError);
|
||||
void read_doc(xmlDocPtr doc, XMLSerializerFactory& fact) throw(SerializerError);
|
||||
|
||||
/**
|
||||
\brief Restore all the resources from the passed xml node
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "history.hh"
|
||||
#include "resource.hh"
|
||||
// #include "backend/process.hh"
|
||||
#include "backend/serializer_error.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
@ -50,7 +49,7 @@ History* XMLSerializerFactory::get_history()
|
|||
}
|
||||
|
||||
void
|
||||
XMLSerializerFactory::factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializeError)
|
||||
XMLSerializerFactory::factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializerError)
|
||||
{
|
||||
if(class_name == "Resource")
|
||||
{
|
||||
|
@ -241,7 +240,7 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
|||
|
||||
int old_key=0;
|
||||
int lasts_for=0;
|
||||
int places=1;
|
||||
//int places=1;
|
||||
Parameters::iterator pos;
|
||||
resource_key_t new_key = 0;
|
||||
|
||||
|
@ -260,10 +259,10 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
|||
}
|
||||
|
||||
// read "priority" property
|
||||
pos = parameters.find(Glib::ustring("how-many"));
|
||||
if (pos != parameters.end()) {
|
||||
string_to_int(pos->second, places);
|
||||
}
|
||||
//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"));
|
||||
|
@ -271,7 +270,8 @@ XMLSerializerFactory::create_subrequest(Parameters& parameters)
|
|||
string_to_int(pos->second, lasts_for);
|
||||
}
|
||||
|
||||
return _hist->add_subrequest(*_last_request, new_key, (History::time_t)lasts_for, (History::size_t)places);
|
||||
//FIXME places?
|
||||
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
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "config.h"
|
||||
#include "history.hh"
|
||||
#include "environment.hh"
|
||||
#include "serializer_error.hh"
|
||||
|
||||
#include <glibmm/ustring.h>
|
||||
#include <map>
|
||||
|
@ -76,7 +77,7 @@ namespace sgpem
|
|||
|
||||
\throw SerializerError If not all necessary parameters for an object creation are provided
|
||||
*/
|
||||
void factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializeError);
|
||||
void factory_method(const Glib::ustring& class_name, Parameters& parameters) throw(SerializerError);
|
||||
protected:
|
||||
private:
|
||||
typedef Environment::resource_key_t resource_key_t;
|
||||
|
|
|
@ -300,15 +300,16 @@ void XMLVisitor::from_subrequest(xmlNodePtr parent, const SubRequest& obj) throw
|
|||
{
|
||||
|
||||
Glib::ustring strResource;
|
||||
Glib::ustring strHowMany;
|
||||
//Glib::ustring strHowMany;
|
||||
Glib::ustring strLastsFor;
|
||||
int_to_string(obj.get_resource_key(), strResource);
|
||||
int_to_string(obj.get_places(), strHowMany);
|
||||
//FIXME places?
|
||||
//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 *) "how-many", (const xmlChar *) strHowMany.c_str());
|
||||
xmlNewProp(subrequest_node, (const xmlChar *) "lasts-for", (const xmlChar *) strLastsFor.c_str());
|
||||
}
|
||||
else
|
||||
|
|
|
@ -122,6 +122,10 @@ DynamicProcess::get_state() const
|
|||
if (future > 0) // running == 0 && ready == 0 && blocked == 0 && terminated == 0
|
||||
return state_future;
|
||||
|
||||
// I'm not sure if we can get here (maybe if there are no threads?),
|
||||
// but I don't like this compiler warning: 'control reaches end of non-void function'
|
||||
return state_future;
|
||||
|
||||
// Since premature optimization is the root of all evil, and the
|
||||
// following code was very fast but also very wrong, the coder
|
||||
// will be punished by allowing her to code in C++ just after
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
|
||||
using namespace sgpem;
|
||||
|
||||
Serializer::Serializer()
|
||||
{
|
||||
SerializersGatekeeper::get_instance().register_serializer(this);
|
||||
}
|
||||
|
||||
Serializer::~Serializer()
|
||||
{}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "history.hh"
|
||||
#include "serializer_error.hh"
|
||||
|
||||
#include <glibmm/ustring.h>
|
||||
|
||||
|
@ -33,10 +34,11 @@ namespace sgpem
|
|||
class Serializer
|
||||
{
|
||||
public:
|
||||
Serializer();
|
||||
virtual ~Serializer() = 0;
|
||||
|
||||
virtual void save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializeError) = 0;
|
||||
virtual void restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializeError) = 0;
|
||||
virtual void save_snapshot(const Glib::ustring& filename, const History& hist) throw(SerializerError) = 0;
|
||||
virtual void restore_snapshot(const Glib::ustring& filename, History& hist) throw(SerializerError) = 0;
|
||||
virtual const Glib::ustring get_filename_extension() = 0;
|
||||
virtual const Glib::ustring get_filename_description() = 0;
|
||||
protected:
|
||||
|
|
|
@ -419,7 +419,7 @@ main(int argc, char** argv)
|
|||
}
|
||||
test << endl;
|
||||
|
||||
ThreadCreationData p1_3_d = { "p1_3", &p1, 3, 4 };
|
||||
ThreadCreationData p1_3_d = { "p1_3", &p1, 3, 4, 0 };
|
||||
|
||||
Thread& p1_3 = h.add_thread(p1_3_d.name,
|
||||
*p1_3_d.parent,
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "backend/cpu_policy_manager.hh"
|
||||
#include "backend/policy_parameters.hh"
|
||||
#include "backend/history.hh"
|
||||
#include "backend/serializers_gatekeeper.hh"
|
||||
#include "backend/serializer.hh"
|
||||
#include "backend/static_process.hh"
|
||||
#include "backend/static_resource.hh"
|
||||
#include "backend/static_thread.hh"
|
||||
|
@ -1288,6 +1290,37 @@ TextSimulation::on_remove_subrequest(const Tokens& arguments)
|
|||
h.remove(*r);
|
||||
}
|
||||
|
||||
void
|
||||
TextSimulation::on_save(const Tokens& arguments)
|
||||
{
|
||||
if(!check_arguments_num(arguments, 1))
|
||||
return;
|
||||
|
||||
ustring filename = arguments[0];
|
||||
|
||||
try
|
||||
{
|
||||
vector<Serializer*> serializers =
|
||||
SerializersGatekeeper::get_instance().get_registered();
|
||||
|
||||
Serializer& serializer = *serializers.at(0);
|
||||
|
||||
const History& history = Simulation::get_instance().get_history();
|
||||
|
||||
serializer.save_snapshot(filename, history);
|
||||
}
|
||||
catch(out_of_range e)
|
||||
{
|
||||
p_stderr(_("ERROR: No registered serializer available\n"));
|
||||
}
|
||||
catch(SerializerError e)
|
||||
{
|
||||
string msg = _("ERROR: ");
|
||||
|
||||
p_stderr(msg + e.what() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextSimulation::p_stdout(const ustring& str)
|
||||
{
|
||||
|
@ -1327,6 +1360,7 @@ TextSimulation::parse_command(TextSimulation& sim, const ustring& str)
|
|||
command_handlers["SHOW"] = &TextSimulation::on_show;
|
||||
command_handlers["ADD"] = &TextSimulation::on_add;
|
||||
command_handlers["REMOVE"] = &TextSimulation::on_remove;
|
||||
command_handlers["SAVE"] = &TextSimulation::on_save;
|
||||
command_handlers["QUIT"] = &TextSimulation::on_quit;
|
||||
|
||||
Tokens arguments = tokenize(str);
|
||||
|
|
|
@ -106,6 +106,7 @@ namespace sgpem
|
|||
void on_remove_thread(const Tokens& arguments);
|
||||
void on_remove_request(const Tokens& arguments);
|
||||
void on_remove_subrequest(const Tokens& arguments);
|
||||
void on_save(const Tokens& arguments);
|
||||
|
||||
// FIXME This is a temporary replacement for the
|
||||
// to-be written I/O layer
|
||||
|
|
Loading…
Reference in New Issue