Blame view

src/XMLParameterConfigurator/ParamNode.cc 3.38 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
59
60
61
62
63
64
65
					p->setGapThreshold(atof((char*)pNode->children->content));
				}
			}
		};


		  ParamNode::ParamNode() : AMDA::XMLConfigurator::NodeGrpCfg()
			{
				LOG4CXX_DEBUG(gLogger, "ParamNode Constructor")
				getChildList()["time_resolution"]=NodeCfgSPtr(new NodeTimeResolution);
				getChildList()["gap_threshold"]=NodeCfgSPtr(new NodeGapThreshold);
				getChildList()["process"]=NodeCfgSPtr(new ProcessNode());
e8fa18b6   Benjamin Renard   Add the possibili...
66
				getChildList()["clbManual"]=NodeCfgSPtr(new ManualCalibrationNode());
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
				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 */