Blame view

src/ParamGetImpl/DDServerInterface/GetDDBaseNode.cc 8.1 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * GetDDBaseNode.cc
 *
 *  Created on: Oct 31, 2012
 *      Author: f.casimir
 */
//#include <boost/scope_exit.hpp>
//#include "ScopeExit.hh"
#include "ServicesServer.hh"
#include "Parameter.hh"
#include "FileConfigurator.hh"
#include "ParamGet.hh"
//#include "ProcessNode.hh"
#include "ParamGetDDBase.hh"
#include "ParameterManager.hh"

using namespace AMDA::Parameters;

#include "Constant.hh"

#include "Config.hh"
#include "GetDDBaseNode.hh"

using namespace AMDA::XMLConfigurator;

namespace AMDA {
namespace XMLParameterConfigurator {

class DDCalibrationNode: public AMDA::XMLConfigurator::NodeCfg {
public:
	/**
	 * @brief read Calibration info name vi/baseParam/clb@name.
	 */
	void proceed(xmlNodePtr pNode,
			const AMDA::Parameters::CfgContext& context) {
		LOG4CXX_DEBUG(gLogger, "CalibrationNode::proceed")
		ParamGetDDBase* lParamGet = context.get<ParamGetDDBase*>();
		xmlChar* lParamName = NULL;

		try {

			if ((lParamName = xmlGetProp(pNode, (const xmlChar *) "name"))) {
				lParamGet->createInfoRequest((const char*) lParamName);
			} else {
				ERROR_EXCEPTION(
						ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "name")
			}

		} catch (...) {
			if (lParamName) {
				xmlFree(lParamName);
			}
			throw;
		}
		if (lParamName) {
			xmlFree(lParamName);
		}
	}
};
class BaseParamNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	BaseParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() {
		getChildList()["clb"]=NodeCfgSPtr(new DDCalibrationNode());
	}

	/**
	 * @brief read Parameter name vi/baseParam@name and child.
	 */
	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
fbe3c2bb   Benjamin Renard   First commit
70
71
72
73
74
75
76
77
78
		LOG4CXX_DEBUG(gLogger,	"NodeGetDDBase::proceed: '" << pNode->name << "' node")

		// Context setting
		ServicesServer* lServicesServer = pContext.get<ServicesServer*>();
		Parameter* lParentParameter = pContext.get<Parameter*>();
		ParameterManager* lParameterManager =  pContext.get<ParameterManager*>();
		xmlChar*lVIName = pContext.get<xmlChar*>();

		// Attributes list
fbe3c2bb   Benjamin Renard   First commit
79
80
		try {

c6a67968   Benjamin Renard   Fix some violatio...
81
82
83
84
85
86
87
			xmlChar* lParamName = xmlGetProp(pNode, (const xmlChar *) PARAMNAME);
			std::string paramNameStr;
			if (lParamName) {
				paramNameStr = std::string((const char*) lParamName);
				xmlFree(lParamName);
			}
			else {
fbe3c2bb   Benjamin Renard   First commit
88
89
90
				ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << PARAMNAME)
			}

52e57055   Benjamin Renard   Fix a bug with pa...
91
92
93
94
95
96
97
98
99
100
101
102
103
			xmlChar* lDim3NumValue = xmlGetProp(pNode, (const xmlChar *) "dim3Num");
			std::string paramDim3NumStr;
			if (lDim3NumValue != NULL) {
				paramDim3NumStr = std::string((const char*) lDim3NumValue);
				xmlFree(lDim3NumValue);
 			}

			xmlChar* lDim3CutIndexValue = xmlGetProp(pNode, (const xmlChar *) "dim3CutIndex");
			std::string paramDim3CutIndexStr;
			if (lDim3CutIndexValue != NULL) {
				paramDim3CutIndexStr = std::string((const char*) lDim3CutIndexValue);
				xmlFree(lDim3CutIndexValue);
			}
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
104
105
106
107
108
109
110
111
112
113
114
115
116
117
                        
