GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
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 |
mainObjectMutex(), |
||
25 |
mainObject(), |
||
26 |
update(false) |
||
27 |
|||
28 |
, |
||
29 |
SOUT(boost::bind(&Mailbox::get, this, _1, _2), sotNOSIGNAL, |
||
30 |
"Mailbox(" + name + ")::output(Object)::sout"), |
||
31 |
objSOUT(boost::bind(&Mailbox::getObject, this, _1, _2), SOUT, |
||
32 |
"Mailbox(" + name + ")::output(Object)::object"), |
||
33 |
timeSOUT(boost::bind(&Mailbox::getTimestamp, this, _1, _2), SOUT, |
||
34 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
1 |
"Mailbox(" + name + ")::output(Object)::timestamp") { |
35 |
✓✗✓✗ ✓✗ |
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 |
✓✗ | 500 |
boost::timed_mutex::scoped_try_lock lockMain(this->mainObjectMutex); |
50 |
|||
51 |
✓✗ | 250 |
if (lockMain.owns_lock()) { |
52 |
250 |
return update; |
|
53 |
} else { |
||
54 |
return false; |
||
55 |
} |
||
56 |
} |
||
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 |
✓✗ | 250 |
boost::timed_mutex::scoped_try_lock lockMain(this->mainObjectMutex); |
64 |
|||
65 |
✓✗ | 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 |
✓✗ | 250 |
res.obj = this->mainObject; |
71 |
} |
||
72 |
|||
73 |
500 |
return res; |
|
74 |
} |
||
75 |
|||
76 |
/* -------------------------------------------------------------------------- */ |
||
77 |
template <class Object> |
||
78 |
250 |
void Mailbox<Object>::post(const Object &value) { |
|
79 |
✓✗ | 500 |
boost::timed_mutex::scoped_lock lockMain(this->mainObjectMutex); |
80 |
✓✗ | 250 |
mainObject = value; |
81 |
250 |
gettimeofday(&this->mainTimeStamp, NULL); |
|
82 |
250 |
update = true; |
|
83 |
250 |
SOUT.setReady(); |
|
84 |
|||
85 |
500 |
return; |
|
86 |
} |
||
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 |
Generated by: GCOVR (Version 4.2) |