- updated xml_serializer.??, xml_visitor.??
- added xml_serializer_factory.?? git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@750 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
864e71b82e
commit
b6b303c4e3
6 changed files with 568 additions and 32 deletions
|
@ -20,17 +20,28 @@
|
|||
|
||||
#include "xml_serializer.hh"
|
||||
#include "xml_visitor.hh"
|
||||
#include "xml_serializer_factory.hh"
|
||||
|
||||
#include "backend/string_utils.hh"
|
||||
#include "backend/environment.hh"
|
||||
#include "backend/history.hh"
|
||||
#include "string_utils.hh"
|
||||
#include "environment.hh"
|
||||
#include "history.hh"
|
||||
/*
|
||||
#include "backend/concrete_environment.hh"
|
||||
#include "backend/concrete_history.hh"
|
||||
*/
|
||||
#include "backend/process.hh"
|
||||
#include "backend/serializer_error.hh"
|
||||
|
||||
using namespace sgpem;
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
XMLSerializer::~XMLSerializer()
|
||||
{
|
||||
}
|
||||
|
@ -70,9 +81,44 @@ 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;
|
||||
|
||||
LIBXML_TEST_VERSION
|
||||
xmlKeepBlanksDefault(0);
|
||||
|
||||
/*
|
||||
* build an XML tree from a the file;
|
||||
*/
|
||||
doc = xmlParseFile(filename.c_str());
|
||||
if (doc == NULL) {
|
||||
xmlCleanupParser();
|
||||
throw SerializerError("Parsing Error: doc is invalid.");
|
||||
}
|
||||
// read all elements and fill hist
|
||||
read_doc(doc, fact);
|
||||
|
||||
// frees all xml related data
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
/* Clean up everything else before quitting. */
|
||||
xmlCleanupParser();
|
||||
|
||||
#else
|
||||
/*
|
||||
* the library has been compiled without some of the old interfaces
|
||||
*/
|
||||
throw SerializerError("ERROR: Compilation with SAX1 must be enabled! (?)");
|
||||
#endif /* LIBXML_SAX1_ENABLED */
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const Glib::ustring XMLSerializer::get_filename_extension()
|
||||
{
|
||||
return Glib::ustring("ocio");
|
||||
|
@ -112,11 +158,28 @@ void XMLSerializer::fill_doc(xmlDocPtr doc, const History& hist)
|
|||
fill_schedulables(schedulables_node, hist);
|
||||
}
|
||||
|
||||
void XMLSerializer::fill_resources(xmlNodePtr resources, const History& hist)
|
||||
void XMLSerializer::fill_resources(xmlNodePtr resources_node, const History& hist)
|
||||
{
|
||||
|
||||
|
||||
const Environment& env = hist.get_last_environment();
|
||||
|
||||
const Environment::Resources& rvect = env.get_resources();
|
||||
typedef Environment::Resources::const_iterator res_iterator;
|
||||
|
||||
res_iterator iter = rvect.begin();
|
||||
res_iterator end = rvect.end();
|
||||
while(iter!=end)
|
||||
{
|
||||
XMLVisitor xvisit(resources_node);
|
||||
Glib::ustring key;
|
||||
int_to_string((int)(*iter).first, key);
|
||||
xvisit.from_resource(*((*iter).second), key);
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLSerializer::fill_schedulables(xmlNodePtr schedulables, const History& hist)
|
||||
void XMLSerializer::fill_schedulables(xmlNodePtr schedulables_node, const History& hist)
|
||||
{
|
||||
|
||||
|
||||
|
@ -129,20 +192,130 @@ void XMLSerializer::fill_schedulables(xmlNodePtr schedulables, const History& hi
|
|||
proc_iterator end = pvect.end();
|
||||
while(iter!=end)
|
||||
{
|
||||
XMLVisitor xvisit(schedulables);
|
||||
XMLVisitor xvisit(schedulables_node);
|
||||
xvisit.from_process(*(*iter));
|
||||
/*
|
||||
Glib::ustring strPriority;
|
||||
Glib::ustring strArrivalTime;
|
||||
Process* p = (*iter);
|
||||
int_to_string(p->get_base_priority(), strPriority);
|
||||
int_to_string(p->get_arrival_time(), strArrivalTime);
|
||||
|
||||
xmlNodePtr process_node = xmlNewChild(schedulables, NULL, (const xmlChar *) p->get_name().c_str(), NULL);
|
||||
xmlNewProp(process_node, (const xmlChar *) "name", (const xmlChar *) p->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());
|
||||
*/
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void XMLSerializer::read_doc(xmlDocPtr doc, XMLSerializerFactory& fact)
|
||||
{
|
||||
/*
|
||||
* Check the document is of the right kind
|
||||
*/
|
||||
xmlNodePtr root;
|
||||
root = xmlDocGetRootElement(doc);
|
||||
if (root == NULL) {
|
||||
xmlFreeDoc(doc);
|
||||
xmlCleanupParser();
|
||||
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")
|
||||
{
|
||||
read_resources(cur, fact);
|
||||
}
|
||||
if(name=="schedulables")
|
||||
{
|
||||
read_schedulables(cur, fact);
|
||||
}
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
XMLSerializerFactory::Parameters* read_properties(xmlAttrPtr prop)
|
||||
{
|
||||
if(prop==NULL)
|
||||
return NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void XMLSerializer::read_resources(xmlNodePtr resources_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
xmlNodePtr cur;
|
||||
cur = resources_node->children;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
Glib::ustring node_name((const char *)cur->name);
|
||||
if(node_name=="resource")
|
||||
{
|
||||
cout << "NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
XMLSerializerFactory::Parameters* par=read_properties(prop);
|
||||
if(par!=NULL)
|
||||
{
|
||||
fact.factory_method(Glib::ustring("Resource"), *par);
|
||||
}
|
||||
// fact.create_resource(*par);
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
void XMLSerializer::read_schedulables(xmlNodePtr schedulables_node, XMLSerializerFactory& fact)
|
||||
{
|
||||
xmlNodePtr cur;
|
||||
cur = schedulables_node->children;
|
||||
while(cur!=NULL)
|
||||
{
|
||||
cout << "NODE: " << cur->name << endl;
|
||||
|
||||
xmlAttrPtr prop = cur->properties;
|
||||
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;
|
||||
xmlFree(key);
|
||||
}
|
||||
else
|
||||
cout << " !VALUE IS NULL! ";
|
||||
}
|
||||
cout << endl;
|
||||
prop = prop->next;
|
||||
}
|
||||
|
||||
cur = cur->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* comment */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue