Blame view

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

#include "Helper.hh"
#include "Properties.hh"
#include "ParamMgr.hh"
#include "ParamParser.hh"
#include "InfoLogger.hh"

namespace AMDA {
namespace Info {

const ParamInfoSPtr ParamMgr::getParamInfoFromId (const std::string &id, bool forceCreateIfNoExist) {
	if (id.empty())
		return ParamInfoSPtr();

	// If Param id already loaded, return it
	if (_paramInfoMap.find (id) != _paramInfoMap.end()) {
		return _paramInfoMap [id];
	}

	// Otherwise, build Param path & filename using the id
	AMDA::helpers::Properties lProperties("app.properties");

	std::string xmlFileName = lProperties["app.param.path"] + "/" + id + ".xml";
	_paramInfoMap [id] = getParamInfoFromFile (id, xmlFileName);

	if (forceCreateIfNoExist && (_paramInfoMap [id] == nullptr))
	{
		_paramInfoMap [id] = ParamInfoSPtr(new ParamInfo);
		_paramInfoMap [id]->setId(id);
	}

	return _paramInfoMap [id];
}

const ParamInfoSPtr ParamMgr::cloneParamInfoFromId(const std::string &originId, const std::string &dstId)
{
2e2cd07c   Benjamin Renard   Test if param inf...
43
	if (originId.empty() || dstId.empty()) {
fbe3c2bb   Benjamin Renard   First commit
44
		return ParamInfoSPtr();
2e2cd07c   Benjamin Renard   Test if param inf...
45
	}
fbe3c2bb   Benjamin Renard   First commit
46
47

	//if param dst id exist, return it
2e2cd07c   Benjamin Renard   Test if param inf...
48
	if (_paramInfoMap.find (dstId) != _paramInfoMap.end()) {
fbe3c2bb   Benjamin Renard   First commit
49
		return _paramInfoMap [dstId];
2e2cd07c   Benjamin Renard   Test if param inf...
50
	}
fbe3c2bb   Benjamin Renard   First commit
51
52

	//if Param origin id no exist, return nullptr
2e2cd07c   Benjamin Renard   Test if param inf...
53
54
55
56
57
	if (_paramInfoMap.find (originId) == _paramInfoMap.end()) {
		return ParamInfoSPtr();
	}

	if (_paramInfoMap[originId] == nullptr) {
fbe3c2bb   Benjamin Renard   First commit
58
		return ParamInfoSPtr();
2e2cd07c   Benjamin Renard   Test if param inf...
59
	}
fbe3c2bb   Benjamin Renard   First commit
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

	//copy param info
	_paramInfoMap [dstId] = ParamInfoSPtr(new ParamInfo(*_paramInfoMap[originId].get()));

	_paramInfoMap [dstId]->setId(dstId);

	return _paramInfoMap [dstId];
}

ParamInfoSPtr ParamMgr::getParamInfoFromFile (const std::string &paramId,
		const std::string &xmlFilename) {
	AMDA::helpers::Properties lProperties("app.properties");

	// Retrieve XSD file for Param and build a parser
	ParamParser parser(lProperties["app.paramInfo.xsd"].c_str());

	// Parse XML file
	return parser.parse (paramId, xmlFilename);
}

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