Blame view

src/XMLParameterConfigurator/ParamNode.cc 3.93 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
/**
 * 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"
e8fa18b6   Benjamin Renard   Add the possibili...
23
#include "ManualCalibrationNode.hh"
fbe3c2bb   Benjamin Renard   First commit
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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*>();
f7b99646   Benjamin Renard   Give the possibil...
42
				if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
fbe3c2bb   Benjamin Renard   First commit
43
44
45
46
47
48
49
50
51
52
					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*>();
f7b99646   Benjamin Renard   Give the possibil...
53
				if ( pNode->children && pNode->children->content && pNode->children->content[0] != '\0') {
fbe3c2bb   Benjamin Renard   First commit
54
55
56
57
58
					p->setGapThreshold(atof((char*)pNode->children->content));
				}
			}
		};

deefda79   Benjamin Renard   Addapt resampling...
59
60
61
62
63
64
65
66
67
68
69
		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);
				}
			}
		};
fbe3c2bb   Benjamin Renard   First commit
70
71
72
73
74
75

		  ParamNode::ParamNode() : AMDA::XMLConfigurator::NodeGrpCfg()
			{
				LOG4CXX_DEBUG(gLogger, "ParamNode Constructor")
				getChildList()["time_resolution"]=NodeCfgSPtr(new NodeTimeResolution);
				getChildList()["gap_threshold"]=NodeCfgSPtr(new NodeGapThreshold);
deefda79   Benjamin Renard   Addapt resampling...
76
				getChildList()["reference_parameter"]=NodeCfgSPtr(new NodeReferenceParameter);
fbe3c2bb   Benjamin Renard   First commit
77
				getChildList()["process"]=NodeCfgSPtr(new ProcessNode());
e8fa18b6   Benjamin Renard   Add the possibili...
78
				getChildList()["clbManual"]=NodeCfgSPtr(new ManualCalibrationNode());
fbe3c2bb   Benjamin Renard   First commit
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
				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 */