GCC Code Coverage Report


Directory: ./
File: src/PEmptyControlBackend.cpp
Date: 2024-12-09 11:00:39
Exec Total Coverage
Lines: 52 91 57.1%
Branches: 27 74 36.5%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #include "string_utils.h"
8 #include "PEmptyControlBackend.h"
9
10 ///Create a PEmptyControlParam
11 /** @param logDirectory : directory where to put logs
12 * @param logLevel : level of log to be used in the backend
13 * @return corresponding PEmptyControlParam
14 */
15 2 PEmptyControlParam phoenix_emptyControlParam(const std::string & logDirectory, PLog::Level logLevel){
16 2 PEmptyControlParam param;
17
1/1
✓ Branch 1 taken 2 times.
2 param.logDirectory = logDirectory;
18 2 param.logLevel = logLevel;
19 2 return param;
20 }
21
22 ///Create a PEmptyManagerParam
23 /** @param name : name of the manager
24 * @param logDirectory : directory where to put logs
25 * @param logLevel : level of log to be used in the backend
26 * @return corresponding PEmptyManagerParam
27 */
28 1 PEmptyManagerParam phoenix_emptyManagerParam(const std::string & name, const std::string & logDirectory, PLog::Level logLevel){
29 1 PEmptyManagerParam param;
30
1/1
✓ Branch 1 taken 1 times.
1 param.name = name;
31
1/1
✓ Branch 1 taken 1 times.
1 param.logDirectory = logDirectory;
32 1 param.logLevel = logLevel;
33 1 return param;
34 }
35
36 ///Create a default Param
37 /** @param logDirectory : directory where to put logs
38 * @param logLevel : level of log to be used in the backend
39 * @return corresponding PEmptyControlParam
40 */
41 PEmptyControlBackend::Param PEmptyControlBackend::defaultParam(const std::string & logDirectory, PLog::Level logLevel){
42 return phoenix_emptyControlParam(logDirectory, logLevel);
43 }
44
45 ///Create a default MgrParam
46 /** @param name : name of the manager
47 * @param logDirectory : directory where to put logs
48 * @param logLevel : level of log to be used in the backend
49 * @return corresponding PEmptyControlParam
50 */
51 1 PEmptyControlBackend::MgrParam PEmptyControlBackend::defaultMgrParam(const std::string & name, const std::string & logDirectory, PLog::Level logLevel){
52 1 return phoenix_emptyManagerParam(name, logDirectory, logLevel);
53 }
54
55 ///Contructor of the empty Backend
56 PEmptyControlBackend::PEmptyControlBackend(){
57
58 }
59
60 ///Initialise the manager
61 /** @param[out] manager : manager to be initialised
62 * @param param : parameters to be used to initialise the manager data
63 * @return true on success, false otherwise
64 */
65 1 bool PEmptyControlBackend::initialiseDataManager(PEmptyControlBackend::Manager & manager, const PEmptyControlBackend::MgrParam & param){
66
1/1
✓ Branch 1 taken 1 times.
1 manager.name = param.name;
67 1 PLog & logger = manager.logger;
68
1/1
✓ Branch 1 taken 1 times.
1 std::string logDirectory(param.logDirectory);
69
1/1
✓ Branch 1 taken 1 times.
1 createDirectoriesIfNotExist(logDirectory);
70
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
1 logger.setFileName(logDirectory + "/manager_"+manager.name+".log");
71
1/1
✓ Branch 1 taken 1 times.
1 logger.setLogLevel(param.logLevel);
72
2/3
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if(!logger.open()){return false;};
73
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
1 logger.getLogInfo() << "Create Empty Manager '"<<manager.name<<"'" << std::endl;
74 1 return true;
75 1 }
76
77 ///Create a client connector
78 /** @param manager : manager to be used to initialise connector
79 * @param[out] connector : connector to be created
80 * @param address : address of the server, the client has to connect to
81 * @param param : extra customisable parameters for the creation of the connector (depends on the backend)
82 * @return true if the connector has been created, false otherwise
83 */
84 2 bool PEmptyControlBackend::createClientConnector(PEmptyControlBackend::Manager & manager, PEmptyControlBackend::Connector & connector,
85 const std::string & address, const PEmptyControlBackend::Param & param)
86 {
87
2/2
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
2 return PEmptyControlBackend::createConnector(manager, connector, "client", address, param);
88 }
89
90 ///Create a server connector
91 /** @param manager : manager to be used to initialise connector
92 * @param[out] connector : connector to be created
93 * @param address : address of the server, the client has to connect to
94 * @param param : extra customisable parameters for the creation of the connector (depends on the backend)
95 * @return true if the connector has been created, false otherwise
96 */
97 bool PEmptyControlBackend::createServerConnector(PEmptyControlBackend::Manager & manager, PEmptyControlBackend::Connector & connector,
98 const std::string & address, const PEmptyControlBackend::Param & param)
99 {
100 return PEmptyControlBackend::createConnector(manager, connector, "server", address, param);
101 }
102
103 ///Regiter a variable which can be used by the given connector
104 /** @param connector : connector to be used
105 * @param composeVar : variable to be used (can have a complex type)
106 * @return true on success, false otherwise
107 */
108 bool PEmptyControlBackend::registerVar(PEmptyControlBackend::Connector & connector, const PComposeVar & composeVar){
109 PLog & logger = *connector.logger;
110 logger.getLogInfo() << "Register Var '"<<ts_pcomposeVarToStr(composeVar)<<"' to host '"<<connector.hostname<<"'" << std::endl;
111 return true;
112 }
113
114 ///Regiter a method which can be called by the given connector
115 /** @param connector : connector to be used
116 * @param prototype : prototype of the method to be called
117 * @return true on success, false otherwise
118 */
119 bool PEmptyControlBackend::registerCall(PEmptyControlBackend::Connector & connector, const PFunctionPrototype & prototype){
120 PLog & logger = *connector.logger;
121 logger.getLogInfo() << "Register Call '"<<ts_protoTypeToStr(prototype)<<"' to host '"<<connector.hostname<<"'" << std::endl;
122 return true;
123 }
124
125 ///Push a value in the server/client describes by the connector
126 /** @param connector : connector to be used
127 * @param varName : name of the variable to be pushed
128 * @param value : value of the variable to be pushed
129 * @return true on success, false otherwise
130 */
131 10 bool PEmptyControlBackend::push(PEmptyControlBackend::Connector & connector, const std::string & varName, const PEmptyControlBackend::Message & value){
132 10 PLog & logger = *connector.logger;
133 10 logger.getLogInfo() << "Some empty Push to host '"<<connector.hostname<<"' and variable '"<<varName<<"'" << std::endl;
134 10 return true;
135 }
136
137 ///Pull value from a server/client
138 /** @param[out] connector : connector to be used
139 * @param varName : variable name to pull the value from
140 * @param[out] value : pulled binary data
141 * @return true on success, false otherwise
142 */
143 10 bool PEmptyControlBackend::pull(PEmptyControlBackend::Connector & connector, const std::string & varName, PEmptyControlBackend::Message & value){
144 10 PLog & logger = *connector.logger;
145 10 logger.getLogInfo() << "Some empty pull from host '"<<connector.hostname<<"' and variable '"<<varName<<"'" << std::endl;
146 10 return true;
147 }
148
149 ///Call method on a server/client
150 /** @param[out] connector : connector to be used
151 * @param methodCall : method to be called
152 * @return true on success, false otherwise
153 */
154 bool PEmptyControlBackend::call(PEmptyControlBackend::Connector & connector, PFunctionCall & methodCall){
155 PLog & logger = *connector.logger;
156 logger.getLogInfo() << "Some call of method '"<<methodCall.getPrototype().getName()<<"' to host '"<<connector.hostname<<"'" << std::endl;
157 return true;
158 }
159
160 ///Resize a message
161 /** @param[out] msg : message to be resized
162 * @param sizeMsg : new size of the message
163 */
164 void PEmptyControlBackend::msgResize(PEmptyControlBackend::Message& msg, size_t sizeMsg){
165 msg.resize(sizeMsg);
166 }
167
168 ///Get the size of Message in bytes
169 /** @param msg : given message
170 * @return size of the given message in bytes
171 */
172 10 size_t PEmptyControlBackend::msgSize(const PEmptyControlBackend::Message& msg){
173 10 return msg.size();
174 }
175
176 ///Get the data pointer of the given message
177 /** @param msg : given message
178 * @return data pointer of the given message
179 */
180 const char* PEmptyControlBackend::msgData(const PEmptyControlBackend::Message& msg){
181 return (const char*)msg.data();
182 }
183
184 ///Get the data pointer of the given message
185 /** @param msg : given message
186 * @return data pointer of the given message
187 */
188 char* PEmptyControlBackend::msgData(PEmptyControlBackend::Message& msg){
189 return (char*)msg.data();
190 }
191
192 ///Close the Connector
193 /** @param connector : connector to be closed
194 */
195 2 void PEmptyControlBackend::close(PEmptyControlBackend::Connector & connector){
196 2 PLog & logger = *connector.logger;
197 2 logger.getLogInfo() << "Close Empty connection with host '"<<connector.hostname<<"'" << std::endl;
198 2 }
199
200 ///Close the Manager
201 /** @param manager : manager to be closed
202 */
203 1 void PEmptyControlBackend::closeMgr(PEmptyControlBackend::Manager & manager){
204 1 PLog & logger = manager.logger;
205 1 logger.getLogInfo() << "Close Empty connection with Manager '"<<manager.name<<"'" << std::endl;
206 1 }
207
208 ///Say if the given Connector is connected to its host or not
209 /** @param connector : connector to be used
210 * @return true if the given Connector is connected to its host, false otherwise
211 */
212 bool PEmptyControlBackend::isConnected(PEmptyControlBackend::Connector & connector){
213 PLog & logger = *connector.logger;
214 logger.getLogInfo() << "Check Empty connection with host '"<<connector.hostname<<"' but as we are optimistic, let's say the connection is OK" << std::endl;
215 return true;
216 }
217
218 ///Register a local variable
219 /** @param manager : Manager to be used
220 * @param composeVar : description of the varaible to be registered
221 * @return true on success, false otherwise
222 */
223 bool PEmptyControlBackend::registerLocalVar(PEmptyControlBackend::Manager & manager, const PComposeVar & composeVar){
224 PLog & logger = manager.logger;
225 logger.getLogInfo() << "Register local variable '"<<ts_pcomposeVarToStr(composeVar)<<"' to EmptyManager '"<<manager.name<<"'" << std::endl;
226 return true;
227 }
228
229 ///Get value of local variable
230 /** @param manager : Manager to be used
231 * @param[out] localVar : local variable to be updated
232 * @return true on success, false otherwise
233 */
234 bool PEmptyControlBackend::getLocalVar(PEmptyControlBackend::Manager & manager, PComposeVar & localVar){
235 PLog & logger = manager.logger;
236 logger.getLogInfo() << "EmptyManager '"<<manager.name<<"' : get local variable '"<<ts_pcomposeVarToStr(localVar)<<"'" << std::endl;
237 return true;
238 }
239
240 ///Set value of local variable
241 /** @param manager : Manager to be used
242 * @param localVar : local variable to be written
243 * @return true on success, false otherwise
244 */
245 bool PEmptyControlBackend::setLocalVar(PEmptyControlBackend::Manager & manager, const PComposeVar & localVar){
246 PLog & logger = manager.logger;
247 logger.getLogInfo() << "EmptyManager '"<<manager.name<<"' : set value of local variable '"<<ts_pcomposeVarToStr(localVar)<<"'" << std::endl;
248 return true;
249 }
250
251 ///Create a generic connector
252 /** @param manager : manager to be used to initialise connector
253 * @param[out] connector : connector to be created
254 * @param connectorType : type of the conenctor (client or server)
255 * @param address : address of the server, the client has to connect to
256 * @param param : extra customisable parameters for the creation of the connector (depends on the backend)
257 * @return true if the connector has been created, false otherwise
258 */
259 2 bool PEmptyControlBackend::createConnector(PEmptyControlBackend::Manager & manager, PEmptyControlBackend::Connector & connector, const std::string & connectorType,
260 const std::string & address, const Param & param)
261 {
262 2 connector.logger = &manager.logger;
263
1/1
✓ Branch 1 taken 2 times.
2 connector.hostname = address;
264 2 PLog & logger = *connector.logger;
265
1/1
✓ Branch 1 taken 2 times.
2 std::string logDirectory(param.logDirectory);
266
5/5
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✓ Branch 13 taken 2 times.
2 logger.getLogInfo() << "Create Empty "<<connectorType<<" Connector" << std::endl;
267 2 return true;
268 2 }
269
270
271