30 XmlModLoader::XmlModLoader(
const char* szPath,
const char* szName)
39 if((strPath.rfind(directorySeparator)==string::npos) ||
40 (strPath.rfind(directorySeparator)!=strPath.size()-1))
41 strPath = strPath + string(directorySeparator);
51 XmlModLoader::XmlModLoader(
const char* szFileName)
56 strFileName = szFileName;
61 XmlModLoader::~XmlModLoader()
70 bool XmlModLoader::init()
79 if(!strFileName.empty())
81 fileNames.push_back(strFileName);
87 logger->
addError(
"No module path is introduced.");
93 if ((dir = opendir(strPath.c_str())) ==
nullptr)
96 err<<
"Cannot access "<<strPath;
102 while((entry = readdir(dir)))
104 string name = entry->d_name;
107 string ext = name.substr(name.size()-3,3);
109 fileNames.push_back(strPath+name);
127 void XmlModLoader::reset()
134 void XmlModLoader::fini()
148 if(fileNames.empty())
151 string fname = fileNames.back();
152 fileNames.pop_back();
153 mod = parsXml(fname.c_str());
162 vector<string>::iterator itr;
163 for(itr=fileNames.begin(); itr<fileNames.end(); itr++)
165 Module* mod = parsXml((*itr).c_str());
166 if(mod && (
string(mod->
getName())==strName))
175 Module* XmlModLoader::parsXml(
const char* szFile)
180 TiXmlDocument doc(szFile);
184 err<<
"Syntax error while loading "<<szFile<<
" at line "\
185 <<doc.ErrorRow()<<
": ";
186 err<<doc.ErrorDesc();
192 TiXmlElement *root = doc.RootElement();
196 err<<
"Syntax error while loading "<<szFile<<
" . ";
197 err<<
"No root element.";
213 auto* name = (TiXmlElement*) root->FirstChild(
"name");
214 if(!name || !name->GetText())
217 err<<
"Module from "<<szFile<<
" has no name.";
222 for(TiXmlElement* var = root->FirstChildElement(
"var"); var; var = var->NextSiblingElement())
224 if(var->Attribute(
"name") && var->GetText())
226 parser->addVariable(var->Attribute(
"name"), var->GetText());
230 module.setXmlFile(szFile);
233 module.setName(parser->parseText(name->GetText()).c_str());
237 if((desc = (TiXmlElement*) root->FirstChild(
"description")))
238 module.setDescription(parser->parseText(desc->GetText()).c_str());
242 if((ver = (TiXmlElement*) root->FirstChild(
"version")))
243 module.setVersion(parser->parseText(ver->GetText()).c_str());
247 TiXmlElement* arguments;
248 if((arguments = (TiXmlElement*) root->FirstChild(
"arguments")))
249 for(TiXmlElement* param = arguments->FirstChildElement(); param;
250 param = param->NextSiblingElement())
256 bool brequired =
false;
259 Argument arg(parser->parseText(param->GetText()).c_str(),
261 param->Attribute(
"desc"));
262 arg.setDefault(param->Attribute(
"default"));
271 bool brequired =
false;
274 Argument arg(parser->parseText(param->GetText()).c_str(),
276 param->Attribute(
"desc"),
true);
277 arg.setDefault(param->Attribute(
"default"));
284 war<<
"Unrecognized tag from "<<szFile<<
" at line "\
294 if((rank = (TiXmlElement*) root->FirstChild(
"rank")) &&
296 module.setRank(atoi(parser->parseText(rank->GetText()).c_str()));
300 TiXmlElement* authors;
301 if((authors = (TiXmlElement*) root->FirstChild(
"authors")))
302 for(TiXmlElement* ath = authors->FirstChildElement(); ath;
303 ath = ath->NextSiblingElement())
309 author.
setName(parser->parseText(ath->GetText()).c_str());
310 if(ath->Attribute(
"email"))
311 author.
setEmail(ath->Attribute(
"email"));
317 war<<
"Unrecognized tag from "<<szFile<<
" at line "\
326 if(root->FirstChild(
"data"))
327 for(TiXmlElement* data = root->FirstChild(
"data")->FirstChildElement();
328 data; data = data->NextSiblingElement())
335 if(
compareString(data->Attribute(
"port_type"),
"stream") || !data->Attribute(
"port_type"))
337 else if(
compareString(data->Attribute(
"port_type"),
"event"))
339 else if(
compareString(data->Attribute(
"port_type"),
"service"))
344 war<<
"Unknown port type \'"<<data->Attribute(
"port_type")<<
"\' from "<<szFile<<
" at line "\
345 <<data->Row()<<
". Available types : stream, event, service";
350 TiXmlElement* element;
353 if((element = (TiXmlElement*) data->FirstChild(
"type")))
354 output.
setName(parser->parseText(element->GetText()).c_str());
358 war<<
"Output data from "<<szFile<<
" at line "\
359 <<data->Row()<<
" has no type.";
366 if((element = (TiXmlElement*) data->FirstChild(
"port")))
368 output.
setPort(parser->parseText(element->GetText()).c_str());
369 output.
setCarrier(element->Attribute(
"carrier"));
374 war<<
"Output data from "<<szFile<<
" at line "\
375 <<data->Row()<<
" has no port.";
379 if((element = (TiXmlElement*) data->FirstChild(
"description")))
380 output.
setDescription(parser->parseText(element->GetText()).c_str());
390 if(
compareString(data->Attribute(
"port_type"),
"stream") || !data->Attribute(
"port_type"))
392 else if(
compareString(data->Attribute(
"port_type"),
"event"))
394 else if(
compareString(data->Attribute(
"port_type"),
"service"))
399 war<<
"Unknown port type \'"<<data->Attribute(
"port_type")<<
"\' from "<<szFile<<
" at line "\
400 <<data->Row()<<
". Available types : stream, event, service";
404 TiXmlElement* element;
408 if((element = (TiXmlElement*) data->FirstChild(
"type")))
409 input.
setName(parser->parseText(element->GetText()).c_str());
413 war<<
"Input data from "<<szFile<<
" at line "\
414 <<data->Row()<<
" has no type.";
421 if((element = (TiXmlElement*) data->FirstChild(
"port")))
423 input.
setPort(parser->parseText(element->GetText()).c_str());
424 input.
setCarrier(element->Attribute(
"carrier"));
429 war<<
"Input data from "<<szFile<<
" at line "\
430 <<data->Row()<<
" has no port.";
434 if((element = (TiXmlElement*) data->FirstChild(
"description")))
435 input.
setDescription(parser->parseText(element->GetText()).c_str());
437 if((element = (TiXmlElement*) data->FirstChild(
"required")))
438 if(
compareString(parser->parseText(element->GetText()).c_str(),
"yes"))
441 if((element = (TiXmlElement*) data->FirstChild(
"priority")))
442 if(
compareString(parser->parseText(element->GetText()).c_str(),
"yes"))
450 if(root->FirstChild(
"services")) {
451 for(TiXmlElement* services = root->FirstChild(
"services")->FirstChildElement();
452 services; services = services->NextSiblingElement())
459 TiXmlElement* element;
460 if((element = (TiXmlElement*) services->FirstChild(
"port"))) {
461 input.
setPort(parser->parseText(element->GetText()).c_str());
464 if((element = (TiXmlElement*) services->FirstChild(
"description")))
465 input.
setDescription(parser->parseText(element->GetText()).c_str());
466 if((element = (TiXmlElement*) services->FirstChild(
"type")))
467 input.
setName(parser->parseText(element->GetText()).c_str());
477 TiXmlElement* element;
478 if((element = (TiXmlElement*) services->FirstChild(
"port"))) {
479 output.
setPort(parser->parseText(element->GetText()).c_str());
482 if((element = (TiXmlElement*) services->FirstChild(
"description")))
483 output.
setDescription(parser->parseText(element->GetText()).c_str());
484 if((element = (TiXmlElement*) services->FirstChild(
"type")))
485 output.
setName(parser->parseText(element->GetText()).c_str());
495 TiXmlElement* element;
496 if((element = (TiXmlElement*) root->FirstChild(
"deployer")))
498 module.setBroker(parser->parseText(element->GetText()).c_str());
499 module.setNeedDeployer(
true);
503 if(root->FirstChild(
"dependencies"))
504 for(TiXmlElement* restag = root->FirstChild(
"dependencies")->FirstChildElement();
505 restag; restag = restag->NextSiblingElement())
512 for(TiXmlElement* comptag = restag->FirstChildElement();
513 comptag; comptag = comptag->NextSiblingElement())
517 computer.
setName(parser->parseText(comptag->GetText()).c_str());
521 computer.
setDescription(parser->parseText(comptag->GetText()).c_str());
527 TiXmlElement* element;
528 if((element = (TiXmlElement*) comptag->FirstChild(
"name")))
529 os.
setName(parser->parseText(element->GetText()).c_str());
530 if((element = (TiXmlElement*) comptag->FirstChild(
"distribution")))
532 if((element = (TiXmlElement*) comptag->FirstChild(
"release")))
533 os.
setRelease(parser->parseText(element->GetText()).c_str());
567 TiXmlElement* element;
568 if((element = (TiXmlElement*) comptag->FirstChild(
"total_space")))
570 if((element = (TiXmlElement*) comptag->FirstChild(
"free_space")))
579 TiXmlElement* element;
580 if((element = (TiXmlElement*) comptag->FirstChild(
"total_space")))
582 if((element = (TiXmlElement*) comptag->FirstChild(
"free_space")))
591 TiXmlElement* element;
592 if((element = (TiXmlElement*) comptag->FirstChild(
"architecture")))
594 if((element = (TiXmlElement*) comptag->FirstChild(
"model")))
595 proc.
setModel(parser->parseText(element->GetText()).c_str());
596 if((element = (TiXmlElement*) comptag->FirstChild(
"cores")))
597 proc.
setCores((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
598 if((element = (TiXmlElement*) comptag->FirstChild(
"siblings")))
599 proc.
setSiblings((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
600 if((element = (TiXmlElement*) comptag->FirstChild(
"frequency")))
601 proc.
setFrequency(atof(parser->parseText(element->GetText()).c_str()));
609 TiXmlElement* element;
610 if((element = (TiXmlElement*) comptag->FirstChild(
"ip4")))
611 net.
setIP4(parser->parseText(element->GetText()).c_str());
612 if((element = (TiXmlElement*) comptag->FirstChild(
"ip6")))
613 net.
setIP6(parser->parseText(element->GetText()).c_str());
614 if((element = (TiXmlElement*) comptag->FirstChild(
"mac")))
615 net.
setMAC(parser->parseText(element->GetText()).c_str());
624 auto* element = (TiXmlElement*) comptag->FirstChild(
"name");
625 if(element && element->GetText())
627 yport.
setName(parser->parseText(element->GetText()).c_str());
628 yport.
setPort(parser->parseText(element->GetText()).c_str());
634 war<<
"yarp_port from "<<szFile<<
" at line " <<comptag->Row()<<
" has no name.";
643 TiXmlElement* element;
644 if((element = (TiXmlElement*) comptag->FirstChild(
"name")))
645 gpu.
setName(parser->parseText(element->GetText()).c_str());
646 if((element = (TiXmlElement*) comptag->FirstChild(
"capability")))
648 if((element = (TiXmlElement*) comptag->FirstChild(
"cores")))
649 gpu.
setCores((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
650 if((element = (TiXmlElement*) comptag->FirstChild(
"frequency")))
651 gpu.
setFrequency(atof(parser->parseText(element->GetText()).c_str()));
652 if((element = (TiXmlElement*) comptag->FirstChild(
"register_block")))
654 if((element = (TiXmlElement*) comptag->FirstChild(
"thread_block")))
655 gpu.
setThreadPerBlock((
size_t)atoi(parser->parseText(element->GetText()).c_str()));
656 if((element = (TiXmlElement*) comptag->FirstChild(
"overlap")))
658 if(
compareString(parser->parseText(element->GetText()).c_str(),
"yes"))
666 if(comptag->FirstChild(
"global_memory"))
668 TiXmlElement* element;
669 element = (TiXmlElement*) comptag->FirstChild(
"global_memory");
670 if((element = (TiXmlElement*) element->FirstChild(
"total_space")))
675 if(comptag->FirstChild(
"shared_memory"))
677 TiXmlElement* element;
678 element = (TiXmlElement*) comptag->FirstChild(
"shared_memory");
679 if((element = (TiXmlElement*) element->FirstChild(
"total_space")))
684 if(comptag->FirstChild(
"constant_memory"))
686 TiXmlElement* element;
687 element = (TiXmlElement*) comptag->FirstChild(
"constant_memory");
688 if((element = (TiXmlElement*) element->FirstChild(
"total_space")))
694 module.addResource(computer);