3.2.2 : File PEmptyControlBackend.cpp



The file PEmptyControlBackend.cpp can be found in src :

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/

#include "string_utils.h"
#include "PEmptyControlBackend.h"

///Create a PEmptyControlParam
/**	@param logDirectory : directory where to put logs
 * 	@param logLevel : level of log to be used in the backend
 * 	@return corresponding PEmptyControlParam
*/
PEmptyControlParam phoenix_emptyControlParam(const std::string & logDirectory, PLog::Level logLevel){
	PEmptyControlParam param;
	param.logDirectory = logDirectory;
	param.logLevel = logLevel;
	return param;
}

///Create a PEmptyManagerParam
/**	@param name : name of the manager
 * 	@param logDirectory : directory where to put logs
 * 	@param logLevel : level of log to be used in the backend
 * 	@return corresponding PEmptyManagerParam
*/
PEmptyManagerParam phoenix_emptyManagerParam(const std::string & name, const std::string & logDirectory, PLog::Level logLevel){
	PEmptyManagerParam param;
	param.name = name;
	param.logDirectory = logDirectory;
	param.logLevel = logLevel;
	return param;
}

///Create a default Param
/**	@param logDirectory : directory where to put logs
 * 	@param logLevel : level of log to be used in the backend
 * 	@return corresponding PEmptyControlParam
*/
PEmptyControlBackend::Param PEmptyControlBackend::defaultParam(const std::string & logDirectory, PLog::Level logLevel){
	return phoenix_emptyControlParam(logDirectory, logLevel);
}

///Create a default MgrParam
/**	@param name : name of the manager
 * 	@param logDirectory : directory where to put logs
 * 	@param logLevel : level of log to be used in the backend
 * 	@return corresponding PEmptyControlParam
*/
PEmptyControlBackend::MgrParam PEmptyControlBackend::defaultMgrParam(const std::string & name, const std::string & logDirectory, PLog::Level logLevel){
	return phoenix_emptyManagerParam(name, logDirectory, logLevel);
}

///Contructor of the empty Backend
PEmptyControlBackend::PEmptyControlBackend(){
	
}

///Initialise the manager
/**	@param[out] manager : manager to be initialised
 * 	@param param : parameters to be used to initialise the manager data
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::initialiseDataManager(PEmptyControlBackend::Manager & manager, const PEmptyControlBackend::MgrParam & param){
	manager.name = param.name;
	PLog & logger = manager.logger;
	std::string logDirectory(param.logDirectory);
	createDirectoriesIfNotExist(logDirectory);
	logger.setFileName(logDirectory + "/manager_"+manager.name+".log");
	logger.setLogLevel(param.logLevel);
	if(!logger.open()){return false;};
	logger.getLogInfo() << "Create Empty Manager '"<<manager.name<<"'" << std::endl;
	return true;
}

///Create a client connector
/**	@param manager : manager to be used to initialise connector
 * 	@param[out] connector : connector to be created
 * 	@param address : address of the server, the client has to connect to
 * 	@param param : extra customisable parameters for the creation of the connector (depends on the backend)
 * 	@return true if the connector has been created, false otherwise
*/
bool PEmptyControlBackend::createClientConnector(PEmptyControlBackend::Manager & manager, PEmptyControlBackend::Connector & connector,
				const std::string & address, const PEmptyControlBackend::Param & param)
{
	return PEmptyControlBackend::createConnector(manager, connector, "client", address, param);
}

///Create a server connector
/**	@param manager : manager to be used to initialise connector
 * 	@param[out] connector : connector to be created
 * 	@param address : address of the server, the client has to connect to
 * 	@param param : extra customisable parameters for the creation of the connector (depends on the backend)
 * 	@return true if the connector has been created, false otherwise
*/
bool PEmptyControlBackend::createServerConnector(PEmptyControlBackend::Manager & manager, PEmptyControlBackend::Connector & connector,
				const std::string & address, const PEmptyControlBackend::Param & param)
{
	return PEmptyControlBackend::createConnector(manager, connector, "server", address, param);
}

