36 #include <libxml/parser.h> 42 xmlParserCtxtPtr pContext{xmlNewParserCtxt()};
44 xmlDocPtr pDoc = xmlCtxtReadFile(pContext,
45 sConfigurationFile.c_str(),
54 throw makeException<ConfigureException>(
"Failed to parse document: %s",
55 sConfigurationFile.c_str());
58 if(pContext->valid == 0)
60 throw makeException<ConfigureException>(
"Failed to validate document: %s",
61 sConfigurationFile.c_str());
64 xmlNodePtr pRoot = xmlDocGetRootElement(pDoc);
66 xmlChar * pLibrary = xmlGetProp(pRoot,BAD_CAST
"library");
68 sPluginName_ =
reinterpret_cast<char *
>(pLibrary);
72 if(!xmlStrcmp(pRoot->name,BAD_CAST
"mac"))
76 else if(!xmlStrcmp(pRoot->name,BAD_CAST
"phy"))
80 else if(!xmlStrcmp(pRoot->name,BAD_CAST
"shim"))
84 else if(!xmlStrcmp(pRoot->name,BAD_CAST
"eventgenerator"))
88 else if(!xmlStrcmp(pRoot->name,BAD_CAST
"eventagent"))
92 else if(!xmlStrcmp(pRoot->name,BAD_CAST
"transport"))
98 throw makeException<ConfigureException>(
"Unkown plugin type: %s",
102 for(xmlNodePtr pNode = pRoot->children; pNode; pNode = pNode->next)
104 if(pNode->type == XML_ELEMENT_NODE)
106 if(!xmlStrcmp(pNode->name,BAD_CAST
"param"))
108 xmlChar * pName = xmlGetProp(pNode,BAD_CAST
"name");
109 xmlChar * pValue = xmlGetProp(pNode,BAD_CAST
"value");
111 std::string sName{std::string{
reinterpret_cast<const char *
>(pName)}};
112 std::string sValue{std::string{
reinterpret_cast<const char *
>(pValue)}};
118 if(isUniqueConfigurationName(sName))
120 request_.push_back(std::make_pair(sName,
121 std::vector<std::string>{sValue}));
125 throw makeException<ConfigureException>(
"Duplicate parameter name: %s",
129 else if(!xmlStrcmp(pNode->name,BAD_CAST
"paramlist"))
131 xmlChar * pName = xmlGetProp(pNode,BAD_CAST
"name");
133 std::string sName{std::string{
reinterpret_cast<const char *
>(pName)}};
138 if(isUniqueConfigurationName(sName))
140 std::vector<std::string> values;
142 for(xmlNodePtr pItem = pNode->children; pItem; pItem = pItem->next)
144 if(pItem->type == XML_ELEMENT_NODE)
146 if(!xmlStrcmp(pItem->name,BAD_CAST
"item"))
148 xmlChar * pValue = xmlGetProp(pItem,BAD_CAST
"value");
149 values.push_back(reinterpret_cast<char *>(pValue));
155 request_.push_back(std::make_pair(sName,values));
159 throw makeException<ConfigureException>(
"Duplicate parameter name: %s",
180 EMANE::Application::ConfigurationLoader::isUniqueConfigurationName(std::string & sName)
182 return std::find_if(request_.begin(),
184 std::bind(std::equal_to<std::string>(),
185 std::bind(&ConfigurationUpdateRequest::value_type::first,
186 std::placeholders::_1),
187 sName)) == request_.end();
const std::string getPluginName() const
const EMANE::ConfigurationUpdateRequest & getConfigurationUpdateRequest() const
std::vector< ConfigurationNameStringValues > ConfigurationUpdateRequest
ConfigurationLoader(std::string &sConfigurationFile)
PluginType getPluginType() const