Blame view

src/SpiceKernel/SpiceKernelConfigParser.cc 3.67 KB
cebd3f0e   Benjamin Renard   First implementat...
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
/*
 * SpiceKernelConfigParser.cc
 *
 *  Created on: Jul 8, 2016
 *      Author: AKKA IS
 */

#include "NodeCfg.hh"
#include "AMDA_exception.hh"
#include "SpiceKernelConfigParser.hh"
#include "SpiceKernelLogger.hh"

using namespace AMDA::XMLConfigurator;

namespace AMDA {
namespace SpiceKernel {

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief SpiceKernel data file node
 */
class DataFileNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  SpiceKernelConfig* pSpiceKernelConfig =  pContext.get<SpiceKernelConfig*>();

	  std::string path;
	  std::string bodyId;

	  // read path
	  xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "path");
	  if (value) {
		path = (const char*) value;
	  	xmlFree(value);
	  }
	  else {
		  LOG4CXX_ERROR(gLogger, "DataFileNode::proceed - Cannot load data file path");
	  }

	  // read bodyId
	  value = xmlGetProp(pNode, (const xmlChar *) "bodyId");
	  if (value) {
		  bodyId = (const char*) value;
		  	xmlFree(value);
	  }
	  else {
		  LOG4CXX_ERROR(gLogger, "DataFileNode::proceed - Cannot load data file related body id");
	  }

	  if (!path.empty() && !bodyId.empty())
		  pSpiceKernelConfig->addDataFileForBodyId(atoi(bodyId.c_str()), path.c_str());
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief SpiceKernel data files node
 */
class DataFilesNode : public NodeGrpCfg
{
public:
	DataFilesNode () : NodeGrpCfg() {
		getChildList()["datafile"] = NodeCfgSPtr(new DataFileNode());
	}


	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_INFO(gLogger, "DataFilesNode::proceed");

		SpiceKernelConfig* pSpiceKernelConfig =  pContext.get<SpiceKernelConfig*>();

		// read rootPath
		xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "rootPath");
		if (value) {
			pSpiceKernelConfig->setRootPath ((const char*) value);
			xmlFree(value);
		}

		// Proceed nodes
		NodeGrpCfg::proceed(pNode, pContext);
	}
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief SpiceKernel config node
 */
class SpiceKernelConfigNode : public NodeGrpCfg {
public:

	SpiceKernelConfigNode () : NodeGrpCfg() {
		getChildList()["datafiles"] = NodeCfgSPtr(new DataFilesNode());
	}

	void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
		LOG4CXX_INFO(gLogger, "SpiceKernelConfigNode::proceed");

d6c7a344   RENARD Benjamin   Fix some warning ...
99
		//SpiceKernelConfig* pSpiceKernelConfig =  pContext.get<SpiceKernelConfig*>();
cebd3f0e   Benjamin Renard   First implementat...
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

		// Proceed nodes
		NodeGrpCfg::proceed(pNode, pContext);
	}
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Dataset node parser
 */
SpiceKernelConfigParser::SpiceKernelConfigParser (const char* pXSDFile) : XMLConfigurator(pXSDFile,false)
{
	// SpiceKernel config root node
	getXmlConfiguratorMap()["spicekernelconfig"] = RootNodeCfgSPtr(new SpiceKernelConfigNode());
}

boost::shared_ptr<SpiceKernelConfig> SpiceKernelConfigParser::parse (const std::string& configFile) {
	LOG4CXX_INFO(gLogger, "SpiceKernelConfigParser::parse parsing " << configFile);

	AMDA::Parameters::CfgContext ctx;
	boost::shared_ptr<SpiceKernelConfig> spiceKernelConfig (new SpiceKernelConfig ());
	ctx.push<SpiceKernelConfig *>(spiceKernelConfig.get());

	// Check schema validity and parse xml file
	try {
48d596b2   brenard   Do not log an err...
125
		XMLConfigurator::proceed(configFile.c_str(), ctx, false);
cebd3f0e   Benjamin Renard   First implementat...
126
127
128
129
130
131
132
133
134
135
136
	}
	catch (...) {
		LOG4CXX_INFO(gLogger, "SpiceKernelConfigParser::parse error while parsing file " << configFile);
		// Return a null ptr to DataSetInfo
		return boost::shared_ptr<SpiceKernelConfig>();
	}
	return spiceKernelConfig;
}

} /* namespace SpiceKernel */
} /* namespace AMDA */