Blame view

src/ParamGetImpl/LocalFileInterface/GetLocalFileNode.cc 6.57 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
/*
 * GetLocalFileNode.cc
 *
 *  Created on: Nov 22, 2014
 *      Author: AKKA
 */

#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

#include "ServicesServer.hh"
#include "Parameter.hh"
#include "FileConfigurator.hh"
#include "ParamGet.hh"
#include "ParamGetLocalFile.hh"
#include "ParameterManager.hh"

using namespace AMDA::Parameters;

#include "Constant.hh"

#include "Config.hh"
#include "GetLocalFileNode.hh"
#include "LocalParamData.hh"

using namespace AMDA::XMLConfigurator;

namespace AMDA {
namespace XMLParameterConfigurator {

f5c53312   Benjamin Renard   Get calib info in...
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
class LocalCalibrationNode: public AMDA::XMLConfigurator::NodeCfg {
public:
	/**
	 * @brief read Calibration info name localvi/param/clb@name.
	 */
	void proceed(xmlNodePtr pNode,
			const AMDA::Parameters::CfgContext& context) {
		LOG4CXX_DEBUG(gLogger, "LocalCalibrationNode::proceed");
		AMDA::LocalFileInterface::ParamGetLocalFile* lParamGet = context.get<AMDA::LocalFileInterface::ParamGetLocalFile*>();
		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);
		}
	}
};
fbe3c2bb   Benjamin Renard   First commit
62
63
64
65

class LocalFileParamNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
	LocalFileParamNode() : AMDA::XMLConfigurator::NodeGrpCfg() {
f5c53312   Benjamin Renard   Get calib info in...
66
		getChildList()["clb"]=NodeCfgSPtr(new LocalCalibrationNode());
fbe3c2bb   Benjamin Renard   First commit
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
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext)
	{
		const char *lSouceParamGet = "LOCALFILE";
		LOG4CXX_DEBUG(gLogger,	"LocalFileParamNode::proceed: '" << pNode->name << "' node")

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

		// Attributes list
		xmlChar* lParamId = NULL;

		try {

			if (!(lParamId = xmlGetProp(pNode, (const xmlChar*)"id"))) {
				ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@id")
			}

			//build unique param id
			std::string paramId = "localfile_";
			paramId += std::string((const char*) lVIId);
			paramId += "_";
			paramId += std::string((const char*) lParamId);

			lParameterManager->applyParamIdCorrection(paramId);

			ParameterSPtr lParameter;
			if ( lParameterManager->addParameter(lParentParameter,paramId,lParameter)) {
				AMDA::LocalFileInterface::ParamGetLocalFileSPtr lParamGet(dynamic_cast<AMDA::LocalFileInterface::ParamGetLocalFile*>(lServicesServer->getParamGet( lSouceParamGet, *lParameter)));
				DataWriterSPtr lDataWriter( lParamGet);

				std::string* xmlFileName = pContext.get<std::string*>();
				lDataWriter->setSignatureTrigger(*xmlFileName);
				lParamGet->setParamId((const char*) lParamId);
				lParameter->setDataWriter(lDataWriter);
				lParamGet->setVIId((const char*) lVIId);

				//type
				xmlChar* value = NULL;
				if ((value = xmlGetProp(pNode, (const xmlChar*)"type")) != NULL)
				{
					if (strcmp((const char*)value,"float") == 0)
						lParamGet->setParamType(AMDA::LocalFileInterface::LocalParamType::TYPE_FLOAT);
					else if (strcmp((const char*)value,"double") == 0)
						lParamGet->setParamType(AMDA::LocalFileInterface::LocalParamType::TYPE_DOUBLE);
					else if (strcmp((const char*)value,"short") == 0)
						lParamGet->setParamType(AMDA::LocalFileInterface::LocalParamType::TYPE_SHORT);
					else if (strcmp((const char*)value,"int") == 0)
						lParamGet->setParamType(AMDA::LocalFileInterface::LocalParamType::TYPE_INT);
					else
					{
						LOG4CXX_ERROR(gLogger, "LocalFileParamNode::proceed - Unknown data type " << ((const char*)value))
					}
					xmlFree(value);
				}

				//size
				if ((value = xmlGetProp(pNode, (const xmlChar*)"size")) != NULL)
				{
					std::vector<std::string> dims;
					std::string dimsDef = (const char*)value;
					boost::split(dims, dimsDef, boost::is_any_of("*"));

					if (dims.size() == 1)
					{
						lParamGet->setParamDim1Size(std::stoi(dims[0]));
					}
					else if (dims.size() == 2)
					{
						lParamGet->setParamDim1Size(std::stoi(dims[0]));
						lParamGet->setParamDim2Size(std::stoi(dims[1]));
					}
					xmlFree(value);
				}

				//minSampling
				if ((value = xmlGetProp(pNode, (const xmlChar*)"minSampling")) != NULL)
				{
					lParamGet->setParamMinSampling(atof((const char*)value));
					xmlFree(value);
				}

				//maxSampling
				if ((value = xmlGetProp(pNode, (const xmlChar*)"maxSampling")) != NULL)
				{
					lParamGet->setParamMaxSampling(atof((const char*)value));
					xmlFree(value);
				}

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

f5c53312   Benjamin Renard   Get calib info in...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
				//timeFormat
				if ((value = xmlGetProp(pNode, (const xmlChar*)"timeFormat")) != NULL)
				{
					if (std::strcmp((const char*)value, "ISO") == 0)
						lParamGet->setTimeFormat(AMDA::LocalFileInterface::LocalTimeFormat::ISO);
					else
					{
						LOG4CXX_WARN(gLogger, "LocalFileParamNode::proceed - Unknown time format " << (const char*)value);
						lParamGet->setTimeFormat(AMDA::LocalFileInterface::LocalTimeFormat::DOUBLE);
					}
					xmlFree(value);
				}
				else
					lParamGet->setTimeFormat(AMDA::LocalFileInterface::LocalTimeFormat::DOUBLE);

fbe3c2bb   Benjamin Renard   First commit
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
				AMDA::Parameters::CfgContext lContext(pContext);
				lContext.push<AMDA::LocalFileInterface::ParamGetLocalFile*>(lParamGet.get());
				NodeGrpCfg::proceed(pNode, lContext);
			}
		} catch (...) {
			if (lParamId) {
				xmlFree(lParamId);
			}
			throw;
		}
		if (lParamId) {
			xmlFree(lParamId);
		}
	}
};

GetLocalFileNode::GetLocalFileNode() : NodeGrpCfg()
{
	getChildList()["param"] = NodeCfgSPtr(new XMLParameterConfigurator::LocalFileParamNode());
}

void GetLocalFileNode::proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext)
{
	LOG4CXX_DEBUG(gLogger, "GetLocalFileNode::proceed")
	xmlChar* lVIId = NULL;
	try {
		if (!(lVIId = xmlGetProp(pNode, (const xmlChar *) "id"))) {
			ERROR_EXCEPTION(ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "id")
		}
		AMDA::Parameters::CfgContext lContext(pContext);
		lContext.push<xmlChar*>(lVIId);
		NodeGrpCfg::proceed(pNode, lContext);
	} catch (...) {
		if (lVIId) {
			xmlFree(lVIId);
		}
		throw;
	}
	if (lVIId) {
		xmlFree(lVIId);
	}
}

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