Class DataAccessManager

Class Documentation

class DataAccessManager

Application service for topic publish + sample.

Pure C++; ROS-side I/O is performed by the injected TopicTransport adapter (typically Ros2TopicTransport). Type introspection and the per-entity TopicDataProvider pointer remain on the manager because they are consumed directly by handlers and the discovery manager.

Public Functions

explicit DataAccessManager(std::shared_ptr<TopicTransport> transport, double topic_sample_timeout_sec = 1.0)
Parameters:
  • transport – Concrete TopicTransport adapter. Manager takes shared ownership.

  • topic_sample_timeout_sec – Default sample timeout in seconds. Used when callers pass a negative timeout.

~DataAccessManager() = default
DataAccessManager(const DataAccessManager&) = delete
DataAccessManager &operator=(const DataAccessManager&) = delete
DataAccessManager(DataAccessManager&&) = delete
DataAccessManager &operator=(DataAccessManager&&) = delete
json publish_to_topic(const std::string &topic_path, const std::string &msg_type, const json &data, double timeout_sec = 5.0)

Publish data to a specific topic.

Parameters:
  • topic_path – Full topic path (e.g., /chassis/brakes/command).

  • msg_type – ROS 2 message type (e.g., std_msgs/msg/Float32).

  • data – JSON data to publish.

  • timeout_sec – Timeout for the publish operation.

Returns:

JSON with publish status.

json get_topic_sample_with_fallback(const std::string &topic_name, double timeout_sec = -1.0)

Get topic sample with fallback to metadata on timeout.

If the topic is publishing, returns actual data with type info. If the topic times out, returns metadata (type, schema, pub/sub counts) instead of an error.

Parameters:
  • topic_name – Full topic path.

  • timeout_sec – Timeout for data retrieval. Use -1.0 to use the configured default.

json get_topic_sample_native(const std::string &topic_name, double timeout_sec = 1.0)

Get single topic sample using the native fast path.

Fast path for single-topic sampling. When no publishers are present, returns metadata-only without calling into the transport.

Parameters:
  • topic_name – Full topic path.

  • timeout_sec – Timeout for sampling (only used if topic has publishers).

inline ros2_medkit_serialization::TypeIntrospection *get_type_introspection() const

Get the type introspection instance (used by handlers and discovery).

Forwarded to the transport adapter, which owns the rclcpp-coupled implementation. May return nullptr for transports that do not support introspection.

inline void set_topic_data_provider(TopicDataProvider *provider)

Attach a TopicDataProvider for sampling.

The provider owns the pool-backed subscription path. Non-owning pointer; caller retains ownership. Safe to call once at wiring time.

inline TopicDataProvider *get_topic_data_provider() const
inline double get_topic_sample_timeout() const

Get the configured topic sample timeout in seconds.