///Regiter a variable which can be used by the given connector
/**	@param connector : connector to be used
 * 	@param composeVar : variable to be used (can have a complex type)
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::registerVar(PEmptyControlBackend::Connector & connector, const PComposeVar & composeVar){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Register Var '"<<ts_pcomposeVarToStr(composeVar)<<"' to host '"<<connector.hostname<<"'" << std::endl;
	return true;
}

///Regiter a method which can be called by the given connector
/**	@param connector : connector to be used
 * 	@param prototype : prototype of the method to be called
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::registerCall(PEmptyControlBackend::Connector & connector, const PFunctionPrototype & prototype){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Register Call '"<<ts_protoTypeToStr(prototype)<<"' to host '"<<connector.hostname<<"'" << std::endl;
	return true;
}

///Push a value in the server/client describes by the connector
/**	@param connector : connector to be used
 * 	@param varName : name of the variable to be pushed
 * 	@param value : value of the variable to be pushed
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::push(PEmptyControlBackend::Connector & connector, const std::string & varName, const PEmptyControlBackend::Message & value){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Some empty Push to host '"<<connector.hostname<<"' and variable '"<<varName<<"'" << std::endl;
	return true;
}

///Pull value from a server/client
/**	@param[out] connector : connector to be used
 * 	@param varName : variable name to pull the value from
 * 	@param[out] value : pulled binary data
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::pull(PEmptyControlBackend::Connector & connector, const std::string & varName, PEmptyControlBackend::Message & value){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Some empty pull from host '"<<connector.hostname<<"' and variable '"<<varName<<"'" << std::endl;
	return true;
}

///Call method on a server/client
/**	@param[out] connector : connector to be used
 * 	@param methodCall : method to be called
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::call(PEmptyControlBackend::Connector & connector, PFunctionCall & methodCall){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Some call of method '"<<methodCall.getPrototype().getName()<<"' to host '"<<connector.hostname<<"'" << std::endl;
	return true;
}

///Resize a message
/**	@param[out] msg : message to be resized
 * 	@param sizeMsg : new size of the message
*/
void PEmptyControlBackend::msgResize(PEmptyControlBackend::Message& msg, size_t sizeMsg){
	msg.resize(sizeMsg);
}

///Get the size of Message in bytes
/**	@param msg : given message
 * 	@return size of the given message in bytes
*/
size_t PEmptyControlBackend::msgSize(const PEmptyControlBackend::Message& msg){
	return msg.size();
}

///Get the data pointer of the given message
/**	@param msg : given message
 * 	@return data pointer of the given message
*/
const char* PEmptyControlBackend::msgData(const PEmptyControlBackend::Message& msg){
	return (const char*)msg.data();
}

///Get the data pointer of the given message
/**	@param msg : given message
 * 	@return data pointer of the given message
*/
char* PEmptyControlBackend::msgData(PEmptyControlBackend::Message& msg){
	return (char*)msg.data();
}

///Close the Connector
/**	@param connector : connector to be closed
*/
void PEmptyControlBackend::close(PEmptyControlBackend::Connector & connector){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Close Empty connection with host '"<<connector.hostname<<"'" << std::endl;
}

///Close the Manager
/**	@param manager : manager to be closed
*/
void PEmptyControlBackend::closeMgr(PEmptyControlBackend::Manager & manager){
	PLog & logger = manager.logger;
	logger.getLogInfo() << "Close Empty connection with Manager '"<<manager.name<<"'" << std::endl;
}

///Say if the given Connector is connected to its host or not
/**	@param connector : connector to be used
 * 	@return true if the given Connector is connected to its host, false otherwise
*/
bool PEmptyControlBackend::isConnected(PEmptyControlBackend::Connector & connector){
	PLog & logger = *connector.logger;
	logger.getLogInfo() << "Check Empty connection with host '"<<connector.hostname<<"' but as we are optimistic, let's say the connection is OK" << std::endl;
	return true;
}

///Register a local variable
/**	@param manager : Manager to be used
 * 	@param composeVar : description of the varaible to be registered
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::registerLocalVar(PEmptyControlBackend::Manager & manager, const PComposeVar & composeVar){
	PLog & logger = manager.logger;
	logger.getLogInfo() << "Register local variable '"<<ts_pcomposeVarToStr(composeVar)<<"' to EmptyManager '"<<manager.name<<"'" << std::endl;
	return true;
}

///Get value of local variable
/**	@param manager : Manager to be used
 * 	@param[out] localVar : local variable to be updated
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::getLocalVar(PEmptyControlBackend::Manager & manager, PComposeVar & localVar){
	PLog & logger = manager.logger;
	logger.getLogInfo() << "EmptyManager '"<<manager.name<<"' : get local variable '"<<ts_pcomposeVarToStr(localVar)<<"'" << std::endl;
	return true;
}

///Set value of local variable
/**	@param manager : Manager to be used
 * 	@param localVar : local variable to be written
 * 	@return true on success, false otherwise
*/
bool PEmptyControlBackend::setLocalVar(PEmptyControlBackend::Manager & manager, const PComposeVar & localVar){
	PLog & logger = manager.logger;
	logger.getLogInfo() << "EmptyManager '"<<manager.name<<"' : set value of local variable '"<<ts_pcomposeVarToStr(localVar)<<"'" << std::endl;
	return true;
}

///Create a generic connector
/**	@param manager : manager to be used to initialise connector
 * 	@param[out] connector : connector to be created
 * 	@param connectorType : type of the conenctor (client or server)
 * 	@param address : address of the server, the client has to connect to
 * 	@param param : extra customisable parameters for the creation of the connector (depends on the backend)
 * 	@return true if the connector has been created, false otherwise
*/
bool PEmptyControlBackend::createConnector(PEmptyControlBackend::Manager & manager, PEmptyControlBackend::Connector & connector, const std::string & connectorType,
					const std::string & address, const Param & param)
{
	connector.logger = &manager.logger;
	connector.hostname = address;
	PLog & logger = *connector.logger;
	std::string logDirectory(param.logDirectory);
	logger.getLogInfo() << "Create Empty "<<connectorType<<" Connector" << std::endl;
	return true;
}