|
16 | 16 | #include <string> |
17 | 17 |
|
18 | 18 | #include "iceoryx_posh/capro/service_description.hpp" |
| 19 | +#include "iceoryx_posh/popo/listener.hpp" |
19 | 20 |
|
20 | 21 | #include "rcutils/error_handling.h" |
21 | 22 |
|
@@ -188,11 +189,49 @@ rmw_ret_t rmw_subscription_set_on_new_message_callback( |
188 | 189 | rmw_event_callback_t callback, |
189 | 190 | const void * user_data) |
190 | 191 | { |
191 | | - RCUTILS_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_INVALID_ARGUMENT); |
192 | | - RCUTILS_CHECK_ARGUMENT_FOR_NULL(callback, RMW_RET_INVALID_ARGUMENT); |
193 | | - RCUTILS_CHECK_ARGUMENT_FOR_NULL(user_data, RMW_RET_INVALID_ARGUMENT); |
| 192 | + RMW_CHECK_ARGUMENT_FOR_NULL(subscription, RMW_RET_INVALID_ARGUMENT); |
194 | 193 |
|
195 | | - return RMW_RET_UNSUPPORTED; |
| 194 | + auto iceoryx_subscription = static_cast<IceoryxSubscription *>(subscription->data); |
| 195 | + if (!iceoryx_subscription) { |
| 196 | + RMW_SET_ERROR_MSG("subscription data is null"); |
| 197 | + return RMW_RET_ERROR; |
| 198 | + } |
| 199 | + |
| 200 | + auto iceoryx_receiver = iceoryx_subscription->iceoryx_receiver_; |
| 201 | + if (!iceoryx_receiver) { |
| 202 | + RMW_SET_ERROR_MSG("iceoryx_receiver is null"); |
| 203 | + return RMW_RET_ERROR; |
| 204 | + } |
| 205 | + const std::lock_guard<std::mutex> lock(iceoryx_subscription->mutex_); |
| 206 | + rmw_ret_t ret = RMW_RET_ERROR; |
| 207 | + |
| 208 | + if (callback == nullptr) { |
| 209 | + iceoryx_subscription->listener_.detachEvent( |
| 210 | + *(iceoryx_subscription->iceoryx_receiver_), |
| 211 | + iox::popo::SubscriberEvent::DATA_RECEIVED); |
| 212 | + ret = RMW_RET_OK; |
| 213 | + return ret; |
| 214 | + } |
| 215 | + |
| 216 | + iceoryx_subscription->user_callback_ = callback; |
| 217 | + iceoryx_subscription->user_data_ = user_data; |
| 218 | + iceoryx_subscription->listener_ |
| 219 | + .attachEvent( |
| 220 | + *(iceoryx_subscription->iceoryx_receiver_), |
| 221 | + iox::popo::SubscriberEvent::DATA_RECEIVED, |
| 222 | + iox::popo::createNotificationCallback( |
| 223 | + IceoryxSubscription::onSampleReceivedCallback, |
| 224 | + *iceoryx_subscription)) |
| 225 | + .or_else( |
| 226 | + [&](auto) { |
| 227 | + RMW_SET_ERROR_MSG( |
| 228 | + "rmw_subscription_get_content_filter: Unable to attach subscriber to listener"); |
| 229 | + ret = RMW_RET_ERROR; |
| 230 | + }); |
| 231 | + |
| 232 | + ret = RMW_RET_OK; |
| 233 | + |
| 234 | + return ret; |
196 | 235 | } |
197 | 236 |
|
198 | 237 | rmw_ret_t |
|
0 commit comments