35 if ((strPath.rfind(directorySeparator) == std::string::npos) || (strPath.rfind(directorySeparator) != strPath.size() - 1)) {
36 strPath = strPath + std::string(directorySeparator);
53 strFileName = szFileName;
77 if(!strFileName.empty())
79 fileNames.push_back(strFileName);
85 logger->
addError(
"No module path is introduced.");
91 if ((dir = opendir(strPath.c_str())) ==
nullptr)
94 err<<
"Cannot access "<<strPath;
100 while((entry = readdir(dir)))
102 std::string name = entry->d_name;
105 std::string ext = name.substr(name.size()-3,3);
107 fileNames.push_back(strPath + name);
147 if (fileNames.empty()) {
151 std::string fname = fileNames.back();
152 fileNames.pop_back();
153 mod = parsXml(fname.c_str());
162 std::vector<std::string>::iterator itr;
163 for(itr=fileNames.begin(); itr<fileNames.end(); itr++)
165 Module* mod = parsXml((*itr).c_str());
166 if (mod && (std::string(mod->
getName()) == strName)) {
176Module* XmlModLoader::parsXml(
const char* szFile)
181 TiXmlDocument doc(szFile);
185 err<<
"Syntax error while loading "<<szFile<<
" at line "\
186 <<doc.ErrorRow()<<
": ";
187 err<<doc.ErrorDesc();
193 TiXmlElement *root = doc.RootElement();
197 err<<
"Syntax error while loading "<<szFile<<
" . ";
198 err<<
"No root element.";
214 auto* name = (TiXmlElement*) root->FirstChild(
"name");
215 if(!name || !name->GetText())
218 err<<
"Module from "<<szFile<<
" has no name.";
223 for(TiXmlElement* var = root->FirstChildElement(
"var"); var; var = var->NextSiblingElement())
225 if(var->Attribute(
"name") && var->GetText())
227 parser->
addVariable(var->Attribute(
"name"), var->GetText());
231 module.setXmlFile(szFile);
234 module.setName(parser->parseText(name->GetText()).c_str());
239 if ((desc = (TiXmlElement*)root->FirstChild(
"description"))) {
240 module.setDescription(parser->parseText(desc->GetText()).c_str());
245 if ((ver = (TiXmlElement*)root->FirstChild(
"version"))) {
246 module.setVersion(parser->parseText(ver->GetText()).c_str());
251 TiXmlElement* arguments;
252 if ((arguments = (TiXmlElement*)root->FirstChild(
"arguments"))) {
253 for(TiXmlElement* param = arguments->FirstChildElement(); param;
254 param = param->NextSiblingElement())
260 bool brequired =
false;
266 param->Attribute(
"desc"));
267 arg.setDefault(param->Attribute(
"default"));
268 module.addArgument(arg);
276 bool brequired =
false;
282 param->Attribute(
"desc"),
true);
283 arg.setDefault(param->Attribute(
"default"));
284 module.addArgument(arg);
290 war<<
"Unrecognized tag from "<<szFile<<
" at line "\
300 if ((rank = (TiXmlElement*)root->FirstChild(
"rank")) && rank->GetText()) {
301 module.setRank(atoi(parser->parseText(rank->GetText()).c_str()));
306 TiXmlElement* authors;
307 if ((authors = (TiXmlElement*)root->FirstChild(
"authors"))) {
308 for(TiXmlElement* ath = authors->FirstChildElement(); ath;
309 ath = ath->NextSiblingElement())
314 if (ath->GetText()) {
317 if (ath->Attribute(
"email")) {
318 author.
setEmail(ath->Attribute(
"email"));
320 module.addAuthor(author);
325 war<<
"Unrecognized tag from "<<szFile<<
" at line "\
334 if (root->FirstChild(
"data")) {
335 for(TiXmlElement* data = root->FirstChild(
"data")->FirstChildElement();
336 data; data = data->NextSiblingElement())
343 if (
compareString(data->Attribute(
"port_type"),
"stream") || !data->Attribute(
"port_type")) {
345 }
else if (
compareString(data->Attribute(
"port_type"),
"event")) {
347 }
else if (
compareString(data->Attribute(
"port_type"),
"service")) {
351 war<<
"Unknown port type \'"<<data->Attribute(
"port_type")<<
"\' from "<<szFile<<
" at line "\
352 <<data->Row()<<
". Available types : stream, event, service";
357 TiXmlElement* element;
360 if ((element = (TiXmlElement*)data->FirstChild(
"type"))) {
364 war<<
"Output data from "<<szFile<<
" at line "\
365 <<data->Row()<<
" has no type.";
372 if((element = (TiXmlElement*) data->FirstChild(
"port")))
375 output.
setCarrier(element->Attribute(
"carrier"));
380 war<<
"Output data from "<<szFile<<
" at line "\
381 <<data->Row()<<
" has no port.";
385 if ((element = (TiXmlElement*)data->FirstChild(
"description"))) {
389 module.addOutput(output);
397 if (
compareString(data->Attribute(
"port_type"),
"stream") || !data->Attribute(
"port_type")) {
399 }
else if (
compareString(data->Attribute(
"port_type"),
"event")) {
401 }
else if (
compareString(data->Attribute(
"port_type"),
"service")) {
405 war<<
"Unknown port type \'"<<data->Attribute(
"port_type")<<
"\' from "<<szFile<<
" at line "\
406 <<data->Row()<<
". Available types : stream, event, service";
410 TiXmlElement* element;
414 if ((element = (TiXmlElement*)data->FirstChild(
"type"))) {
418 war<<
"Input data from "<<szFile<<
" at line "\
419 <<data->Row()<<
" has no type.";
426 if((element = (TiXmlElement*) data->FirstChild(
"port")))
429 input.
setCarrier(element->Attribute(
"carrier"));
434 war<<
"Input data from "<<szFile<<
" at line "\
435 <<data->Row()<<
" has no port.";
439 if ((element = (TiXmlElement*)data->FirstChild(
"description"))) {
443 if ((element = (TiXmlElement*)data->FirstChild(
"required"))) {
449 if ((element = (TiXmlElement*)data->FirstChild(
"priority"))) {
455 module.addInput(input);
460 if(root->FirstChild(
"services")) {
461 for(TiXmlElement* services = root->FirstChild(
"services")->FirstChildElement();
462 services; services = services->NextSiblingElement())
469 TiXmlElement* element;
470 if((element = (TiXmlElement*) services->FirstChild(
"port"))) {
474 if ((element = (TiXmlElement*)services->FirstChild(
"description"))) {
477 if ((element = (TiXmlElement*)services->FirstChild(
"type"))) {
482 module.addInput(input);
489 TiXmlElement* element;
490 if((element = (TiXmlElement*) services->FirstChild(
"port"))) {
494 if ((element = (TiXmlElement*)services->FirstChild(
"description"))) {
497 if ((element = (TiXmlElement*)services->FirstChild(
"type"))) {
502 module.addOutput(output);
509 TiXmlElement* element;
510 if((element = (TiXmlElement*) root->FirstChild(
"deployer")))
512 module.setBroker(parser->parseText(element->GetText()).c_str());
513 module.setNeedDeployer(true);
517 if (root->FirstChild(
"dependencies")) {
518 for(TiXmlElement* restag = root->FirstChild(
"dependencies")->FirstChildElement();
519 restag; restag = restag->NextSiblingElement())
526 for(TiXmlElement* comptag = restag->FirstChildElement();
527 comptag; comptag = comptag->NextSiblingElement())
543 TiXmlElement* element;
544 if ((element = (TiXmlElement*)comptag->FirstChild(
"name"))) {
547 if ((element = (TiXmlElement*)comptag->FirstChild(
"distribution"))) {
550 if ((element = (TiXmlElement*)comptag->FirstChild(
"release"))) {
586 TiXmlElement* element;
587 if ((element = (TiXmlElement*)comptag->FirstChild(
"total_space"))) {
590 if ((element = (TiXmlElement*)comptag->FirstChild(
"free_space"))) {
600 TiXmlElement* element;
601 if ((element = (TiXmlElement*)comptag->FirstChild(
"total_space"))) {
604 if ((element = (TiXmlElement*)comptag->FirstChild(
"free_space"))) {
614 TiXmlElement* element;
615 if ((element = (TiXmlElement*)comptag->FirstChild(
"architecture"))) {
618 if ((element = (TiXmlElement*)comptag->FirstChild(
"model"))) {
621 if ((element = (TiXmlElement*)comptag->FirstChild(
"cores"))) {
624 if ((element = (TiXmlElement*)comptag->FirstChild(
"siblings"))) {
627 if ((element = (TiXmlElement*)comptag->FirstChild(
"frequency"))) {
637 TiXmlElement* element;
638 if ((element = (TiXmlElement*)comptag->FirstChild(
"ip4"))) {
641 if ((element = (TiXmlElement*)comptag->FirstChild(
"ip6"))) {
644 if ((element = (TiXmlElement*)comptag->FirstChild(
"mac"))) {
647 module.addResource(net);
655 auto* element = (TiXmlElement*) comptag->FirstChild(
"name");
656 if(element && element->GetText())
665 war<<
"yarp_port from "<<szFile<<
" at line " <<comptag->Row()<<
" has no name.";
674 TiXmlElement* element;
675 if ((element = (TiXmlElement*)comptag->FirstChild(
"name"))) {
678 if ((element = (TiXmlElement*)comptag->FirstChild(
"capability"))) {
681 if ((element = (TiXmlElement*)comptag->FirstChild(
"cores"))) {
684 if ((element = (TiXmlElement*)comptag->FirstChild(
"frequency"))) {
687 if ((element = (TiXmlElement*)comptag->FirstChild(
"register_block"))) {
690 if ((element = (TiXmlElement*)comptag->FirstChild(
"thread_block"))) {
693 if((element = (TiXmlElement*) comptag->FirstChild(
"overlap")))
704 if(comptag->FirstChild(
"global_memory"))
706 TiXmlElement* element;
707 element = (TiXmlElement*) comptag->FirstChild(
"global_memory");
708 if ((element = (TiXmlElement*)element->FirstChild(
"total_space"))) {
714 if(comptag->FirstChild(
"shared_memory"))
716 TiXmlElement* element;
717 element = (TiXmlElement*) comptag->FirstChild(
"shared_memory");
718 if ((element = (TiXmlElement*)element->FirstChild(
"total_space"))) {
724 if(comptag->FirstChild(
"constant_memory"))
726 TiXmlElement* element;
727 element = (TiXmlElement*) comptag->FirstChild(
"constant_memory");
728 if ((element = (TiXmlElement*)element->FirstChild(
"total_space"))) {
735 module.addResource(computer);
void setName(const char *name)
void setEmail(const char *email)
void setProcessor(Processor &proc)
void setNetwork(Network &net)
bool addPeripheral(GenericResource &res)
void setPlatform(Platform &os)
void setStorage(Storage &stg)
void setMemory(Memory &mem)
Singleton class ErrorLogger.
void addError(const char *szError)
void addWarning(const char *szWarning)
static ErrorLogger * Instance()
Singleton class ErrorLogger.
void setFrequency(double f)
void setThreadPerBlock(size_t val)
void setOverlap(bool flag)
void setCompCompatibility(const char *cap)
void setConstantMemory(Capacity c)
void setSharedMemory(Capacity c)
void setResgisterPerBlock(size_t val)
void setGlobalMemory(Capacity c)
void setName(const char *szName)
void setXmlFile(const char *szFilename)
void setDescription(const char *szDesc)
void setFreeSpace(Capacity c)
void setTotalSpace(Capacity c)
void setIP4(const char *ip)
void setIP6(const char *ip)
void setMAC(const char *mac)
void setCarrier(const char *szCr)
void setPortType(NodeType type)
void setName(const char *szName)
void setDescription(const char *szDesc)
void setPort(const char *szPort)
void setArchitecture(const char *arch)
void setSiblings(size_t n)
void setModel(const char *model)
void setFrequency(double f)
void setPort(const char *szPort)
void setFreeSpace(Capacity c)
void setTotalSpace(Capacity c)
bool addVariable(const std::string &key, const std::string &value)
std::string parseText(const char *element)
Module * getNextModule() override
XmlModLoader(const char *szFileName)
load only one module indicated by its xml file name
static constexpr value_type preferred_separator
bool compareString(const char *szFirst, const char *szSecond)
std::stringstream OSTRINGSTREAM