                        		xmlChar* lMinSumIndexValue = xmlGetProp(pNode, (const xmlChar *) "minSumIndex");
			std::string paramMinSumIndexStr;
			if (lMinSumIndexValue != NULL) {
				paramMinSumIndexStr = std::string((const char*) lMinSumIndexValue);
				xmlFree(lMinSumIndexValue);
			}
                        
                                                	xmlChar* lMaxSumIndexValue = xmlGetProp(pNode, (const xmlChar *) "maxSumIndex");
			std::string paramMaxSumIndexStr;
			if (lMaxSumIndexValue != NULL) {
				paramMaxSumIndexStr = std::string((const char*) lMaxSumIndexValue);
				xmlFree(lMaxSumIndexValue);
			}
52e57055   Benjamin Renard   Fix a bug with pa...
118

fbe3c2bb   Benjamin Renard   First commit
119
120
121
122
			//build unique param id
			std::string paramId = std::string((const char*) lVIName);
			std::replace( paramId.begin(), paramId.end(), ':', '_');
			paramId += "_";
c6a67968   Benjamin Renard   Fix some violatio...
123
			paramId += paramNameStr;
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
124
125
126
127
                                                            if( ( !paramDim3CutIndexStr.empty()  &&  !paramMinSumIndexStr.empty() ) ||
                                                                 ( !paramDim3CutIndexStr.empty()  &&  !paramMaxSumIndexStr.empty() ) ){
                                                                              ERROR_EXCEPTION( "Too much attributes: CUT and SUM")
                                                            }
52e57055   Benjamin Renard   Fix a bug with pa...
128
			if (!paramDim3NumStr.empty()) {
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
129
                                                                       if (!paramDim3CutIndexStr.empty()) {
52e57055   Benjamin Renard   Fix a bug with pa...
130
131
				paramId += "_CUT_";
				paramId += paramDim3NumStr;
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
132
133
134
135
136
137
138
139
140
141
142
143
				paramId += "_";
				paramId += paramDim3CutIndexStr;
		                               }else if( !paramMinSumIndexStr.empty() && !paramMaxSumIndexStr.empty() ){
                                                   		paramId += "_SUM_";
				paramId += paramDim3NumStr;
                                                                                paramId += "_";
				paramId += paramMinSumIndexStr;
                                                                                paramId += "_";
				paramId += paramMaxSumIndexStr;
                                                                                }
                                                                     }
			
fbe3c2bb   Benjamin Renard   First commit
144
145
146
147
			lParameterManager->applyParamIdCorrection(paramId);

