GCC Code Coverage Report


Directory: ./
File: src/Representation/Representation.h
Date: 2025-03-14 12:18:05
Exec Total Coverage
Lines: 21 21 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5 ****************************************/
6
7 #ifndef __REPRESENTATION_H__
8 #define __REPRESENTATION_H__
9
10 #include "phoenix_data_stream.h"
11 #include "PString.h"
12 #include "MessageType.h"
13
14 #include "data_all.h"
15
16 #include "phoenix_type_stream.h"
17
18 ///@brief Basic Data exchanged in the swarm
19 class Data{
20 public:
21 Data();
22 Data(const Data & other);
23 virtual ~Data();
24 Data & operator = (const Data & other);
25 void setName(const PString & name);
26 void setDescription(const PString & description);
27 void setType(const PString & type);
28 void setValue(const DataStreamMsg & value);
29 const PString & getName() const;
30 PString & getName();
31 const PString & getDescription() const;
32 PString & getDescription();
33 const PString & getType() const;
34 PString & getType();
35 const DataStreamMsg & getValue() const;
36 DataStreamMsg & getValue();
37
38 ///Load the current Data with a stream
39 /** @param[out] ds : stream to be used
40 * @return true on success, false otherwise
41 */
42 template<typename Stream, DataStreamMode::DataStreamMode Mode>
43 56 bool readWriteStream(Stream & ds){
44 56 bool b(true);
45 56 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
46 56 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description);
47 56 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_type);
48 56 b &= DataStream<Stream, Mode, DataStreamMsg >::data_stream(ds, p_value);
49 56 return b;
50 }
51
52 protected:
53 void copyData(const Data & other);
54 private:
55 void initialisationData();
56 ///Name of the Data
57 PString p_name;
58 ///Description of the Data
59 PString p_description;
60 ///Type of the Data
61 PString p_type;
62 ///Value of the Data
63 DataStreamMsg p_value;
64 };
65
66 ///@brief Generic Data serialisation/deserialisation, load/save and size function
67 template<typename Stream, DataStreamMode::DataStreamMode Mode>
68 struct DataStream<Stream, Mode, Data>{
69 ///Generic function to load/save/serialise/deserialise Data
70 /** @param data : Data to be used
71 * @return true on success, false otherwise
72 */
73 56 static bool data_stream(Stream & ds, Data & data){
74 56 return data.readWriteStream<Stream, Mode>(ds);
75 }
76 };
77
78
79
80 template<>
81 std::string phoenix_getTypeName<Data>();
82
83 ///@brief Basic function which can be called from an other Daemon
84 class Function{
85 public:
86 Function();
87 Function(const Function & other);
88 virtual ~Function();
89 Function & operator = (const Function & other);
90 void setName(const PString & name);
91 void setDescription(const PString & description);
92 void setVecParam(const std::vector<Data> & vecParam);
93 void setReturnValue(const Data & returnValue);
94 const PString & getName() const;
95 PString & getName();
96 const PString & getDescription() const;
97 PString & getDescription();
98 const std::vector<Data> & getVecParam() const;
99 std::vector<Data> & getVecParam();
100 const Data & getReturnValue() const;
101 Data & getReturnValue();
102
103 ///Load the current Function with a stream
104 /** @param[out] ds : stream to be used
105 * @return true on success, false otherwise
106 */
107 template<typename Stream, DataStreamMode::DataStreamMode Mode>
108 bool readWriteStream(Stream & ds){
109 bool b(true);
110 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
111 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description);
112 b &= DataStream<Stream, Mode, std::vector<Data> >::data_stream(ds, p_vecParam);
113 b &= DataStream<Stream, Mode, Data >::data_stream(ds, p_returnValue);
114 return b;
115 }
116
117 protected:
118 void copyFunction(const Function & other);
119 private:
120 void initialisationFunction();
121 ///Name of the Function
122 PString p_name;
123 ///Description of the Function
124 PString p_description;
125 ///Vector of parameters of the Function
126 std::vector<Data> p_vecParam;
127 ///Return value of the Function
128 Data p_returnValue;
129 };
130
131 ///@brief Generic Function serialisation/deserialisation, load/save and size function
132 template<typename Stream, DataStreamMode::DataStreamMode Mode>
133 struct DataStream<Stream, Mode, Function>{
134 ///Generic function to load/save/serialise/deserialise Function
135 /** @param data : Function to be used
136 * @return true on success, false otherwise
137 */
138 static bool data_stream(Stream & ds, Function & data){
139 return data.readWriteStream<Stream, Mode>(ds);
140 }
141 };
142
143
144
145 template<>
146 std::string phoenix_getTypeName<Function>();
147
148 ///@brief Message exchanged by Daemons
149 class Message{
150 public:
151 Message();
152 Message(const Message & other);
153 virtual ~Message();
154 Message & operator = (const Message & other);
155 void setSendTime(const time_t & sendTime);
156 void setId(size_t id);
157 void setIsConfirmationNeeded(bool isConfirmationNeeded);
158 void setSender(const PString & sender);
159 void setVecRecver(const std::vector<PString> & vecRecver);
160 void setType(const MessageType::MessageType & type);
161 void setData(const Data & data);
162 const time_t & getSendTime() const;
163 time_t & getSendTime();
164 size_t getId() const;
165 size_t & getId();
166 bool getIsConfirmationNeeded() const;
167 bool & getIsConfirmationNeeded();
168 const PString & getSender() const;
169 PString & getSender();
170 const std::vector<PString> & getVecRecver() const;
171 std::vector<PString> & getVecRecver();
172 const MessageType::MessageType & getType() const;
173 MessageType::MessageType & getType();
174 const Data & getData() const;
175 Data & getData();
176
177 ///Load the current Message with a stream
178 /** @param[out] ds : stream to be used
179 * @return true on success, false otherwise
180 */
181 template<typename Stream, DataStreamMode::DataStreamMode Mode>
182 56 bool readWriteStream(Stream & ds){
183 56 bool b(true);
184 56 b &= DataStream<Stream, Mode, time_t >::data_stream(ds, p_sendTime);
185 56 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_id);
186 56 b &= DataStream<Stream, Mode, bool >::data_stream(ds, p_isConfirmationNeeded);
187 56 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_sender);
188 56 b &= DataStream<Stream, Mode, std::vector<PString> >::data_stream(ds, p_vecRecver);
189 56 b &= DataStream<Stream, Mode, MessageType::MessageType >::data_stream(ds, p_type);
190 56 b &= DataStream<Stream, Mode, Data >::data_stream(ds, p_data);
191 56 return b;
192 }
193
194 protected:
195 void copyMessage(const Message & other);
196 private:
197 void initialisationMessage();
198 ///Time when the message was sent
199 time_t p_sendTime;
200 ///Id of the message (will be usefull to trigger method when a transmission is confirmed)
201 size_t p_id;
202 ///True if the MESSAGE_CONFIRMATION is needed
203 bool p_isConfirmationNeeded;
204 ///Address of the Daemon which sends the message
205 PString p_sender;
206 ///Addresses of Daemons which recieve the message
207 std::vector<PString> p_vecRecver;
208 ///Type of the message
209 MessageType::MessageType p_type;
210 ///Data in the message
211 Data p_data;
212 };
213
214 ///@brief Generic Message serialisation/deserialisation, load/save and size function
215 template<typename Stream, DataStreamMode::DataStreamMode Mode>
216 struct DataStream<Stream, Mode, Message>{
217 ///Generic function to load/save/serialise/deserialise Message
218 /** @param data : Message to be used
219 * @return true on success, false otherwise
220 */
221 28 static bool data_stream(Stream & ds, Message & data){
222 28 return data.readWriteStream<Stream, Mode>(ds);
223 }
224 };
225
226
227
228 template<>
229 std::string phoenix_getTypeName<Message>();
230
231 ///@brief All latency data between the current Daemon and one Daemon of the Swarm
232 class DaemonLatency{
233 public:
234 DaemonLatency();
235 DaemonLatency(const DaemonLatency & other);
236 virtual ~DaemonLatency();
237 DaemonLatency & operator = (const DaemonLatency & other);
238 void setVecLatency(const std::vector<time_t> & vecLatency);
239 void setNbMaxLatency(size_t nbMaxLatency);
240 const std::vector<time_t> & getVecLatency() const;
241 std::vector<time_t> & getVecLatency();
242 size_t getNbMaxLatency() const;
243 size_t & getNbMaxLatency();
244
245 ///Load the current DaemonLatency with a stream
246 /** @param[out] ds : stream to be used
247 * @return true on success, false otherwise
248 */
249 template<typename Stream, DataStreamMode::DataStreamMode Mode>
250 bool readWriteStream(Stream & ds){
251 bool b(true);
252 b &= DataStream<Stream, Mode, std::vector<time_t> >::data_stream(ds, p_vecLatency);
253 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbMaxLatency);
254 return b;
255 }
256
257 protected:
258 void copyDaemonLatency(const DaemonLatency & other);
259 private:
260 void initialisationDaemonLatency();
261 ///Vector of measured latencies between the current Daemon
262 std::vector<time_t> p_vecLatency;
263 ///Maximum number of latencies to be retained to make plots
264 size_t p_nbMaxLatency;
265 };
266
267 ///@brief Generic DaemonLatency serialisation/deserialisation, load/save and size function
268 template<typename Stream, DataStreamMode::DataStreamMode Mode>
269 struct DataStream<Stream, Mode, DaemonLatency>{
270 ///Generic function to load/save/serialise/deserialise DaemonLatency
271 /** @param data : DaemonLatency to be used
272 * @return true on success, false otherwise
273 */
274 static bool data_stream(Stream & ds, DaemonLatency & data){
275 return data.readWriteStream<Stream, Mode>(ds);
276 }
277 };
278
279
280
281 template<>
282 std::string phoenix_getTypeName<DaemonLatency>();
283
284 ///@brief Describe a Daemon of the Swarm
285 class DaemonConfig{
286 public:
287 DaemonConfig();
288 DaemonConfig(const DaemonConfig & other);
289 virtual ~DaemonConfig();
290 DaemonConfig & operator = (const DaemonConfig & other);
291 void setHostName(const PString & hostName);
292 void setRecievingPort(size_t recievingPort);
293 void setName(const PString & name);
294 void setDescription(const PString & description);
295 void setLatency(const DaemonLatency & latency);
296 const PString & getHostName() const;
297 PString & getHostName();
298 size_t getRecievingPort() const;
299 size_t & getRecievingPort();
300 const PString & getName() const;
301 PString & getName();
302 const PString & getDescription() const;
303 PString & getDescription();
304 const DaemonLatency & getLatency() const;
305 DaemonLatency & getLatency();
306
307 ///Load the current DaemonConfig with a stream
308 /** @param[out] ds : stream to be used
309 * @return true on success, false otherwise
310 */
311 template<typename Stream, DataStreamMode::DataStreamMode Mode>
312 bool readWriteStream(Stream & ds){
313 bool b(true);
314 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_hostName);
315 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_recievingPort);
316 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
317 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description);
318 b &= DataStream<Stream, Mode, DaemonLatency >::data_stream(ds, p_latency);
319 return b;
320 }
321
322 protected:
323 void copyDaemonConfig(const DaemonConfig & other);
324 private:
325 void initialisationDaemonConfig();
326 ///Name of the host where the daemon is running
327 PString p_hostName;
328 ///Port which is used by the Daemon to recieve messages
329 size_t p_recievingPort;
330 ///Name of the Daemon
331 PString p_name;
332 ///Description of the Daemon
333 PString p_description;
334 ///Latency of this Daemon compare to the current Daemon (the one which own the Map of Daemon)
335 DaemonLatency p_latency;
336 };
337
338 ///@brief Generic DaemonConfig serialisation/deserialisation, load/save and size function
339 template<typename Stream, DataStreamMode::DataStreamMode Mode>
340 struct DataStream<Stream, Mode, DaemonConfig>{
341 ///Generic function to load/save/serialise/deserialise DaemonConfig
342 /** @param data : DaemonConfig to be used
343 * @return true on success, false otherwise
344 */
345 static bool data_stream(Stream & ds, DaemonConfig & data){
346 return data.readWriteStream<Stream, Mode>(ds);
347 }
348 };
349
350
351
352 template<>
353 std::string phoenix_getTypeName<DaemonConfig>();
354
355
356
357 #endif
358
359