ParamNode.cc
3.93 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
119
120
121
122
123
124
125
126
/**
* ParamNode.cc
*
* Created on: 18 oct. 2012
* Author: AKKA IS
*/
#include <sstream>
#include <boost/shared_ptr.hpp>
#include "Config.hh"
#include "ParameterManager.hh"
#include "Parameter.hh"
#include "ParamGet.hh"
#include "ServicesServer.hh"
#include "Parameter.hh"
#include "ParamNode.hh"
#include "ProcessNode.hh"
#include "CalibrationNode.hh"
#include "ManualCalibrationNode.hh"
#include "GetAMDAParamNode.hh"
#include "Constant.hh"
using namespace log4cxx;
#define strXMLFree(str) if(str) { xmlFree(str); str=NULL; }
using namespace AMDA::Parameters;
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace XMLParameterConfigurator {
class NodeTimeResolution: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) {
LOG4CXX_DEBUG(gLogger, "NodeTimeResolution::proceed")
Parameter* p = context.get<Parameter*>();
if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
p->setTimeResolution(atof((char*)pNode->children->content));
}
}
};
class NodeGapThreshold: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) {
LOG4CXX_DEBUG(gLogger, "NodeGapThreshold::proceed")
Parameter* p = context.get<Parameter*>();
if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
p->setGapThreshold(atof((char*)pNode->children->content));
}
}
};
class NodeReferenceParameter: public AMDA::XMLConfigurator::NodeCfg {
public:
void proceed( xmlNodePtr pNode, const AMDA::Parameters::CfgContext& context) {
LOG4CXX_DEBUG(gLogger, "NodeReferenceParameter::proceed")
Parameter* p = context.get<Parameter*>();
if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
std::string refParam = (char*)pNode->children->content;
p->setReferenceParameter(refParam);
}
}
};
ParamNode::ParamNode() : AMDA::XMLConfigurator::NodeGrpCfg()
{
LOG4CXX_DEBUG(gLogger, "ParamNode Constructor")
getChildList()["time_resolution"]=NodeCfgSPtr(new NodeTimeResolution);
getChildList()["gap_threshold"]=NodeCfgSPtr(new NodeGapThreshold);
getChildList()["reference_parameter"]=NodeCfgSPtr(new NodeReferenceParameter);
getChildList()["process"]=NodeCfgSPtr(new ProcessNode());
getChildList()["clbManual"]=NodeCfgSPtr(new ManualCalibrationNode());
getChildList()["clbProcess"]=NodeCfgSPtr(new CalibrationNode());
NodeCfgSPtr getNode = NodeCfgSPtr(new NodeGrpCfg);
getChildList()["get"]=getNode;
addNodeParser("get/amdaParam",NodeCfgSPtr(new GetAMDAParamNode));
// Output group node
NodeGrpCfg* lOutputNode = new NodeGrpCfg();
getChildList()["output"] = NodeCfgSPtr(lOutputNode);
}
ParamNode::~ParamNode()
{
LOG4CXX_DEBUG(gLogger, "~ParamNode")
}
void ParamNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext)
{
LOG4CXX_DEBUG(gLogger, "ParamNode::proceed")
//ServicesServer* lServicesServer = pContext.get<ServicesServer*>();
ParameterManager* lParameterManager = pContext.get<ParameterManager*>();
xmlChar* lParamName = NULL;
try {
if (!(lParamName = xmlGetProp(pNode, (const xmlChar *) "id"))) {
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << PARAMNAME)
}
ParameterSPtr parameter;
if ( lParameterManager->addParameter(NULL, std::string((char*)lParamName), parameter)) {
parameter->setInfoId(std::string((char*)lParamName));
AMDA::Parameters::CfgContext lContext(pContext);
lContext.push<Parameter*>(parameter.get());
NodeGrpCfg::proceed(pNode, lContext);
}
} catch (...) {
if (lParamName) {
xmlFree(lParamName);
}
throw;
}
if (lParamName) {
xmlFree(lParamName);
}
}
}/* namespace XMLParameterConfigurator */
} /* namespace AMDA */