25 XmlAppSaver::XmlAppSaver(
const char* szFileName)
27 if(szFileName) strFileName = szFileName;
32 if(!strFileName.size())
33 return serialXml(application, application->
getXmlFile());
35 return serialXml(application, strFileName.c_str());
38 XmlAppSaver::~XmlAppSaver() =
default;
40 bool XmlAppSaver::serialXml(
Application* app,
const char* szFile)
49 auto* root =
new TiXmlElement(
"application");
50 doc.LinkEndChild( root );
51 auto* appName =
new TiXmlElement(
"name");
52 appName->LinkEndChild(
new TiXmlText(app->
getName()));
53 root->LinkEndChild(appName);
58 auto* desc=
new TiXmlElement(
"description");
60 root->LinkEndChild(desc);
65 auto* vers=
new TiXmlElement(
"version");
66 vers->LinkEndChild(
new TiXmlText( app->
getVersion()));
67 root->LinkEndChild(vers);
87 auto* auths=
new TiXmlElement(
"authors");
91 auto* auth=
new TiXmlElement(
"author");
94 auths->LinkEndChild(auth);
96 root->LinkEndChild(auths);
102 for (
int modCt=0; modCt<nModules; ++modCt)
104 auto* newMod =
new TiXmlElement(
"module");
105 root->LinkEndChild(newMod);
108 auto* name =
new TiXmlElement(
"name");
109 name->LinkEndChild(
new TiXmlText(curMod.
getName()));
110 newMod->LinkEndChild(name);
112 auto* parameters=
new TiXmlElement(
"parameters");
113 parameters->LinkEndChild(
new TiXmlText(curMod.
getParam()));
114 newMod->LinkEndChild(parameters);
116 auto* node =
new TiXmlElement(
"node");
117 node->LinkEndChild(
new TiXmlText(curMod.
getHost()));
118 newMod->LinkEndChild(node);
120 auto* prefix=
new TiXmlElement(
"prefix");
121 prefix->LinkEndChild(
new TiXmlText(curMod.
getPrefix()));
122 newMod->LinkEndChild(prefix);
124 if(strcmp(curMod.
getStdio(),
"") != 0)
126 auto* stdio=
new TiXmlElement(
"stdio");
127 stdio->LinkEndChild(
new TiXmlText(curMod.
getStdio()));
128 newMod->LinkEndChild(stdio);
133 auto* workdir=
new TiXmlElement(
"workdir");
134 workdir->LinkEndChild(
new TiXmlText(curMod.
getWorkDir()));
135 newMod->LinkEndChild(workdir);
140 auto* broker=
new TiXmlElement(
"deployer");
141 broker->LinkEndChild(
new TiXmlText(curMod.
getBroker()));
142 newMod->LinkEndChild(broker);
159 txt<<
"(Pos (x "<<model.
points[0].x<<
") "<<
"(y "<<model.
points[0].y<<
"))";
160 auto* geometry=
new TiXmlElement(
"geometry");
161 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
162 newMod->LinkEndChild(geometry);
171 for (
int appCt=0; appCt<nApps; ++appCt)
173 auto* newApp =
new TiXmlElement(
"application");
174 root->LinkEndChild(newApp);
177 auto* name =
new TiXmlElement(
"name");
178 name->LinkEndChild(
new TiXmlText(curApp.
getName()));
179 newApp->LinkEndChild(name);
182 auto* prefix=
new TiXmlElement(
"prefix");
183 prefix->LinkEndChild(
new TiXmlText(curApp.
getPrefix()));
184 newApp->LinkEndChild(prefix);
190 txt<<
"(Pos (x "<<model.
points[0].x<<
") "<<
"(y "<<model.
points[0].y<<
"))";
191 auto* geometry=
new TiXmlElement(
"geometry");
192 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
193 newApp->LinkEndChild(geometry);
202 for (
int connCt=0; connCt<nConns; ++connCt)
204 auto* newConn=
new TiXmlElement(
"connection");
207 if(strlen(curConn.
getId()))
208 newConn->SetAttribute(
"id", curConn.
getId());
211 newConn->SetAttribute(
"persist",
"true");
213 auto* from =
new TiXmlElement(
"from");
215 from->SetAttribute(
"external",
"true");
216 from->LinkEndChild(
new TiXmlText(curConn.
from()));
217 newConn->LinkEndChild(from);
219 auto* to =
new TiXmlElement(
"to");
221 to->SetAttribute(
"external",
"true");
222 to->LinkEndChild(
new TiXmlText(curConn.
to()));
223 newConn->LinkEndChild(to);
225 auto* protocol =
new TiXmlElement(
"protocol");
226 protocol->LinkEndChild(
new TiXmlText(curConn.
carrier()));
227 newConn->LinkEndChild(protocol);
234 for(
auto& point : model.
points)
235 txt<<
"((x "<<point.x<<
") "<<
"(y "<<point.y<<
")) ";
237 auto* geometry=
new TiXmlElement(
"geometry");
238 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
239 newConn->LinkEndChild(geometry);
242 root->LinkEndChild(newConn);
251 auto* newArb =
new TiXmlElement(
"arbitrator");
253 auto* port =
new TiXmlElement(
"port");
254 port->LinkEndChild(
new TiXmlText(arb.
getPort()));
255 newArb->LinkEndChild(port);
257 std::map<string, string> &rules = arb.
getRuleMap();
258 for(
auto& it : rules)
260 auto* rule =
new TiXmlElement(
"rule");
261 rule->SetAttribute(
"connection", it.first.c_str());
262 rule->LinkEndChild(
new TiXmlText(it.second.c_str()));
263 newArb->LinkEndChild(rule);
271 for(
auto& point : model.
points)
272 txt<<
"((x "<<point.x<<
") "<<
"(y "<<point.y<<
")) ";
274 auto* geometry=
new TiXmlElement(
"geometry");
275 geometry->LinkEndChild(
new TiXmlText(txt.str().c_str()));
276 newArb->LinkEndChild(geometry);
278 root->LinkEndChild(newArb);
287 err<<
"tinyXml error for file " << app->
getXmlFile();
289 err <<
" at line " << doc.ErrorRow() <<
", column " << doc.ErrorCol() <<
": " << doc.ErrorDesc();