@@ -274,9 +274,9 @@ void TrajectoryPointInterface::connectionCallback(const socket_t filedescriptor)
274
274
void TrajectoryPointInterface::disconnectionCallback (const socket_t filedescriptor)
275
275
{
276
276
URCL_LOG_DEBUG (" Connection to trajectory interface dropped." );
277
- if (disconnection_callback_ != nullptr )
277
+ for ( auto handler : disconnect_callbacks_ )
278
278
{
279
- disconnection_callback_ (filedescriptor);
279
+ handler. function (filedescriptor);
280
280
}
281
281
client_fd_ = INVALID_SOCKET;
282
282
}
@@ -288,9 +288,12 @@ void TrajectoryPointInterface::messageCallback(const socket_t filedescriptor, ch
288
288
int32_t * status = reinterpret_cast <int *>(buffer);
289
289
URCL_LOG_DEBUG (" Received message %d on TrajectoryPointInterface" , be32toh (*status));
290
290
291
- if (handle_trajectory_end_ )
291
+ if (!trajectory_end_callbacks_. empty () )
292
292
{
293
- handle_trajectory_end_ (static_cast <TrajectoryResult>(be32toh (*status)));
293
+ for (auto handler : trajectory_end_callbacks_)
294
+ {
295
+ handler.function (static_cast <TrajectoryResult>(be32toh (*status)));
296
+ }
294
297
}
295
298
else
296
299
{
@@ -303,5 +306,23 @@ void TrajectoryPointInterface::messageCallback(const socket_t filedescriptor, ch
303
306
nbytesrecv);
304
307
}
305
308
}
309
+
310
+ void TrajectoryPointInterface::setTrajectoryEndCallback (std::function<void (TrajectoryResult)> callback)
311
+ {
312
+ addTrajectoryEndCallback (callback);
313
+ }
314
+
315
+ uint32_t TrajectoryPointInterface::addTrajectoryEndCallback (const std::function<void (TrajectoryResult)>& callback)
316
+ {
317
+ trajectory_end_callbacks_.push_back ({ next_done_callback_id_, callback });
318
+ return next_done_callback_id_++;
319
+ }
320
+
321
+ void TrajectoryPointInterface::removeTrajectoryEndCallback (const uint32_t handler_id)
322
+ {
323
+ trajectory_end_callbacks_.remove_if (
324
+ [handler_id](const HandlerFunction<void (TrajectoryResult)>& h) { return h.id == handler_id; });
325
+ }
326
+
306
327
} // namespace control
307
328
} // namespace urcl
0 commit comments