Class XMedkit
Defined in File x_medkit.hpp
Class Documentation
-
class XMedkit
Fluent builder for x-medkit extension JSON object.
The x-medkit extension provides a clean separation between SOVD-compliant fields and ros2_medkit-specific extensions in API responses.
Example usage:
XMedkit ext; ext.ros2_node("/sensors/temp_sensor") .ros2_type("sensor_msgs/msg/Temperature") .source("heuristic") .is_online(true); json response; response["id"] = "temp_sensor"; response["name"] = "Temperature Sensor"; if (!ext.empty()) { response["x-medkit"] = ext.build(); }Output structure:
{ "id": "temp_sensor", "name": "Temperature Sensor", "x-medkit": { "ros2": { "node": "/sensors/temp_sensor", "type": "sensor_msgs/msg/Temperature" }, "source": "heuristic", "is_online": true } }
Public Functions
-
XMedkit() = default
-
XMedkit &ros2_node(const std::string &node_name)
Set the ROS2 node name.
- Parameters:
node_name – Fully qualified node name (e.g., “/namespace/node_name”)
-
XMedkit &ros2_namespace(const std::string &ns)
Set the ROS2 namespace.
- Parameters:
ns – Namespace (e.g., “/sensors”)
-
XMedkit &ros2_type(const std::string &type)
Set the ROS2 message/service/action type.
- Parameters:
type – Type string (e.g., “std_msgs/msg/String”)
-
XMedkit &ros2_topic(const std::string &topic)
Set the ROS2 topic name.
- Parameters:
topic – Topic path (e.g., “/sensors/temperature”)
-
XMedkit &ros2_service(const std::string &service)
Set the ROS2 service name.
- Parameters:
service – Service path (e.g., “/calibrate”)
-
XMedkit &ros2_action(const std::string &action)
Set the ROS2 action name.
- Parameters:
action – Action path (e.g., “/navigate”)
-
XMedkit &ros2_kind(const std::string &kind)
Set the ROS2 interface kind.
- Parameters:
kind – Interface kind (“topic”, “service”, “action”)
-
XMedkit &source(const std::string &source)
Set the entity discovery source.
- Parameters:
source – Discovery source (“heuristic”, “static”, “runtime”)
-
XMedkit &is_online(bool online)
Set the entity online status.
- Parameters:
online – True if the entity is currently online/available
-
XMedkit &component_id(const std::string &id)
Set the parent component ID.
- Parameters:
id – Component identifier
-
XMedkit &entity_id(const std::string &id)
Set a generic entity ID reference.
- Parameters:
id – Entity identifier
-
XMedkit &type_info(const nlohmann::json &info)
Set type introspection information.
- Parameters:
info – JSON object with type metadata
-
XMedkit &type_schema(const nlohmann::json &schema)
Set ROS2 IDL type schema.
Note: This is distinct from SOVD’s OpenAPI schema. The type_schema contains ROS2 message/service/action structure derived from IDL definitions.
- Parameters:
schema – JSON object with IDL-derived type structure
-
XMedkit &goal_id(const std::string &id)
Set the ROS2 action goal ID.
- Parameters:
id – Goal UUID string
-
XMedkit &goal_status(const std::string &status)
Set the ROS2 action goal status.
- Parameters:
status – Status string (“pending”, “executing”, “succeeded”, “canceled”, “aborted”)
-
XMedkit &last_feedback(const nlohmann::json &feedback)
Set the last received action feedback.
- Parameters:
feedback – JSON object with feedback data
-
XMedkit &add(const std::string &key, const nlohmann::json &value)
Add a custom field to the x-medkit object (top level).
- Parameters:
key – Field name
value – Field value
-
XMedkit &add_ros2(const std::string &key, const nlohmann::json &value)
Add a custom field to the ros2 sub-object.
- Parameters:
key – Field name
value – Field value
-
nlohmann::json build() const
Build the final x-medkit JSON object.
- Returns:
JSON object containing all set fields
-
bool empty() const
Check if any fields have been set.
- Returns:
True if no fields have been set
-
XMedkit() = default