File tree 12 files changed +128
-0
lines changed 12 files changed +128
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ class ClientBase
150
150
bool
151
151
exchange_in_use_by_wait_set_state (bool in_use_state);
152
152
153
+ RCLCPP_PUBLIC
154
+ void
155
+ set_listener_callback (
156
+ rmw_listener_callback_t callback,
157
+ const void * user_data) const ;
158
+
153
159
protected:
154
160
RCLCPP_DISABLE_COPY (ClientBase)
155
161
Original file line number Diff line number Diff line change @@ -74,6 +74,12 @@ class SubscriptionIntraProcessBase : public rclcpp::Waitable
74
74
rmw_qos_profile_t
75
75
get_actual_qos () const ;
76
76
77
+ RCLCPP_PUBLIC
78
+ void
79
+ set_listener_callback (
80
+ rmw_listener_callback_t callback,
81
+ const void * user_data) const override ;
82
+
77
83
protected:
78
84
std::recursive_mutex reentrant_mutex_;
79
85
rcl_guard_condition_t gc_;
Original file line number Diff line number Diff line change @@ -102,6 +102,12 @@ class QOSEventHandlerBase : public Waitable
102
102
bool
103
103
is_ready (rcl_wait_set_t * wait_set) override ;
104
104
105
+ RCLCPP_PUBLIC
106
+ void
107
+ set_listener_callback (
108
+ rmw_listener_callback_t callback,
109
+ const void * user_data) const override ;
110
+
105
111
protected:
106
112
rcl_event_t event_handle_;
107
113
size_t wait_set_event_index_;
Original file line number Diff line number Diff line change @@ -121,6 +121,12 @@ class ServiceBase
121
121
bool
122
122
exchange_in_use_by_wait_set_state (bool in_use_state);
123
123
124
+ RCLCPP_PUBLIC
125
+ void
126
+ set_listener_callback (
127
+ rmw_listener_callback_t callback,
128
+ const void * user_data) const ;
129
+
124
130
protected:
125
131
RCLCPP_DISABLE_COPY (ServiceBase)
126
132
Original file line number Diff line number Diff line change @@ -263,6 +263,12 @@ class SubscriptionBase : public std::enable_shared_from_this<SubscriptionBase>
263
263
bool
264
264
exchange_in_use_by_wait_set_state (void * pointer_to_subscription_part, bool in_use_state);
265
265
266
+ RCLCPP_PUBLIC
267
+ void
268
+ set_listener_callback (
269
+ rmw_listener_callback_t callback,
270
+ const void * user_data) const ;
271
+
266
272
protected:
267
273
template <typename EventCallbackT>
268
274
void
Original file line number Diff line number Diff line change @@ -203,6 +203,13 @@ class Waitable
203
203
bool
204
204
exchange_in_use_by_wait_set_state (bool in_use_state);
205
205
206
+ RCLCPP_PUBLIC
207
+ virtual
208
+ void
209
+ set_listener_callback (
210
+ rmw_listener_callback_t callback,
211
+ const void * user_data) const ;
212
+
206
213
private:
207
214
std::atomic<bool > in_use_by_wait_set_{false };
208
215
}; // class Waitable
Original file line number Diff line number Diff line change @@ -198,3 +198,18 @@ ClientBase::exchange_in_use_by_wait_set_state(bool in_use_state)
198
198
{
199
199
return in_use_by_wait_set_.exchange (in_use_state);
200
200
}
201
+
202
+ void
203
+ ClientBase::set_listener_callback (
204
+ rmw_listener_callback_t callback,
205
+ const void * user_data) const
206
+ {
207
+ rcl_ret_t ret = rcl_client_set_listener_callback (
208
+ client_handle_.get (),
209
+ callback,
210
+ user_data);
211
+
212
+ if (RCL_RET_OK != ret) {
213
+ throw std::runtime_error (" Couldn't set listener callback to client" );
214
+ }
215
+ }
Original file line number Diff line number Diff line change @@ -68,4 +68,20 @@ QOSEventHandlerBase::is_ready(rcl_wait_set_t * wait_set)
68
68
return wait_set->events [wait_set_event_index_] == &event_handle_;
69
69
}
70
70
71
+ void
72
+ QOSEventHandlerBase::set_listener_callback (
73
+ rmw_listener_callback_t callback,
74
+ const void * user_data) const
75
+ {
76
+ rcl_ret_t ret = rcl_event_set_listener_callback (
77
+ &event_handle_,
78
+ callback,
79
+ user_data,
80
+ false /* Discard previous events */ );
81
+
82
+ if (RCL_RET_OK != ret) {
83
+ throw std::runtime_error (" Couldn't set listener callback to QOSEventHandlerBase" );
84
+ }
85
+ }
86
+
71
87
} // namespace rclcpp
Original file line number Diff line number Diff line change @@ -84,3 +84,18 @@ ServiceBase::exchange_in_use_by_wait_set_state(bool in_use_state)
84
84
{
85
85
return in_use_by_wait_set_.exchange (in_use_state);
86
86
}
87
+
88
+ void
89
+ ServiceBase::set_listener_callback (
90
+ rmw_listener_callback_t callback,
91
+ const void * user_data) const
92
+ {
93
+ rcl_ret_t ret = rcl_service_set_listener_callback (
94
+ service_handle_.get (),
95
+ callback,
96
+ user_data);
97
+
98
+ if (RCL_RET_OK != ret) {
99
+ throw std::runtime_error (" Couldn't set listener callback to service" );
100
+ }
101
+ }
Original file line number Diff line number Diff line change @@ -288,3 +288,18 @@ SubscriptionBase::exchange_in_use_by_wait_set_state(
288
288
}
289
289
throw std::runtime_error (" given pointer_to_subscription_part does not match any part" );
290
290
}
291
+
292
+ void
293
+ SubscriptionBase::set_listener_callback (
294
+ rmw_listener_callback_t callback,
295
+ const void * user_data) const
296
+ {
297
+ rcl_ret_t ret = rcl_subscription_set_listener_callback (
298
+ subscription_handle_.get (),
299
+ callback,
300
+ user_data);
301
+
302
+ if (RCL_RET_OK != ret) {
303
+ throw std::runtime_error (" Couldn't set listener callback to subscription" );
304
+ }
305
+ }
Original file line number Diff line number Diff line change @@ -36,3 +36,19 @@ SubscriptionIntraProcessBase::get_actual_qos() const
36
36
{
37
37
return qos_profile_;
38
38
}
39
+
40
+ void
41
+ SubscriptionIntraProcessBase::set_listener_callback (
42
+ rmw_listener_callback_t callback,
43
+ const void * user_data) const
44
+ {
45
+ rcl_ret_t ret = rcl_guard_condition_set_listener_callback (
46
+ &gc_,
47
+ callback,
48
+ user_data,
49
+ true /* Use previous events*/ );
50
+
51
+ if (RCL_RET_OK != ret) {
52
+ throw std::runtime_error (" Couldn't set guard condition listener callback" );
53
+ }
54
+ }
Original file line number Diff line number Diff line change 12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ #include < stdexcept>
16
+
15
17
#include " rclcpp/waitable.hpp"
16
18
17
19
using rclcpp::Waitable;
@@ -57,3 +59,15 @@ Waitable::exchange_in_use_by_wait_set_state(bool in_use_state)
57
59
{
58
60
return in_use_by_wait_set_.exchange (in_use_state);
59
61
}
62
+
63
+ void
64
+ Waitable::set_listener_callback (
65
+ rmw_listener_callback_t callback,
66
+ const void * user_data) const
67
+ {
68
+ (void )callback;
69
+ (void )user_data;
70
+
71
+ throw std::runtime_error (
72
+ " Custom waitables should override set_listener_callback() if they want to use RMW listeners" );
73
+ }
You can’t perform that action at this time.
0 commit comments