GCC Code Coverage Report


Directory: ./
File: src/Representation/Representation.h
Date: 2026-01-15 15:35:36
Exec Total Coverage
Lines: 44 44 100.0%
Functions: 24 24 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 <string>
11 #include "phoenix_data_stream.h"
12 #include "phoenix_path_stream.h"
13 #include "PString.h"
14 #include "MessageType.h"
15
16 #include "phoenix_type_stream.h"
17 #include "phoenix_data_stream.h"
18 #include "phoenix_check_stream.h"
19
20 ///@brief Basic Data exchanged in the swarm
21 class Data{
22 public:
23 Data();
24 virtual ~Data();
25 Data(const Data & other);
26 Data & operator = (const Data & other);
27 void setName(const PString & name);
28 void setDescription(const PString & description);
29 void setType(const PString & type);
30 void setValue(const DataStreamMsg & value);
31 const PString & getName() const;
32 PString & getName();
33 const PString & getDescription() const;
34 PString & getDescription();
35 const PString & getType() const;
36 PString & getType();
37 const DataStreamMsg & getValue() const;
38 DataStreamMsg & getValue();
39
40 ///Load the current Data with a stream
41 /** @param[out] ds : stream to be used
42 * @return true on success, false otherwise
43 */
44 template<typename Stream, DataStreamMode::DataStreamMode Mode>
45 87 bool readWriteStream(Stream & ds){
46 87 bool b(true);
47 87 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
48 87 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description);
49 87 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_type);
50 87 b &= DataStream<Stream, Mode, DataStreamMsg >::data_stream(ds, p_value);
51 87 return b;
52 }
53
54 protected:
55 void copyData(const Data & other);
56 private:
57 void initialisationData();
58 ///Name of the Data
59 PString p_name;
60 ///Description of the Data
61 PString p_description;
62 ///Type of the Data
63 PString p_type;
64 ///Value of the Data
65 DataStreamMsg p_value;
66 };
67
68 template<>
69 std::string phoenix_getTypeName<Data>();
70
71 ///@brief Generic Data serialisation/deserialisation, load/save and size function for PhoenixDataStream
72 template<typename Stream, DataStreamMode::DataStreamMode Mode>
73 struct DataStream<Stream, Mode, Data>{
74 ///Generic function to load/save/serialise/deserialise Data
75 /** @param[out] ds : stream to be used
76 * @param data : Data to be used
77 * @return true on success, false otherwise
78 */
79 87 static bool data_stream(Stream & ds, Data & data){
80 87 return data.readWriteStream<Stream, Mode>(ds);
81 }
82 };
83
84 ///@brief Generic Data Check function
85 template<>
86 struct CheckStream<Data>{
87 static bool check_stream(const std::string & fieldDescription, const Data & data, const Data & reference, std::ostream & out);
88 };
89
90
91
92
93 ///@brief Basic function which can be called from an other Daemon
94 class Function{
95 public:
96 Function();
97 virtual ~Function();
98 Function(const Function & other);
99 Function & operator = (const Function & other);
100 void setName(const PString & name);
101 void setDescription(const PString & description);
102 void setVecParam(const std::vector<Data> & vecParam);
103 void setReturnValue(const Data & returnValue);
104 const PString & getName() const;
105 PString & getName();
106 const PString & getDescription() const;
107 PString & getDescription();
108 const std::vector<Data> & getVecParam() const;
109 std::vector<Data> & getVecParam();
110 const Data & getReturnValue() const;
111 Data & getReturnValue();
112
113 ///Load the current Function with a stream
114 /** @param[out] ds : stream to be used
115 * @return true on success, false otherwise
116 */
117 template<typename Stream, DataStreamMode::DataStreamMode Mode>
118 bool readWriteStream(Stream & ds){
119 bool b(true);
120 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
121 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description);
122 b &= DataStream<Stream, Mode, std::vector<Data> >::data_stream(ds, p_vecParam);
123 b &= DataStream<Stream, Mode, Data >::data_stream(ds, p_returnValue);
124 return b;
125 }
126
127 protected:
128 void copyFunction(const Function & other);
129 private:
130 void initialisationFunction();
131 ///Name of the Function
132 PString p_name;
133 ///Description of the Function
134 PString p_description;
135 ///Vector of parameters of the Function
136 std::vector<Data> p_vecParam;
137 ///Return value of the Function
138 Data p_returnValue;
139 };
140
141 template<>
142 std::string phoenix_getTypeName<Function>();
143
144 ///@brief Generic Function serialisation/deserialisation, load/save and size function for PhoenixDataStream
145 template<typename Stream, DataStreamMode::DataStreamMode Mode>
146 struct DataStream<Stream, Mode, Function>{
147 ///Generic function to load/save/serialise/deserialise Function
148 /** @param[out] ds : stream to be used
149 * @param data : Function to be used
150 * @return true on success, false otherwise
151 */
152 static bool data_stream(Stream & ds, Function & data){
153 return data.readWriteStream<Stream, Mode>(ds);
154 }
155 };
156
157 ///@brief Generic Function Check function
158 template<>
159 struct CheckStream<Function>{
160 static bool check_stream(const std::string & fieldDescription, const Function & data, const Function & reference, std::ostream & out);
161 };
162
163
164
165
166 ///@brief Message exchanged by Daemons
167 class Message{
168 public:
169 Message();
170 virtual ~Message();
171 Message(const Message & other);
172 Message & operator = (const Message & other);
173 void setSendTime(const time_t & sendTime);
174 void setId(size_t id);
175 void setIsConfirmationNeeded(bool isConfirmationNeeded);
176 void setSender(const PString & sender);
177 void setVecRecver(const std::vector<PString> & vecRecver);
178 void setType(const MessageType::MessageType & type);
179 void setData(const Data & data);
180 const time_t & getSendTime() const;
181 time_t & getSendTime();
182 size_t getId() const;
183 size_t & getId();
184 bool getIsConfirmationNeeded() const;
185 bool & getIsConfirmationNeeded();
186 const PString & getSender() const;
187 PString & getSender();
188 const std::vector<PString> & getVecRecver() const;
189 std::vector<PString> & getVecRecver();
190 const MessageType::MessageType & getType() const;
191 MessageType::MessageType & getType();
192 const Data & getData() const;
193 Data & getData();
194
195 ///Load the current Message with a stream
196 /** @param[out] ds : stream to be used
197 * @return true on success, false otherwise
198 */
199 template<typename Stream, DataStreamMode::DataStreamMode Mode>
200 87 bool readWriteStream(Stream & ds){
201 87 bool b(true);
202 87 b &= DataStream<Stream, Mode, time_t >::data_stream(ds, p_sendTime);
203 87 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_id);
204 87 b &= DataStream<Stream, Mode, bool >::data_stream(ds, p_isConfirmationNeeded);
205 87 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_sender);
206 87 b &= DataStream<Stream, Mode, std::vector<PString> >::data_stream(ds, p_vecRecver);
207 87 b &= DataStream<Stream, Mode, MessageType::MessageType >::data_stream(ds, p_type);
208 87 b &= DataStream<Stream, Mode, Data >::data_stream(ds, p_data);
209 87 return b;
210 }
211
212 protected:
213 void copyMessage(const Message & other);
214 private:
215 void initialisationMessage();
216 ///Time when the message was sent
217 time_t p_sendTime;
218 ///Id of the message (will be usefull to trigger method when a transmission is confirmed)
219 size_t p_id;
220 ///True if the MESSAGE_CONFIRMATION is needed
221 bool p_isConfirmationNeeded;
222 ///Address of the Daemon which sends the message
223 PString p_sender;
224 ///Addresses of Daemons which receive the message
225 std::vector<PString> p_vecRecver;
226 ///Type of the message
227 MessageType::MessageType p_type;
228 ///Data in the message
229 Data p_data;
230 };
231
232 template<>
233 std::string phoenix_getTypeName<Message>();
234
235 ///@brief Generic Message serialisation/deserialisation, load/save and size function for PhoenixDataStream
236 template<typename Stream, DataStreamMode::DataStreamMode Mode>
237 struct DataStream<Stream, Mode, Message>{
238 ///Generic function to load/save/serialise/deserialise Message
239 /** @param[out] ds : stream to be used
240 * @param data : Message to be used
241 * @return true on success, false otherwise
242 */
243 87 static bool data_stream(Stream & ds, Message & data){
244 87 return data.readWriteStream<Stream, Mode>(ds);
245 }
246 };
247
248 ///@brief Generic Message Check function
249 template<>
250 struct CheckStream<Message>{
251 static bool check_stream(const std::string & fieldDescription, const Message & data, const Message & reference, std::ostream & out);
252 };
253
254
255
256
257 ///@brief General statistics in the swarm
258 class VecStat{
259 public:
260 VecStat();
261 virtual ~VecStat();
262 VecStat(const VecStat & other);
263 VecStat & operator = (const VecStat & other);
264 void setNbEvent(const std::vector<size_t> & nbEvent);
265 void setStartTimestamp(const std::vector<time_t> & startTimestamp);
266 void setEndTimestamp(const std::vector<time_t> & endTimestamp);
267 void setMin(const std::vector<float> & min);
268 void setMax(const std::vector<float> & max);
269 void setAverage(const std::vector<float> & average);
270 void setRate(const std::vector<float> & rate);
271 void setVecRateQuantile(const std::vector<std::vector<float> > & vecRateQuantile);
272 void setRateEventBelowLowerBound(const std::vector<float> & rateEventBelowLowerBound);
273 void setRateEventAboveUpperBound(const std::vector<float> & rateEventAboveUpperBound);
274 const std::vector<size_t> & getNbEvent() const;
275 std::vector<size_t> & getNbEvent();
276 const std::vector<time_t> & getStartTimestamp() const;
277 std::vector<time_t> & getStartTimestamp();
278 const std::vector<time_t> & getEndTimestamp() const;
279 std::vector<time_t> & getEndTimestamp();
280 const std::vector<float> & getMin() const;
281 std::vector<float> & getMin();
282 const std::vector<float> & getMax() const;
283 std::vector<float> & getMax();
284 const std::vector<float> & getAverage() const;
285 std::vector<float> & getAverage();
286 const std::vector<float> & getRate() const;
287 std::vector<float> & getRate();
288 const std::vector<std::vector<float> > & getVecRateQuantile() const;
289 std::vector<std::vector<float> > & getVecRateQuantile();
290 const std::vector<float> & getRateEventBelowLowerBound() const;
291 std::vector<float> & getRateEventBelowLowerBound();
292 const std::vector<float> & getRateEventAboveUpperBound() const;
293 std::vector<float> & getRateEventAboveUpperBound();
294
295 ///Load the current VecStat with a stream
296 /** @param[out] ds : stream to be used
297 * @return true on success, false otherwise
298 */
299 template<typename Stream, DataStreamMode::DataStreamMode Mode>
300 6 bool readWriteStream(Stream & ds){
301 6 bool b(true);
302 6 b &= DataStream<Stream, Mode, std::vector<size_t> >::data_stream(ds, p_nbEvent);
303 6 b &= DataStream<Stream, Mode, std::vector<time_t> >::data_stream(ds, p_startTimestamp);
304 6 b &= DataStream<Stream, Mode, std::vector<time_t> >::data_stream(ds, p_endTimestamp);
305 6 b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_min);
306 6 b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_max);
307 6 b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_average);
308 6 b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_rate);
309 6 b &= DataStream<Stream, Mode, std::vector<std::vector<float> > >::data_stream(ds, p_vecRateQuantile);
310 6 b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_rateEventBelowLowerBound);
311 6 b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_rateEventAboveUpperBound);
312 6 return b;
313 }
314
315 protected:
316 void copyVecStat(const VecStat & other);
317 private:
318 void initialisationVecStat();
319 ///Number of events used to make this statistic
320 std::vector<size_t> p_nbEvent;
321 ///Timestamp where this stat started to be accumulated by the clock of the current daemon (TODO: need unit)
322 std::vector<time_t> p_startTimestamp;
323 ///Timestamp where this stat was finished to be accumulated by the clock of the current daemon (TODO: need unit)
324 std::vector<time_t> p_endTimestamp;
325 ///Minimum value of the stat
326 std::vector<float> p_min;
327 ///Maximum value of the stat
328 std::vector<float> p_max;
329 ///Mean of the stat
330 std::vector<float> p_average;
331 ///Number of events per second
332 std::vector<float> p_rate;
333 ///Vector of binned event rate per quantile (quartile decile, etc)
334 std::vector<std::vector<float> > p_vecRateQuantile;
335 ///Number of events below the lower boundary per second
336 std::vector<float> p_rateEventBelowLowerBound;
337 ///Number of events above the upper boundary per second
338 std::vector<float> p_rateEventAboveUpperBound;
339 };
340
341 template<>
342 std::string phoenix_getTypeName<VecStat>();
343
344 ///@brief Generic VecStat serialisation/deserialisation, load/save and size function for PhoenixDataStream
345 template<typename Stream, DataStreamMode::DataStreamMode Mode>
346 struct DataStream<Stream, Mode, VecStat>{
347 ///Generic function to load/save/serialise/deserialise VecStat
348 /** @param[out] ds : stream to be used
349 * @param data : VecStat to be used
350 * @return true on success, false otherwise
351 */
352 6 static bool data_stream(Stream & ds, VecStat & data){
353 6 return data.readWriteStream<Stream, Mode>(ds);
354 }
355 };
356
357 ///@brief Generic VecStat Check function
358 template<>
359 struct CheckStream<VecStat>{
360 static bool check_stream(const std::string & fieldDescription, const VecStat & data, const VecStat & reference, std::ostream & out);
361 };
362
363
364
365
366 ///@brief Statistics of a Daemon
367 class DaemonStat{
368 public:
369 DaemonStat();
370 virtual ~DaemonStat();
371 DaemonStat(const DaemonStat & other);
372 DaemonStat & operator = (const DaemonStat & other);
373 void setName(const PString & name);
374 void setMapStatComputing(const std::map<PString, VecStat > & mapStatComputing);
375 void setMapStatCommunication(const std::map<PString, std::map<PString, VecStat > > & mapStatCommunication);
376 const PString & getName() const;
377 PString & getName();
378 const std::map<PString, VecStat > & getMapStatComputing() const;
379 std::map<PString, VecStat > & getMapStatComputing();
380 const std::map<PString, std::map<PString, VecStat > > & getMapStatCommunication() const;
381 std::map<PString, std::map<PString, VecStat > > & getMapStatCommunication();
382
383 ///Load the current DaemonStat with a stream
384 /** @param[out] ds : stream to be used
385 * @return true on success, false otherwise
386 */
387 template<typename Stream, DataStreamMode::DataStreamMode Mode>
388 6 bool readWriteStream(Stream & ds){
389 6 bool b(true);
390 6 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
391 6 b &= DataStream<Stream, Mode, std::map<PString, VecStat > >::data_stream(ds, p_mapStatComputing);
392 6 b &= DataStream<Stream, Mode, std::map<PString, std::map<PString, VecStat > > >::data_stream(ds, p_mapStatCommunication);
393 6 return b;
394 }
395
396 protected:
397 void copyDaemonStat(const DaemonStat & other);
398 private:
399 void initialisationDaemonStat();
400 ///Name of the Daemon where the stats come from
401 PString p_name;
402 ///Map of the computing statistics (key: stat name, value vector of stat)
403 std::map<PString, VecStat > p_mapStatComputing;
404 ///Map of the communication statistics (key: destination daemon name, value: {key: data type, value: vector of associated stats }
405 std::map<PString, std::map<PString, VecStat > > p_mapStatCommunication;
406 };
407
408 template<>
409 std::string phoenix_getTypeName<DaemonStat>();
410
411 ///@brief Generic DaemonStat serialisation/deserialisation, load/save and size function for PhoenixDataStream
412 template<typename Stream, DataStreamMode::DataStreamMode Mode>
413 struct DataStream<Stream, Mode, DaemonStat>{
414 ///Generic function to load/save/serialise/deserialise DaemonStat
415 /** @param[out] ds : stream to be used
416 * @param data : DaemonStat to be used
417 * @return true on success, false otherwise
418 */
419 6 static bool data_stream(Stream & ds, DaemonStat & data){
420 6 return data.readWriteStream<Stream, Mode>(ds);
421 }
422 };
423
424 ///@brief Generic DaemonStat Check function
425 template<>
426 struct CheckStream<DaemonStat>{
427 static bool check_stream(const std::string & fieldDescription, const DaemonStat & data, const DaemonStat & reference, std::ostream & out);
428 };
429
430
431
432
433 ///@brief Accumulator of event occurence to build swarm statistics over a time period
434 class StatAccumulator{
435 public:
436 StatAccumulator();
437 virtual ~StatAccumulator();
438 StatAccumulator(const StatAccumulator & other);
439 StatAccumulator & operator = (const StatAccumulator & other);
440 void setNbEvent(size_t nbEvent);
441 void setSum(float sum);
442 void setMin(float min);
443 void setMax(float max);
444 void setVecHistogram(const std::vector<size_t> & vecHistogram);
445 void setHistLowerBound(float histLowerBound);
446 void setHistUpperBound(float histUpperBound);
447 void setNbEventBelowLowerBound(size_t nbEventBelowLowerBound);
448 void setNbEventAboveUpperBound(size_t nbEventAboveUpperBound);
449 size_t getNbEvent() const;
450 size_t & getNbEvent();
451 float getSum() const;
452 float & getSum();
453 float getMin() const;
454 float & getMin();
455 float getMax() const;
456 float & getMax();
457 const std::vector<size_t> & getVecHistogram() const;
458 std::vector<size_t> & getVecHistogram();
459 float getHistLowerBound() const;
460 float & getHistLowerBound();
461 float getHistUpperBound() const;
462 float & getHistUpperBound();
463 size_t getNbEventBelowLowerBound() const;
464 size_t & getNbEventBelowLowerBound();
465 size_t getNbEventAboveUpperBound() const;
466 size_t & getNbEventAboveUpperBound();
467
468 ///Load the current StatAccumulator with a stream
469 /** @param[out] ds : stream to be used
470 * @return true on success, false otherwise
471 */
472 template<typename Stream, DataStreamMode::DataStreamMode Mode>
473 bool readWriteStream(Stream & ds){
474 bool b(true);
475 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbEvent);
476 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_sum);
477 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_min);
478 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_max);
479 b &= DataStream<Stream, Mode, std::vector<size_t> >::data_stream(ds, p_vecHistogram);
480 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_histLowerBound);
481 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_histUpperBound);
482 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbEventBelowLowerBound);
483 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbEventAboveUpperBound);
484 return b;
485 }
486
487 protected:
488 void copyStatAccumulator(const StatAccumulator & other);
489 private:
490 void initialisationStatAccumulator();
491 ///Number of events used to make this statistic
492 size_t p_nbEvent;
493 ///Sum of all values
494 float p_sum;
495 ///Minimum value of the stat
496 float p_min;
497 ///Maximum value of the stat
498 float p_max;
499 ///Histogram to acccumulate event counts per quantile
500 std::vector<size_t> p_vecHistogram;
501 ///Minimum value in the histogram
502 float p_histLowerBound;
503 ///Maximum value in the histogram
504 float p_histUpperBound;
505 ///Number of events below the lower bound
506 size_t p_nbEventBelowLowerBound;
507 ///Number of events above the upper boundary
508 size_t p_nbEventAboveUpperBound;
509 };
510
511 template<>
512 std::string phoenix_getTypeName<StatAccumulator>();
513
514 ///@brief Generic StatAccumulator serialisation/deserialisation, load/save and size function for PhoenixDataStream
515 template<typename Stream, DataStreamMode::DataStreamMode Mode>
516 struct DataStream<Stream, Mode, StatAccumulator>{
517 ///Generic function to load/save/serialise/deserialise StatAccumulator
518 /** @param[out] ds : stream to be used
519 * @param data : StatAccumulator to be used
520 * @return true on success, false otherwise
521 */
522 static bool data_stream(Stream & ds, StatAccumulator & data){
523 return data.readWriteStream<Stream, Mode>(ds);
524 }
525 };
526
527 ///@brief Generic StatAccumulator Check function
528 template<>
529 struct CheckStream<StatAccumulator>{
530 static bool check_stream(const std::string & fieldDescription, const StatAccumulator & data, const StatAccumulator & reference, std::ostream & out);
531 };
532
533
534
535
536 ///@brief Accumulator of all events occurence on a Daemon (processing functions and communication latencies) to build swarm statistics over a time period
537 class DaemonStatAccumulator{
538 public:
539 DaemonStatAccumulator();
540 virtual ~DaemonStatAccumulator();
541 DaemonStatAccumulator(const DaemonStatAccumulator & other);
542 DaemonStatAccumulator & operator = (const DaemonStatAccumulator & other);
543 void setMapStatComputing(const std::map<PString, StatAccumulator > & mapStatComputing);
544 void setMapStatCommunication(const std::map<PString, std::map<PString, StatAccumulator > > & mapStatCommunication);
545 const std::map<PString, StatAccumulator > & getMapStatComputing() const;
546 std::map<PString, StatAccumulator > & getMapStatComputing();
547 const std::map<PString, std::map<PString, StatAccumulator > > & getMapStatCommunication() const;
548 std::map<PString, std::map<PString, StatAccumulator > > & getMapStatCommunication();
549
550 ///Load the current DaemonStatAccumulator with a stream
551 /** @param[out] ds : stream to be used
552 * @return true on success, false otherwise
553 */
554 template<typename Stream, DataStreamMode::DataStreamMode Mode>
555 bool readWriteStream(Stream & ds){
556 bool b(true);
557 b &= DataStream<Stream, Mode, std::map<PString, StatAccumulator > >::data_stream(ds, p_mapStatComputing);
558 b &= DataStream<Stream, Mode, std::map<PString, std::map<PString, StatAccumulator > > >::data_stream(ds, p_mapStatCommunication);
559 return b;
560 }
561
562 protected:
563 void copyDaemonStatAccumulator(const DaemonStatAccumulator & other);
564 private:
565 void initialisationDaemonStatAccumulator();
566 ///Map of the computing statistics (key: stat name, value vector of stat)
567 std::map<PString, StatAccumulator > p_mapStatComputing;
568 ///Map of the communication statistics (key: destination daemon name, value: {key: data type, value: vector of associated stats })
569 std::map<PString, std::map<PString, StatAccumulator > > p_mapStatCommunication;
570 };
571
572 template<>
573 std::string phoenix_getTypeName<DaemonStatAccumulator>();
574
575 ///@brief Generic DaemonStatAccumulator serialisation/deserialisation, load/save and size function for PhoenixDataStream
576 template<typename Stream, DataStreamMode::DataStreamMode Mode>
577 struct DataStream<Stream, Mode, DaemonStatAccumulator>{
578 ///Generic function to load/save/serialise/deserialise DaemonStatAccumulator
579 /** @param[out] ds : stream to be used
580 * @param data : DaemonStatAccumulator to be used
581 * @return true on success, false otherwise
582 */
583 static bool data_stream(Stream & ds, DaemonStatAccumulator & data){
584 return data.readWriteStream<Stream, Mode>(ds);
585 }
586 };
587
588 ///@brief Generic DaemonStatAccumulator Check function
589 template<>
590 struct CheckStream<DaemonStatAccumulator>{
591 static bool check_stream(const std::string & fieldDescription, const DaemonStatAccumulator & data, const DaemonStatAccumulator & reference, std::ostream & out);
592 };
593
594
595
596
597 ///@brief Describe a Daemon of the Swarm
598 class DaemonConfig{
599 public:
600 DaemonConfig();
601 virtual ~DaemonConfig();
602 DaemonConfig(const DaemonConfig & other);
603 DaemonConfig & operator = (const DaemonConfig & other);
604 void setHostName(const PString & hostName);
605 void setReceivingPort(size_t receivingPort);
606 void setName(const PString & name);
607 void setDescription(const PString & description);
608 void setMapTimeout(const std::map<PString, time_t> & mapTimeout);
609 void setStatNbBin(size_t statNbBin);
610 void setStatHistLowerBound(float statHistLowerBound);
611 void setStatHistUpperBound(float statHistUpperBound);
612 void setStatTimerPeriodMs(const time_t & statTimerPeriodMs);
613 void setDaemonStatAccumulator(const DaemonStatAccumulator & daemonStatAccumulator);
614 void setStatDaemonName(const PString & statDaemonName);
615 const PString & getHostName() const;
616 PString & getHostName();
617 size_t getReceivingPort() const;
618 size_t & getReceivingPort();
619 const PString & getName() const;
620 PString & getName();
621 const PString & getDescription() const;
622 PString & getDescription();
623 const std::map<PString, time_t> & getMapTimeout() const;
624 std::map<PString, time_t> & getMapTimeout();
625 size_t getStatNbBin() const;
626 size_t & getStatNbBin();
627 float getStatHistLowerBound() const;
628 float & getStatHistLowerBound();
629 float getStatHistUpperBound() const;
630 float & getStatHistUpperBound();
631 const time_t & getStatTimerPeriodMs() const;
632 time_t & getStatTimerPeriodMs();
633 const DaemonStatAccumulator & getDaemonStatAccumulator() const;
634 DaemonStatAccumulator & getDaemonStatAccumulator();
635 const PString & getStatDaemonName() const;
636 PString & getStatDaemonName();
637
638 ///Load the current DaemonConfig with a stream
639 /** @param[out] ds : stream to be used
640 * @return true on success, false otherwise
641 */
642 template<typename Stream, DataStreamMode::DataStreamMode Mode>
643 bool readWriteStream(Stream & ds){
644 bool b(true);
645 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_hostName);
646 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_receivingPort);
647 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name);
648 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description);
649 b &= DataStream<Stream, Mode, std::map<PString, time_t> >::data_stream(ds, p_mapTimeout);
650 b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_statNbBin);
651 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_statHistLowerBound);
652 b &= DataStream<Stream, Mode, float >::data_stream(ds, p_statHistUpperBound);
653 b &= DataStream<Stream, Mode, time_t >::data_stream(ds, p_statTimerPeriodMs);
654 b &= DataStream<Stream, Mode, DaemonStatAccumulator >::data_stream(ds, p_daemonStatAccumulator);
655 b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_statDaemonName);
656 return b;
657 }
658
659 protected:
660 void copyDaemonConfig(const DaemonConfig & other);
661 private:
662 void initialisationDaemonConfig();
663 ///Name of the host where the daemon is running
664 PString p_hostName;
665 ///Port which is used by the Daemon to receive messages
666 size_t p_receivingPort;
667 ///Name of the Daemon
668 PString p_name;
669 ///Description of the Daemon
670 PString p_description;
671 ///Map of the timeout for each daemon in the configuration file
672 std::map<PString, time_t> p_mapTimeout;
673 /// Number of bin for the histogram of the communication statistics
674 size_t p_statNbBin;
675 /// Lower bound for the histogram of the communication statistics
676 float p_statHistLowerBound;
677 /// Upper bound for the histogram of the communication statistics
678 float p_statHistUpperBound;
679 /// Period (in ms) to send statistics to the stat daemon
680 time_t p_statTimerPeriodMs;
681 ///Accumulator used to create statistics of the current Daemon
682 DaemonStatAccumulator p_daemonStatAccumulator;
683 ///Name of the Daemon which is used to gather statistics of the swarm (empty if no stat daemon is used)
684 PString p_statDaemonName;
685 };
686
687 template<>
688 std::string phoenix_getTypeName<DaemonConfig>();
689
690 ///@brief Generic DaemonConfig serialisation/deserialisation, load/save and size function for PhoenixDataStream
691 template<typename Stream, DataStreamMode::DataStreamMode Mode>
692 struct DataStream<Stream, Mode, DaemonConfig>{
693 ///Generic function to load/save/serialise/deserialise DaemonConfig
694 /** @param[out] ds : stream to be used
695 * @param data : DaemonConfig to be used
696 * @return true on success, false otherwise
697 */
698 static bool data_stream(Stream & ds, DaemonConfig & data){
699 return data.readWriteStream<Stream, Mode>(ds);
700 }
701 };
702
703 ///@brief Generic DaemonConfig Check function
704 template<>
705 struct CheckStream<DaemonConfig>{
706 static bool check_stream(const std::string & fieldDescription, const DaemonConfig & data, const DaemonConfig & reference, std::ostream & out);
707 };
708
709
710
711
712
713
714 #endif
715
716