PluginsParser.cc
4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: PluginsParser.cc
* Author: hacene
*
* Created on March 17, 2020, 10:16 AM
*/
#include "PluginsParser.hh"
#include "NodeCfg.hh"
#include <boost/lexical_cast.hpp>
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace Parameters {
class PluginNode : public NodeCfg {
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
if ((pNode->children != NULL) && (pNode->children->content != NULL)) {
AMDA::Parameters::PluginObject *pluginObject = pContext.get<AMDA::Parameters::PluginObject *>();
if (pluginObject != NULL) {
pluginObject->setPluginPath(std::string((char*) pNode->children->content));
} else {
// throw exception
}
}
}
};
class RequestProcessNode : public NodeGrpCfg {
public:
RequestProcessNode() : NodeGrpCfg() {
getChildList()["plugin"] = NodeCfgSPtr(new PluginNode);
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "name");
std::string name;
if (value != NULL) {
name = (char *) value;
xmlFree(value);
}
value = xmlGetProp(pNode, (const xmlChar *) "type");
std::string type;
if (value != NULL) {
type = (char *) value;
xmlFree(value);
}
if (!name.empty() && !type.empty()) {
AMDA::Parameters::CfgContext ctx;
PluginObject pluginObject;
ctx.push<PluginObject*>(&pluginObject);
pluginObject.setRequestProcess(name);
pluginObject.setType(type);
NodeGrpCfg::proceed(pNode, ctx);
AMDA::Parameters::AMDA_ProcessPluginMaps *processPluginMaps = pContext.get<AMDA::Parameters::AMDA_ProcessPluginMaps *>();
(*processPluginMaps)[type][name] = pluginObject.getPluginPath();
}
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief plugins node
*/
class PluginsNode : public NodeGrpCfg {
public:
PluginsNode() : NodeGrpCfg() {
getChildList()["requestProcess"] = NodeCfgSPtr(new RequestProcessNode);
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
// Proceed nodes
NodeGrpCfg::proceed(pNode, pContext);
}
};
///////////////////////////////////////////////////////////////////////////////
/*
* @brief plugins node parser
*/
PluginsParser::PluginsParser(const char* pXSDFile) : XMLConfigurator(pXSDFile, true) {
// functions root node
getXmlConfiguratorMap()["plugins"] = RootNodeCfgSPtr(new PluginsNode());
}
AMDA::Parameters::AMDA_ProcessPluginMaps PluginsParser::parse(const std::string& pluginsFile) {
AMDA::Parameters::CfgContext ctx;
AMDA::Parameters::AMDA_ProcessPluginMaps processPluginMaps;
ctx.push<AMDA::Parameters::AMDA_ProcessPluginMaps *> (&processPluginMaps);
// Check schema validity and parse xml file
try {
if (!XMLConfigurator::proceed(pluginsFile.c_str(), ctx, true)) {
return processPluginMaps;
}
} catch (...) {
throw;
}
return processPluginMaps;
}
} // end AMDA
} //end parameters