GCC Code Coverage Report


Directory: ./
File: include/sot/core/mailbox.hxx
Date: 2024-08-13 12:13:25
Exec Total Coverage
Lines: 37 45 82.2%
Branches: 29 58 50.0%

Line Branch Exec Source
1 /*
2 * Copyright 2010,
3 * François Bleibel,
4 * Olivier Stasse,
5 *
6 * CNRS/AIST
7 *
8 */
9
10 #ifndef __SOT_MAILBOX_T_CPP
11 #define __SOT_MAILBOX_T_CPP
12
13 #include <sot/core/mailbox.hh>
14
15 namespace dynamicgraph {
16 namespace sot {
17
18 /* -------------------------------------------------------------------------- */
19 /* --- CONSTRUCTION --------------------------------------------------------- */
20 /* -------------------------------------------------------------------------- */
21 template <class Object>
22 1 Mailbox<Object>::Mailbox(const std::string &name)
23 : Entity(name),
24 1 mainObjectMutex(),
25
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 mainObject(),
26 1 update(false)
27
28 ,
29
5/10
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
1 SOUT(boost::bind(&Mailbox::get, this, _1, _2), sotNOSIGNAL,
30 "Mailbox(" + name + ")::output(Object)::sout"),
31
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 objSOUT(boost::bind(&Mailbox::getObject, this, _1, _2), SOUT,
32 "Mailbox(" + name + ")::output(Object)::object"),
33
6/12
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
1 timeSOUT(boost::bind(&Mailbox::getTimestamp, this, _1, _2), SOUT,
34
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 "Mailbox(" + name + ")::output(Object)::timestamp") {
35
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 signalRegistration(SOUT << objSOUT << timeSOUT);
36 1 SOUT.setDependencyType(TimeDependency<int>::BOOL_DEPENDENT);
37 1 }
38
39 template <class Object>
40 Mailbox<Object>::~Mailbox(void) {
41 boost::timed_mutex::scoped_lock lockMain(mainObjectMutex);
42 }
43
44 /* -------------------------------------------------------------------------- */
45 /* --- ACCESS --------------------------------------------------------------- */
46 /* -------------------------------------------------------------------------- */
47 template <class Object>
48 250 bool Mailbox<Object>::hasBeenUpdated(void) {
49
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 boost::timed_mutex::scoped_try_lock lockMain(this->mainObjectMutex);
50
51
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 if (lockMain.owns_lock()) {
52 250 return update;
53 } else {
54 return false;
55 }
56 250 }
57
58 /* -------------------------------------------------------------------------- */
59 template <class Object>
60 250 typename Mailbox<Object>::sotTimestampedObject &Mailbox<Object>::get(
61 typename Mailbox<Object>::sotTimestampedObject &res,
62 const int & /*dummy*/) {
63
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 boost::timed_mutex::scoped_try_lock lockMain(this->mainObjectMutex);
64
65
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 if (lockMain.owns_lock()) {
66 250 res.timestamp.tv_sec = this->mainTimeStamp.tv_sec;
67 250 res.timestamp.tv_usec = this->mainTimeStamp.tv_usec;
68
69 250 update = false;
70
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 res.obj = this->mainObject;
71 }
72
73 250 return res;
74 250 }
75
76 /* -------------------------------------------------------------------------- */
77 template <class Object>
78 250 void Mailbox<Object>::post(const Object &value) {
79
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 boost::timed_mutex::scoped_lock lockMain(this->mainObjectMutex);
80
1/2
✓ Branch 1 taken 250 times.
✗ Branch 2 not taken.
250 mainObject = value;
81 250 gettimeofday(&this->mainTimeStamp, NULL);
82 250 update = true;
83 250 SOUT.setReady();
84
85 500 return;
86 250 }
87
88 template <class Object>
89 250 Object &Mailbox<Object>::getObject(Object &res, const int &time) {
90 250 const sotTimestampedObject &data = SOUT(time);
91 250 res = data.obj;
92 250 return res;
93 }
94
95 template <class Object>
96 timeval &Mailbox<Object>::getTimestamp(struct timeval &res, const int &time) {
97 const sotTimestampedObject &data = SOUT(time);
98 res.tv_sec = data.timestamp.tv_sec;
99 res.tv_usec = data.timestamp.tv_usec;
100 return res;
101 }
102
103 } /* namespace sot */
104 } /* namespace dynamicgraph */
105 /* Macro for template specialization */
106 #ifndef WIN32
107 #define MAILBOX_TEMPLATE_SPE(S) \
108 namespace dynamicgraph { \
109 namespace sot { \
110 template void Mailbox<S>::post(const S &obj); \
111 template dynamicgraph::Vector &Mailbox<S>::getObject(S &res, \
112 const int &time); \
113 template bool Mailbox<S>::hasBeenUpdated(void); \
114 template Mailbox<S>::~Mailbox(); \
115 template Mailbox<S>::sotTimestampedObject &Mailbox<S>::get( \
116 Mailbox<S>::sotTimestampedObject &res, const int &dummy); \
117 template Mailbox<S>::Mailbox(const std::string &name); \
118 } \
119 } // namespace sot namespace dynamicgraph
120 #endif // WIN32
121
122 #endif // #ifdef __SOT_MAILBOX_T_CPP
123