VirtualInstrumentBaseParser.cc
4.96 KB
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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/**
* VirtualInstrumentBaseParser.cc
*
* Created on: 21 nov. 2014
* Author: AKKA
*/
#include "VirtualInstrumentBaseParser.hh"
#include "LocalFileInterfaceConfig.hh"
// XML include
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/xmlstring.h>
#include <libxml/xmlschemas.h>
#include "NodeCfg.hh"
#include "Constant.hh"
using namespace AMDA::XMLConfigurator;
namespace AMDA {
namespace LocalFileInterface {
class LocalFileNode: public AMDA::XMLConfigurator::NodeCfg {
public:
/**
* @brief read local file node
*/
void proceed(xmlNodePtr pNode,
const AMDA::Parameters::CfgContext& context) {
LOG4CXX_DEBUG(gLogger, "LocalFileNode::proceed")
VirtualInstrument* lVI = context.get<VirtualInstrument*>();
//name
xmlChar* lName = xmlGetProp(pNode, (const xmlChar *) "name");
if (lName == NULL)
{
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "name")
}
//start
xmlChar* lStart = xmlGetProp(pNode, (const xmlChar *) "start");
if (lStart == NULL)
{
xmlFree(lName);
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "start")
}
//stop
xmlChar* lStop = xmlGetProp(pNode, (const xmlChar *) "stop");
if (lStop == NULL)
{
xmlFree(lName);
xmlFree(lStart);
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "stop")
}
lVI->addFileDefinition((const char *)lName,atof((const char*)lStart),atof((const char*)lStop));
xmlFree(lName);
xmlFree(lStart);
xmlFree(lStop);
}
};
class LocalVINode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
LocalVINode() : AMDA::XMLConfigurator::NodeGrpCfg() {
getChildList()["file"]=NodeCfgSPtr(new LocalFileNode());
}
/**
* @brief read LocalBaseNode
*/
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "LocalVINode::proceed")
VirtualInstrument* lVI = pContext.get<VirtualInstrument*>();
//id
xmlChar* lVIId = NULL;
if (!(lVIId = xmlGetProp(pNode, (const xmlChar *) "id")))
{
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "id")
}
std::string loadedVIId = (const char *)lVIId;
xmlFree(lVIId);
if (lVI->getVIId() != loadedVIId)
return;
//files format
xmlChar* lformat = NULL;
if (!(lformat = xmlGetProp(pNode, (const xmlChar *) "format")))
{
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "format")
}
std::string loadedVIFormat = (const char *)lformat;
xmlFree(lformat);
if (loadedVIFormat == "ASCII")
lVI->setFilesFormat(VIFileFormat::FORMAT_ASCII);
else if (loadedVIFormat == "CDF")
lVI->setFilesFormat(VIFileFormat::FORMAT_CDF);
else if (loadedVIFormat == "VOT")
lVI->setFilesFormat(VIFileFormat::FORMAT_VOT);
else if (loadedVIFormat == "NC")
lVI->setFilesFormat(VIFileFormat::FORMAT_NETCDF);
else
{
ERROR_EXCEPTION("Unknown format " << loadedVIFormat)
}
//start
xmlChar* lStart = xmlGetProp(pNode, (const xmlChar *) "start");
if (lStart == NULL)
{
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "start")
}
lVI->setGlobalStartTime(atof((const char*)lStart));
xmlFree(lStart);
//stop
xmlChar* lStop = xmlGetProp(pNode, (const xmlChar *) "stop");
if (lStop == NULL)
{
ERROR_EXCEPTION(
ERROR_MANDATORY_ATTRIBUTE_MISSING << pNode->name << "@" << "stop")
}
lVI->setGlobalStopTime(atof((const char*)lStop));
xmlFree(lStop);
AMDA::Parameters::CfgContext lContext;
lContext.push<VirtualInstrument *>(lVI);
NodeGrpCfg::proceed(pNode, lContext);
}
};
class LocalBaseNode: public AMDA::XMLConfigurator::NodeGrpCfg {
public:
LocalBaseNode() : AMDA::XMLConfigurator::NodeGrpCfg() {
getChildList()["vi"]=NodeCfgSPtr(new LocalVINode());
}
/**
* @brief read LocalBaseNode
*/
void proceed(xmlNodePtr pNode, const AMDA::Parameters::CfgContext& pContext) {
LOG4CXX_DEBUG(gLogger, "LocalBaseNode::proceed")
VirtualInstrument* lVI = pContext.get<VirtualInstrument*>();
AMDA::Parameters::CfgContext lContext;
lContext.push<VirtualInstrument *>(lVI);
NodeGrpCfg::proceed(pNode, lContext);
}
};
VirtualInstrumentBaseParser::VirtualInstrumentBaseParser(const char* pXSDFile, const char* pBaseFileName) :
XMLConfigurator(pXSDFile, false), _baseFileName(pBaseFileName)
{
LOG4CXX_DEBUG(gLogger, "VirtualInstrumentBaseParser Constructor")
getXmlConfiguratorMap()["base"] = RootNodeCfgSPtr(new LocalBaseNode);
}
VirtualInstrumentBaseParser::~VirtualInstrumentBaseParser()
{
}
void VirtualInstrumentBaseParser::parse(VirtualInstrumentSPtr lResult)
{
AMDA::Parameters::CfgContext ctx;
ctx.push<VirtualInstrument *>(lResult.get());
// Check schema validity and parse xml file
try {
XMLConfigurator::proceed(_baseFileName.c_str(), ctx, false);
}
catch (...) {
LOG4CXX_INFO(gLogger, "VirtualInstrumentBaseParser::parse error while parsing file " << _baseFileName);
return;
}
}
} /* namespace LocalFileInterface*/
} /* namespace AMDA */