Blame view

src/Info/MissionParser.cc 3.41 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
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
/*
 * MissionParser.cc
 *
 *  Created on: Oct 6, 2014
 *      Author: m.mazel
 */

#include "NodeCfg.hh"
#include "AMDA_exception.hh"
#include "MissionParser.hh"
#include "InfoLogger.hh"

using namespace AMDA::XMLConfigurator;

namespace AMDA {
namespace Info {

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Mission name node
 */
class MissionNameNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  MissionInfo* pMissionInfo =  pContext.get<MissionInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pMissionInfo->setName((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Mission description node
 */
class MissionDescriptionNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  MissionInfo* pMissionInfo =  pContext.get<MissionInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pMissionInfo->setDescription((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Mission URL node
 */
class MissionUrlNode : public NodeCfg
{
public:
  void proceed(xmlNodePtr pNode,const AMDA::Parameters::CfgContext& pContext) {
	  MissionInfo* pMissionInfo =  pContext.get<MissionInfo*>();
	  if ((pNode->children != NULL) && (pNode->children->content != NULL))
		  pMissionInfo->setUrl((const char*)pNode->children->content);
  }
};

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Mission info node
 */
class MissionInfoNode : public NodeGrpCfg {
public:

	MissionInfoNode () : NodeGrpCfg() {
		getChildList()["name"] = NodeCfgSPtr(new MissionNameNode);
		getChildList()["description"] = NodeCfgSPtr(new MissionDescriptionNode);
		getChildList()["url"] = NodeCfgSPtr(new MissionUrlNode);
	}

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

		MissionInfo* pMissionInfo =  pContext.get<MissionInfo*>();

		// read mission id
		xmlChar* value = xmlGetProp(pNode, (const xmlChar *) "id");
		if (value) {
			pMissionInfo->setId ((const char*) value);
			xmlFree(value);
		}

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

///////////////////////////////////////////////////////////////////////////////
/*
 * @brief Mission info parser
 */
MissionParser::MissionParser (const char* pXSDFile) : XMLConfigurator(pXSDFile, true)
{

	// MissionInfo root node
	getXmlConfiguratorMap()["mission"] = RootNodeCfgSPtr(new MissionInfoNode ());
}

boost::shared_ptr<MissionInfo> MissionParser::parse (const std::string& missionFile) {
	LOG4CXX_INFO(gLogger, "MissionParser::parse parsing " << missionFile);

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

	// Check schema validity and parse xml file
	try {
ec71f3db   brenard   Return a null poi...
110
111
112
		if (!XMLConfigurator::proceed(missionFile.c_str(), ctx, true)) {
			return MissionInfoSPtr();
		}
fbe3c2bb   Benjamin Renard   First commit
113
114
115
116
117
118
119
120
121
122
123
	}
	catch (...) {
		LOG4CXX_INFO(gLogger, "MissionParser::parse error while parsing file " << missionFile);
		// Return a null ptr to MissionInfo
		return MissionInfoSPtr();
	}
	return missionInfo;
}

} /* namespace Info */
} /* namespace AMDA */