@@ -275,9 +275,12 @@ void TrajectoryPointInterface::connectionCallback(const socket_t filedescriptor)
275275void TrajectoryPointInterface::disconnectionCallback (const socket_t filedescriptor)
276276{
277277 URCL_LOG_DEBUG (" Connection to trajectory interface dropped." );
278- if (disconnection_callback_ != nullptr )
278+ if (!trajectory_end_callbacks_. empty () )
279279 {
280- disconnection_callback_ (filedescriptor);
280+ for (auto handler : disconnect_callbacks_)
281+ {
282+ handler.function (filedescriptor);
283+ }
281284 }
282285 client_fd_ = INVALID_SOCKET;
283286}
@@ -289,9 +292,12 @@ void TrajectoryPointInterface::messageCallback(const socket_t filedescriptor, ch
289292 int32_t * status = reinterpret_cast <int *>(buffer);
290293 URCL_LOG_DEBUG (" Received message %d on TrajectoryPointInterface" , be32toh (*status));
291294
292- if (handle_trajectory_end_ )
295+ if (!trajectory_end_callbacks_. empty () )
293296 {
294- handle_trajectory_end_ (static_cast <TrajectoryResult>(be32toh (*status)));
297+ for (auto handler : trajectory_end_callbacks_)
298+ {
299+ handler.function (static_cast <TrajectoryResult>(be32toh (*status)));
300+ }
295301 }
296302 else
297303 {
@@ -304,5 +310,23 @@ void TrajectoryPointInterface::messageCallback(const socket_t filedescriptor, ch
304310 nbytesrecv);
305311 }
306312}
313+
314+ void TrajectoryPointInterface::setTrajectoryEndCallback (std::function<void (TrajectoryResult)> callback)
315+ {
316+ addTrajectoryEndCallback (callback);
317+ }
318+
319+ uint32_t TrajectoryPointInterface::addTrajectoryEndCallback (const std::function<void (TrajectoryResult)>& callback)
320+ {
321+ trajectory_end_callbacks_.push_back ({ next_done_callback_id_, callback });
322+ return next_done_callback_id_++;
323+ }
324+
325+ void TrajectoryPointInterface::removeTrajectoryEndCallback (const uint32_t handler_id)
326+ {
327+ trajectory_end_callbacks_.remove_if (
328+ [handler_id](const HandlerFunction<void (TrajectoryResult)>& h) { return h.id == handler_id; });
329+ }
330+
307331} // namespace control
308332} // namespace urcl
0 commit comments