Class TriggerTopicSubscriber
Defined in File trigger_topic_subscriber.hpp
Nested Relationships
Nested Types
Class Documentation
-
class TriggerTopicSubscriber
rclcpp-coupled topic subscription executor for the trigger subsystem.
Each trigger that observes a “data” resource registers exactly one subscription here, identified by a caller-provided handle key. The subscriber owns the rclcpp::GenericSubscription, performs the CDR -> JSON deserialization, and delivers each sample to the handle’s callback. When the topic’s type cannot be resolved at subscribe time (publisher not yet up), the entry is queued as “pending” and retried every 5 seconds. Pending entries time out after 60 seconds.
Threading: subscribe()/unsubscribe()/shutdown() are mutex-guarded. Per-handle callbacks are invoked from rclcpp executor threads. The subscription-destructor pattern (callbacks cannot fire on a partially destroyed subscriber) is enforced by the shutdown_flag_ guard followed by subscription map clearing inside shutdown().
The lifetime of an individual subscription is tied to the corresponding handle key: unsubscribe(handle_key) atomically removes both the user callback and the underlying rclcpp::Subscription, so any in-flight dispatch sees the empty map and short-circuits.
The retry callback (set via set_retry_callback) is fired on every retry tick. The trigger manager wires this to retry_unresolved_triggers() so that triggers whose resource_path was not yet resolvable to a topic at creation time get a chance to convert into a real subscription.
Public Types
-
using SampleCallback = std::function<void(const nlohmann::json &sample)>
Callback delivering one deserialized sample as JSON. Invoked on the rclcpp executor thread.
-
using RetryCallback = std::function<void()>
Callback invoked on every retry tick (alongside pending-subscription resolution). The trigger manager wires this to retry_unresolved_triggers().
Public Functions
-
explicit TriggerTopicSubscriber(rclcpp::Node *node)
Construct the subscriber.
- Parameters:
node – Non-owning ROS node used to create rclcpp::GenericSubscription and the retry wall timer.
-
~TriggerTopicSubscriber()
-
TriggerTopicSubscriber(const TriggerTopicSubscriber&) = delete
-
TriggerTopicSubscriber &operator=(const TriggerTopicSubscriber&) = delete
-
TriggerTopicSubscriber(TriggerTopicSubscriber&&) = delete
-
TriggerTopicSubscriber &operator=(TriggerTopicSubscriber&&) = delete
-
void subscribe(const std::string &topic_name, const std::string &msg_type, const std::string &handle_key, SampleCallback callback)
Subscribe to a topic under a unique handle key.
Each call yields one rclcpp::GenericSubscription dedicated to the caller’s handle. If
msg_typeis empty the type is resolved from the ROS graph; if no publisher is yet advertising the topic, the entry is queued for retry.Idempotent: a second call with an already-registered key replaces both the type and the callback for that key.
- Parameters:
topic_name – Fully qualified ROS 2 topic name (e.g. “/sensor/temp”).
msg_type – Fully qualified message type, or empty for auto-resolve.
handle_key – Caller-allocated unique key. The transport adapter uses this to disambiguate per-trigger subscriptions.
callback – Invoked for every successfully deserialized sample.
-
void unsubscribe(const std::string &handle_key)
Drop the subscription for
handle_key. Both the user callback and the rclcpp::GenericSubscription are released; in-flight dispatch is guaranteed not to fire after this returns.
-
void shutdown()
Shut down all subscriptions. Idempotent.
-
void set_retry_callback(RetryCallback cb)
-
using SampleCallback = std::function<void(const nlohmann::json &sample)>