VirtualInstrumentManager.cc
2.33 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
/*
* VirtualInstrumentManager.cc
*
* Created on: Nov 22, 2014
* Author: AKKA
*/
#include "VirtualInstrumentManager.hh"
#include "LocalFileInterfaceConfig.hh"
#include "VirtualInstrument.hh"
#include "Properties.hh"
namespace AMDA {
namespace LocalFileInterface {
VirtualInstrumentManager::VirtualInstrumentManager() : _localBasePath("") {
}
VirtualInstrumentManager::~VirtualInstrumentManager() {
}
VirtualInstrumentSPtr VirtualInstrumentManager::getVirtualInstrument(const std::string& pVirtualInstrumentId) {
VirtualInstrumentSPtr lResult;
auto lIt = _virtualInstrumentMap.find(pVirtualInstrumentId);
if (lIt == _virtualInstrumentMap.end())
{
lResult = VirtualInstrumentSPtr(new VirtualInstrument(*this,pVirtualInstrumentId));
//init new virtual instrument
if (!initNewVirtualInstrument(lResult))
{
lResult.reset();
//ToDo Exception
return lResult;
}
_virtualInstrumentMap[pVirtualInstrumentId] = lResult;
} else {
lResult = lIt->second.lock();
if ( ! lResult) {
_virtualInstrumentMap.erase(lIt);
lResult = VirtualInstrumentSPtr(new VirtualInstrument(*this,pVirtualInstrumentId));
//init new virtual instrument
if (!initNewVirtualInstrument(lResult))
{
lResult.reset();
//ToDo Exception
return lResult;
}
_virtualInstrumentMap[pVirtualInstrumentId]=lResult;
}
}
return lResult;
}
bool VirtualInstrumentManager::initNewVirtualInstrument(VirtualInstrumentSPtr lResult)
{
//load virtual instrument info in base xml file
if (!loadVirtualInstrumentInfo(lResult))
return false;
return true;
}
bool VirtualInstrumentManager::loadVirtualInstrumentInfo(VirtualInstrumentSPtr lResult)
{
if (_virtualInstrumentParserSPtr == nullptr)
{
AMDA::helpers::Properties lProperties("app.properties");
_localBasePath = lProperties["app.localbase.path"];
std::string baseFileName = _localBasePath + "/base.xml";
std::string xsdFileName = lProperties["app.localbase.xsd"];
_virtualInstrumentParserSPtr.reset(new VirtualInstrumentBaseParser(xsdFileName.c_str(),baseFileName.c_str()));
}
try {
_virtualInstrumentParserSPtr->parse(lResult);
}
catch (...) {
LOG4CXX_INFO(gLogger, "VirtualInstrumentManager::loadVirtualInstrumentInfo Cannot get VirtualInstrument info for " << lResult->getVIId());
return false;
}
return true;
}
} /* namespace DDServerInterface */
} /* namespace AMDA */