			ParameterSPtr lParameter;
			if ( lParameterManager->addParameter(lParentParameter,paramId,lParameter)) {
c6a67968   Benjamin Renard   Fix some violatio...
148
				const char *lSouceParamGet = "DDBASE";
fbe3c2bb   Benjamin Renard   First commit
149
150
151
152
153
				ParamGetDDBaseSPtr lParamGet(dynamic_cast<ParamGetDDBase*>(lServicesServer->getParamGet( lSouceParamGet, *lParameter)));
				DataWriterSPtr lDataWriter( lParamGet);

				std::string* xmlFileName = pContext.get<std::string*>();
				lDataWriter->setSignatureTrigger(*xmlFileName);
c6a67968   Benjamin Renard   Fix some violatio...
154
				lParamGet->setParName(paramNameStr.c_str());
fbe3c2bb   Benjamin Renard   First commit
155
156
157
158
159
160
161
162
163
164
165
166
167
				lParameter->setDataWriter(lDataWriter);
				lParamGet->setViName((const char*) lVIName);
				AMDA::Parameters::CfgContext lContext(pContext);
				lContext.push<ParamGetDDBase*>(lParamGet.get());

				// useNearestValue
				xmlChar* lUseNearestValue = xmlGetProp(pNode, (const xmlChar *) "useNearestValue");
				if (lUseNearestValue != NULL)
				{
					lParamGet->setUseNearestValue(strcmp((const char*)lUseNearestValue,"true") == 0);
					xmlFree(lUseNearestValue);
				}

0dfc4085   Benjamin Renard   Give the possibil...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
				// maxDim1Size
				xmlChar* lmaxDim1Size = xmlGetProp(pNode, (const xmlChar *) "maxDim1Size");
				if (lmaxDim1Size != NULL)
				{
					lParamGet->setMaxDim1Size(atoi((const char*)lmaxDim1Size));
					xmlFree(lmaxDim1Size);
				}

				// maxDim2Size
				xmlChar* lmaxDim2Size = xmlGetProp(pNode, (const xmlChar *) "maxDim2Size");
				if (lmaxDim2Size != NULL)
				{
					lParamGet->setMaxDim2Size(atoi((const char*)lmaxDim2Size));
					xmlFree(lmaxDim2Size);
				}

				// maxDim3Size
				xmlChar* lmaxDim3Size = xmlGetProp(pNode, (const xmlChar *) "maxDim3Size");
				if (lmaxDim3Size != NULL)
				{
					lParamGet->setMaxDim3Size(atoi((const char*)lmaxDim3Size));
					xmlFree(lmaxDim3Size);
				}

ff482c31   Benjamin Renard   Give the possibil...
192
				// dim3Num
52e57055   Benjamin Renard   Fix a bug with pa...
193
				if (!paramDim3NumStr.empty())
ff482c31   Benjamin Renard   Give the possibil...
194
				{
52e57055   Benjamin Renard   Fix a bug with pa...
195
					lParamGet->setDim3Num(atoi(paramDim3NumStr.c_str()));
ff482c31   Benjamin Renard   Give the possibil...
196
197
198
				}

				// dim3CutIndex
52e57055   Benjamin Renard   Fix a bug with pa...
199
				if (!paramDim3CutIndexStr.empty())
ff482c31   Benjamin Renard   Give the possibil...
200
				{
52e57055   Benjamin Renard   Fix a bug with pa...
201
					lParamGet->setDim3CutIndex(atoi(paramDim3CutIndexStr.c_str()));
ff482c31   Benjamin Renard   Give the possibil...
202
				}
6edc9ff8   Hacene SI HADJ MOHAND   rm_6463
203
204
205
206
207
208
209
210
211
212
213
214
                                
 				// minSumIndex
				if (!paramMinSumIndexStr.empty())
				{
					lParamGet->setMinSumIndex(atoi(paramMinSumIndexStr.c_str()));
				}
                                		                     // maxSumIndex
				if (!paramMaxSumIndexStr.empty())
				{
					lParamGet->setMaxSumIndex(atoi(paramMaxSumIndexStr.c_str()));
				}
                                
ff482c31   Benjamin Renard   Give the possibil...
215

fbe3c2bb   Benjamin Renard   First commit
216
217
218
219
220
				NodeGrpCfg::proceed(pNode, lContext);
			}


		} catch (...) {
fbe3c2bb   Benjamin Renard   First commit
221
222
			throw;
		}
fbe3c2bb   Benjamin Renard   First commit
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
	}
};

GetDDBaseNode::GetDDBaseNode() : NodeGrpCfg() {
	getChildList()["baseParam"]=NodeCfgSPtr(new XMLParameterConfigurator::BaseParamNode());
}

void GetDDBaseNode::proceed(xmlNodePtr pNode,	const AMDA::Parameters::CfgContext& pContext) {
	LOG4CXX_DEBUG(gLogger, "ViNode::proceed")
	xmlChar* lVIName = NULL;
	try {
		if (!(lVIName = xmlGetProp(pNode, (const xmlChar *) "name"))) {
			ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "name")
		}

		AMDA::Parameters::CfgContext lContext(pContext);
		lContext.push<xmlChar*>(lVIName);

		NodeGrpCfg::proceed(pNode, lContext);
	} catch (...) {
		if (lVIName) {
			xmlFree(lVIName);
		}
		throw;
	}
	if (lVIName) {
		xmlFree(lVIName);
	}
}

}/* namespace XMLParameterConfigurator */
} /* namespace AMDA */