GetConstantNode.cc
5.73 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* GetConstantNode.cc
*
* Created on: Sep 18, 2018
* Author: AKKA
*/
#include "ServicesServer.hh"
#include "Parameter.hh"
#include "ParamGet.hh"
#include "ParamGetConstant.hh"
#include "ParameterManager.hh"
using namespace AMDA::Parameters;
#include "Constant.hh"
#include "Config.hh"
#include "GetConstantNode.hh"
#include "ConstantParamData.hh"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace XMLParameterConfigurator {
class ConstantParamNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
ConstantParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() {
}
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext)
{
LOG4CXX_DEBUG(gLogger, "ConstantParamNode::proceed: '" << pNode->name << "' node")
// Context setting
ServicesServer* lServicesServer = pContext.get<ServicesServer*>();
Parameter* lParentParameter = pContext.get<Parameter*>();
ParameterManager* lParameterManager = pContext.get<ParameterManager*>();
// Attributes list
try {
// Sampling
xmlChar* lSampling = xmlGetProp(pNode, (const xmlChar*)"sampling");
std::string samplingStr;
double sampling = 0.;
if (lSampling) {
samplingStr = std::string((const char*) lSampling);
boost::trim(samplingStr);
xmlFree(lSampling);
if (samplingStr.empty()) {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@sampling")
}
try {
sampling = boost::lexical_cast<double>(samplingStr);
} catch (const boost::bad_lexical_cast &e) {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@sampling")
}
if (sampling <= 0) {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@sampling")
}
}
else {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@sampling")
}
// Type
xmlChar* lType = xmlGetProp(pNode, (const xmlChar*)"type");
std::string typeStr;
AMDA::ConstantInterface::ConstantParamType type = AMDA::ConstantInterface::TYPE_FLOAT;
if (lType) {
typeStr = std::string((const char*) lType);
boost::trim(typeStr);
boost::algorithm::to_lower(typeStr);
xmlFree(lType);
if (typeStr.compare("float") == 0) {
type = AMDA::ConstantInterface::TYPE_FLOAT;
}
else if (typeStr.compare("double") == 0) {
type = AMDA::ConstantInterface::TYPE_DOUBLE;
}
else if (typeStr.compare("int") == 0) {
type = AMDA::ConstantInterface::TYPE_INT;
}
else if (typeStr.compare("short") == 0) {
type = AMDA::ConstantInterface::TYPE_SHORT;
}
else {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@type")
}
}
else {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@type")
}
// Value
xmlChar* lValue = xmlGetProp(pNode, (const xmlChar*)"value");
std::string valueStr;
double value = 0.;
if (lValue) {
valueStr = std::string((const char*) lValue);
boost::trim(valueStr);
xmlFree(lValue);
if (valueStr.empty()) {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@value")
}
try {
value = boost::lexical_cast<double>(valueStr);
} catch (const boost::bad_lexical_cast &e) {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@value")
}
}
else {
ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@value")
}
// Dim1
xmlChar* lDim1 = xmlGetProp(pNode, (const xmlChar*)"dim1");
std::string dim1Str("1");
int dim1 = 1;
if (lDim1) {
dim1Str = std::string((const char*) lDim1);
boost::trim(dim1Str);
xmlFree(lDim1);
try {
dim1 = boost::lexical_cast<int>(dim1Str);
} catch (const boost::bad_lexical_cast &e) {
dim1Str = "1";
dim1 = 1;
}
}
// Dim 2
xmlChar* lDim2 = xmlGetProp(pNode, (const xmlChar*)"dim2");
std::string dim2Str("1");
int dim2 = 1;
if (lDim2) {
dim2Str = std::string((const char*) lDim2);
boost::trim(dim2Str);
xmlFree(lDim2);
try {
dim2 = boost::lexical_cast<int>(dim2Str);
} catch (const boost::bad_lexical_cast &e) {
dim2Str = "1";
dim2 = 1;
}
}
//build unique param id
std::string paramId = "constant_";
paramId += samplingStr;
paramId += "_";
paramId += typeStr;
paramId += "_";
paramId += valueStr;
paramId += "_";
paramId += dim1Str;
paramId += "_";
paramId += dim2Str;
lParameterManager->applyParamIdCorrection(paramId);
ParameterSPtr lParameter;
if ( lParameterManager->addParameter(lParentParameter,paramId,lParameter)) {
const char *lSouceParamGet = "CONSTANT";
AMDA::ConstantInterface::ParamGetConstantSPtr lParamGet(dynamic_cast<AMDA::ConstantInterface::ParamGetConstant*>(lServicesServer->getParamGet( lSouceParamGet, *lParameter)));
DataWriterSPtr lDataWriter( lParamGet);
std::string* xmlFileName = pContext.get<std::string*>();
lDataWriter->setSignatureTrigger(*xmlFileName);
lParamGet->setSampling(sampling);
lParamGet->setType(type);
lParamGet->setValue(value);
lParamGet->setDim1(dim1);
lParamGet->setDim2(dim2);
lParameter->setDataWriter(lDataWriter);
AMDA::Parameters::CfgContext lContext(pContext);
lContext.push<AMDA::ConstantInterface::ParamGetConstant*>(lParamGet.get());
NodeGrpCfg::proceed(pNode, lContext);
}
} catch (...) {
throw;
}
}
};
GetConstantNode::GetConstantNode() : NodeGrpCfg()
{
getChildList()["param"] = NodeCfgSPtr(new XMLParameterConfigurator::ConstantParamNode());
}
void GetConstantNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext)
{
NodeGrpCfg::proceed(pNode, pContext);
}
}/* namespace XMLParameterConfigurator */
} /* namespace AMDA */