- updated & documented all about serializers & visitors
git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@764 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
35ae7f4eae
commit
88d5ca2fe1
6 changed files with 359 additions and 103 deletions
|
@ -19,29 +19,17 @@
|
|||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#include "xml_serializer.hh"
|
||||
#include "xml_visitor.hh"
|
||||
#include "xml_serializer_factory.hh"
|
||||
#include "xml_visitor.hh"
|
||||
|
||||
#include "string_utils.hh"
|
||||
#include "environment.hh"
|
||||
#include "history.hh"
|
||||
/*
|
||||
#include "backend/concrete_environment.hh"
|
||||
#include "backend/concrete_history.hh"
|
||||
*/
|
||||
#include "backend/environment.hh"
|
||||
#include "backend/history.hh"
|
||||
#include "backend/process.hh"
|
||||
#include "backend/serializer_error.hh"
|
||||
#include "backend/string_utils.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
XMLSerializer::~XMLSerializer()
|
||||
{
|
||||
}
|
||||
|
@ -81,7 +69,6 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
|
|||
{
|
||||
// TODO - all to do!!
|
||||
// DEBUG - remove me when finished
|
||||
XMLSerializerFactory fact(hist);
|
||||
|
||||
#ifdef LIBXML_SAX1_ENABLED
|
||||
xmlDocPtr doc;
|
||||
|
@ -97,6 +84,10 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
|
|||
xmlCleanupParser();
|
||||
throw SerializerError("Parsing Error: doc is invalid.");
|
||||
}
|
||||
|
||||
clear_history(hist);
|
||||
XMLSerializerFactory fact(hist);
|
||||
|
||||
// read all elements and fill hist
|
||||
read_doc(doc, fact);
|
||||
|
||||
|
@ -121,13 +112,13 @@ void XMLSerializer::restore_snapshot(const Glib::ustring& filename, History& his
|
|||
|
||||
const Glib::ustring XMLSerializer::get_filename_extension()
|
||||
{
|
||||
return Glib::ustring("ocio");
|
||||
return Glib::ustring("xsgp");
|
||||
}
|
||||
|
||||
|
||||
const Glib::ustring XMLSerializer::get_filename_description()
|
||||
{
|
||||
return Glib::ustring("SGPEMv2 XML formatted snapshot save file");
|
||||
return Glib::ustring("SGPEMv2 XML savefile");
|
||||
}
|
||||
|
||||
void XMLSerializer::fill_doc(xmlDocPtr doc, const History& hist)
|
||||
|
@ -142,22 +133,27 @@ void XMLSerializer::fill_doc(xmlDocPtr doc, const History& hist)
|
|||
/*
|
||||
* Creates a DTD declaration. Isn't mandatory.
|
||||
*/
|
||||
// dtd = xmlCreateIntSubset(doc, BAD_CAST "root", NULL, BAD_CAST "tree2.dtd");
|
||||
xmlDtdPtr dtd = xmlCreateIntSubset(doc, (const xmlChar *) "sgpem", NULL, (const xmlChar *) "sgpem.dtd");
|
||||
|
||||
/*
|
||||
* xmlNewChild() creates a new node, which is "attached" as child node
|
||||
* of root_node node.
|
||||
*/
|
||||
XMLVisitor xvisit(root_node);
|
||||
xvisit.from_history(hist);
|
||||
/*
|
||||
//
|
||||
// xmlNewChild() creates a new node, which is "attached" as child node
|
||||
// of root_node node.
|
||||
//
|
||||
xmlNodePtr resources_node = xmlNewChild(root_node, NULL, (const xmlChar *) "resources", NULL);
|
||||
/*
|
||||
* The same as above, but the new child node doesn't have a content
|
||||
*/
|
||||
//
|
||||
// The same as above, but the new child node doesn't have a content
|
||||
//
|
||||
xmlNodePtr schedulables_node = xmlNewChild(root_node, NULL, (const xmlChar *) "schedulables", NULL);
|
||||
|
||||
fill_resources(resources_node, hist);
|
||||
fill_schedulables(schedulables_node, hist);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
void XMLSerializer::fill_resources(xmlNodePtr resources_node, const History& hist)
|
||||
{
|
||||
|
||||
|
@ -197,24 +193,33 @@ void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const Histor
|
|||
iter++;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void XMLSerializer::clear_history(History& hist)
|
||||
{
|
||||
/*
|
||||
|
||||
const Environment& env = hist.get_last_environment();
|
||||
|
||||
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)
|
||||
while(iter!=pvect.end())
|
||||
{
|
||||
xvisit.from_process(*(*iter));
|
||||
pvect.
|
||||
hist.remove(*(*iter));
|
||||
iter = pvect.begin();
|
||||
}
|
||||
*/
|
||||
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
res_iterator riter = rvect.begin();
|
||||
while(riter!=rvect.end())
|
||||
{
|
||||
hist.remove((*riter).first);
|
||||
riter = rvect.begin();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact)
|
||||
|
@ -230,14 +235,10 @@ void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact)
|
|||
throw SerializerError("Reading Error: xml doc is empty.");
|
||||
}
|
||||
|
||||
// cout << "ROOT: " << root->name << endl;
|
||||
|
||||
xmlNodePtr cur;
|
||||
cur = root->children;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
// cout << "NODE: " << cur->name << endl;
|
||||
|
||||
Glib::ustring name((const char *)cur->name);
|
||||
if(name=="resources")
|
||||
{
|
||||
|
@ -258,25 +259,16 @@ XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
|
|||
|
||||
XMLSerializerFactory::Parameters* par=new XMLSerializerFactory::Parameters();
|
||||
while (prop != NULL) {
|
||||
// // cout << "PROP: " << prop->name;
|
||||
|
||||
if(prop->children && xmlNodeIsText(prop->children)){
|
||||
xmlChar *key = xmlNodeGetContent (prop->children);
|
||||
// xmlChar *key = xmlNodeListGetString(doc, prop->children, 1);
|
||||
if(key!=NULL)
|
||||
{
|
||||
// // cout << " VALUE: " << key;
|
||||
std::pair<Glib::ustring, Glib::ustring> key_value(Glib::ustring((const char *)prop->name), Glib::ustring((const char *)key));
|
||||
par->insert(key_value);
|
||||
// c.insert(typename Cont::value_type(new_key, pos->second));
|
||||
// cout << " pair PROP: " << key_value.first << " VALUE: " << key_value.second << endl;
|
||||
|
||||
xmlFree(key);
|
||||
}
|
||||
// else
|
||||
// cout << " !VALUE IS NULL! ";
|
||||
}
|
||||
// cout << endl;
|
||||
prop = prop->next;
|
||||
}
|
||||
return par;
|
||||
|
@ -291,8 +283,6 @@ void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFacto
|
|||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="resource")
|
||||
{
|
||||
// cout << "read_resources NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
|
@ -317,8 +307,6 @@ void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerialize
|
|||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="process")
|
||||
{
|
||||
// cout << "read_schedulables NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
|
@ -345,8 +333,6 @@ void XMLSerializer::read_threads(xmlNodePtr threads_node, XMLSerializerFactory&
|
|||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="thread")
|
||||
{
|
||||
// cout << "read_threads NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
|
@ -365,7 +351,6 @@ void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory
|
|||
{
|
||||
if(requests_node==NULL)
|
||||
{
|
||||
// cout << "read_requests NULL" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -376,8 +361,6 @@ void XMLSerializer::read_requests(xmlNodePtr requests_node, XMLSerializerFactory
|
|||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="request")
|
||||
{
|
||||
// cout << "read_requests NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
|
@ -396,7 +379,6 @@ void XMLSerializer::read_subrequests(xmlNodePtr subrequest_node, XMLSerializerFa
|
|||
{
|
||||
if(subrequest_node==NULL)
|
||||
{
|
||||
// cout << "read_subrequest NULL" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -407,8 +389,6 @@ void XMLSerializer::read_subrequests(xmlNodePtr subrequest_node, XMLSerializerFa
|
|||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="subrequest")
|
||||
{
|
||||
// cout << "read_subrequest NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue