Class TriggerTopicSubscriber

Nested Relationships

Nested Types

Class Documentation

class TriggerTopicSubscriber

Manages persistent ROS 2 topic subscriptions for data triggers.

When a trigger observes a “data” resource, TriggerTopicSubscriber creates a GenericSubscription for the corresponding topic, deserializes incoming messages to JSON, and forwards them to the ResourceChangeNotifier for trigger evaluation.

Subscriptions are ref-counted: multiple triggers on the same topic share a single ROS 2 subscription. When the last trigger on a topic is removed, the subscription is destroyed.

When a topic’s type cannot be determined at subscribe() time (e.g., the publisher hasn’t started yet), the subscription is queued as “pending” and retried every 5 seconds by a wall timer. Pending subscriptions time out after 60 seconds.

Public Functions

TriggerTopicSubscriber(rclcpp::Node *node, ResourceChangeNotifier &notifier)

Construct the subscriber.

Parameters:
  • node – Raw pointer to the ROS 2 node for creating subscriptions (caller manages lifetime)

  • notifierResourceChangeNotifier to forward data events to

~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 &resource_path, const std::string &entity_id)

Subscribe to a topic for data trigger monitoring.

If the topic is already subscribed, adds the entity_id to the set. Otherwise, creates a GenericSubscription that deserializes messages to JSON and forwards them to the notifier.

If the topic type cannot be determined (e.g., no publishers yet), the subscription is queued as pending and retried periodically.

Parameters:
  • topic_name – ROS 2 topic name (e.g., “/sensor/temperature”)

  • resource_path – Resource path for notification matching (e.g., “/temperature”)

  • entity_id – Entity ID for the notification (e.g., “temp_sensor”)

void unsubscribe(const std::string &topic_name, const std::string &entity_id)

Unsubscribe an entity from a topic.

Removes the entity_id from the set. If the set becomes empty, the ROS 2 subscription is destroyed.

Parameters:
  • topic_name – ROS 2 topic name to unsubscribe from

  • entity_id – Entity ID to remove from the subscription

void shutdown()

Shutdown all subscriptions.

Clears all active subscriptions. Safe to call multiple times.