Blame view

src/InternLib/ParameterCreatorFromExpression.cc 3.62 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
/*
 * ParameterCreatorFromExpression.cc
 *
 *  Created on: Dec 14, 2012
 *      Author: f.casimir
 */

#include <boost/functional/hash.hpp>
#include <boost/algorithm/string.hpp>

#include "DicError.hh"

#include "Process.hh"

#include "ParameterManager.hh"
#include "ServicesServer.hh"

#include "InternLib_Config.hh"
#include "ParameterCreatorFromExpression.hh"

using namespace std;
using namespace boost;
using namespace log4cxx;

namespace AMDA {
	namespace Parameters {

		ParameterCreatorFromExpression::ParameterCreatorFromExpression(ParameterManager& pParameterManager) :
				_parameterManager(pParameterManager) {


		}

		ParameterCreatorFromExpression::~ParameterCreatorFromExpression() {
		}

854a7fcf   Benjamin Renard   First implementat...
37
		ParameterSPtr ParameterCreatorFromExpression::getOneParameterFromExpression(Parameter& pParameter, const std::string& pExpression, bool isUserProcess) {
fbe3c2bb   Benjamin Renard   First commit
38
39
40
41
42
43
			ParameterSPtr lParameter;
			_parser.process(pExpression);

			///Case of one parameter return this parameter
			if (_parser.getListParameterName().size() == 1
					&& _parser.getListProcessName().size() == 0
1ddc0f12   Benjamin Renard   Fix expression pa...
44
45
					&& _parser.getListFctName().size() == 0 
					&& _parser.isParamOnly()) {
fbe3c2bb   Benjamin Renard   First commit
46
47
48
49
50
51
52
53
				lParameter = _parameterManager.getParameter(*_parser.getListParameterName().begin());
				// Here we have a broken link in parameter chaining so create link.
				// Child is already creating before linking it to its parent parameter.
				pParameter.addParameter(lParameter);
			} else {
				///Case of one process return a Parameter with this Process
				if (_parser.getListParameterName().size() == 0
							&& _parser.getListProcessName().size() == 1
1ddc0f12   Benjamin Renard   Fix expression pa...
54
55
							&& _parser.getListFctName().size() == 0
							&& _parser.isProcessOnly()) {
fbe3c2bb   Benjamin Renard   First commit
56
57
58
59
60
61
62
63
					const Parser::ListProcessName& processNameList = _parser.getListProcessName();
					auto lProcessIt = processNameList.begin();

					if ( _parameterManager.addParameter(&pParameter,lProcessIt->first,lParameter)) {
							Process* lProcess = ServicesServer::getInstance()->getProcess(lProcessIt->second.name,*lParameter.get());
							if ( lProcess) {
								lProcess->setExpression(lProcessIt->second.expression);
								lProcess->setAttributList(lProcessIt->second.attribut);
854a7fcf   Benjamin Renard   First implementat...
64
                                                                lProcess->setIsUserProcess(isUserProcess);
fbe3c2bb   Benjamin Renard   First commit
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
								DataWriterSPtr dataWriter(lProcess);
								lParameter->setDataWriter(dataWriter);
							} else {
								stringstream lError;  lError << "Process: '" << lProcessIt->second.name << "' not found";
								LOG4CXX_ERROR(AMDA::InternLib::gLogger, lError.str());
								BOOST_THROW_EXCEPTION(AMDA::InternLib::exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(lError.str()));
							}
						}
				} else {
				    boost::hash<std::string> string_hash;
				     std::stringstream key;
				     key << string_hash(pExpression);
					///Else return a Parameter with a Standard Process
					if ( _parameterManager.addParameter(&pParameter,key.str(),lParameter)) {
						Process *lProcess = ServicesServer::getInstance()->getProcess("standard", *lParameter.get());
						if ( lProcess) {
							lProcess->setExpression(pExpression);
854a7fcf   Benjamin Renard   First implementat...
82
                                                        lProcess->setIsUserProcess(isUserProcess);
fbe3c2bb   Benjamin Renard   First commit
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
							DataWriterSPtr dataWriter(lProcess);
							lParameter->setDataWriter(dataWriter);
						} else {
							stringstream lError;  lError << "Process: 'standard' not found";
							LOG4CXX_ERROR(AMDA::InternLib::gLogger, lError.str());
							BOOST_THROW_EXCEPTION(AMDA::InternLib::exception() << AMDA::errno_code(AMDA_PROCESS_ERR) << AMDA::ex_msg(lError.str()));
						}
					}
				}
			}

			return lParameter;
		}

	} /* namespace Parameters */
} /* namespace AMDA */