Class DiscoveryManager

Inheritance Relationships

Base Type

Class Documentation

class DiscoveryManager : public ros2_medkit_gateway::ServiceActionResolver

Orchestrates entity discovery using a configurable merge pipeline.

The discovery_mode parameter selects which layers the merge pipeline activates:

  • RUNTIME_ONLY: ROS 2 graph introspection only (no merge pipeline; the built-in Ros2RuntimeIntrospection provider is queried directly)

  • MANIFEST_ONLY: Manifest as the sole source of truth

  • HYBRID: Manifest + runtime + plugin layers merged through the pipeline

The DiscoveryManager provides a unified interface for discovering:

  • Areas: Logical groupings (manifest-only)

  • Components: Software/hardware units (HostInfoProvider, manifest, plugins)

  • Apps: Software applications (manifest, runtime nodes, plugins)

  • Functions: Functional groupings (manifest, namespaces, plugins)

Public Functions

explicit DiscoveryManager(rclcpp::Node *node)

Construct the discovery manager.

Parameters:

node – ROS 2 node for graph introspection (must outlive this manager)

bool initialize(const DiscoveryConfig &config)

Initialize with configuration.

Loads manifest if configured, creates appropriate strategy. For RUNTIME_ONLY mode, this is a no-op.

Parameters:

config – Discovery configuration

Returns:

true if initialization succeeded

std::vector<Area> discover_areas()

Discover all areas.

Returns:

Vector of discovered Area entities

std::vector<Component> discover_components()

Discover all components.

Returns:

Vector of discovered Component entities

std::vector<App> discover_apps()

Discover all apps.

Returns:

Vector of discovered App entities (empty in runtime-only mode)

std::vector<Function> discover_functions()

Discover all functions.

Returns:

Vector of discovered Function entities (empty in runtime-only mode)

std::vector<Function> discover_functions(const std::vector<App> &apps)

Discover functions using pre-discovered apps.

Avoids redundant ROS 2 graph introspection when apps have already been discovered in the same refresh cycle. Falls back to the no-arg overload for modes that don’t support this optimization (manifest-only, hybrid).

Parameters:

apps – Pre-discovered apps (used only in RUNTIME_ONLY mode)

Returns:

Vector of discovered Function entities

std::optional<Area> get_area(const std::string &id)

Get area by ID.

Parameters:

idArea identifier

Returns:

Area if found

std::optional<Component> get_component(const std::string &id)

Get component by ID.

Parameters:

idComponent identifier

Returns:

Component if found

std::optional<App> get_app(const std::string &id)

Get app by ID.

Parameters:

idApp identifier

Returns:

App if found

std::optional<Function> get_function(const std::string &id)

Get function by ID.

Parameters:

idFunction identifier

Returns:

Function if found

std::vector<Area> get_subareas(const std::string &area_id)

Get subareas of an area.

Parameters:

area_id – Parent area ID

Returns:

Vector of child areas

std::vector<Component> get_subcomponents(const std::string &component_id)

Get subcomponents of a component.

Parameters:

component_id – Parent component ID

Returns:

Vector of child components

std::vector<Component> get_components_for_area(const std::string &area_id)

Get components in an area.

Parameters:

area_idArea ID

Returns:

Vector of components in the area

std::vector<App> get_apps_for_component(const std::string &component_id)

Get apps for a component.

Parameters:

component_idComponent ID

Returns:

Vector of apps associated with the component

std::vector<std::string> get_hosts_for_function(const std::string &function_id)

Get host component IDs for a function.

Parameters:

function_idFunction ID

Returns:

Vector of component IDs that host the function

std::vector<ServiceInfo> discover_services()

Discover all services in the system.

Returns:

Vector of ServiceInfo with schema information

std::vector<ActionInfo> discover_actions()

Discover all actions in the system.

Returns:

Vector of ActionInfo with schema information

virtual std::optional<ServiceInfo> find_service(const std::string &component_ns, const std::string &operation_name) const override

Find a service by component namespace and operation name.

Parameters:
  • component_nsComponent namespace

  • operation_name – Service name

Returns:

ServiceInfo if found, nullopt otherwise

virtual std::optional<ActionInfo> find_action(const std::string &component_ns, const std::string &operation_name) const override

Find an action by component namespace and operation name.

Parameters:
  • component_nsComponent namespace

  • operation_name – Action name

Returns:

ActionInfo if found, nullopt otherwise

void set_topic_data_provider(TopicDataProvider *provider)

Set the topic sampler for component-topic mapping.

Parameters:

provider – Pointer to TopicDataProvider (must outlive DiscoveryManager)

void set_type_introspection(ros2_medkit_serialization::TypeIntrospection *introspection)

Set the type introspection for operation schema enrichment.

Parameters:

introspection – Pointer to TypeIntrospection (must outlive DiscoveryManager)

void refresh_topic_map()

Refresh the cached topic map.

bool is_topic_map_ready() const

Check if topic map has been built at least once.

Returns:

true if topic map is ready, false if not yet built

void add_plugin_layer(const std::string &plugin_name, IntrospectionProvider *provider)

Add a plugin layer to the merge pipeline.

Wraps an IntrospectionProvider as a PluginLayer and adds it to the pipeline. Only works in HYBRID mode.

Parameters:
void register_introspection_provider(const std::string &name, std::shared_ptr<IntrospectionProvider> provider)

Register an introspection provider with the merge pipeline.

Equivalent to add_plugin_layer for shared-ownership providers; the manager keeps the provider alive for the lifetime of the pipeline. Only meaningful in HYBRID mode.

void refresh_pipeline()

Re-execute the merge pipeline (hybrid mode only)

Call after adding plugin layers to trigger a single pipeline refresh.

discovery::ManifestManager *get_manifest_manager()

Get the manifest manager.

Returns:

Pointer to manifest manager (nullptr if not using manifest)

bool has_host_info_provider() const

Check if a host info provider is active.

Returns:

true if default component is enabled and provider exists

std::optional<Component> get_default_component() const

Get the default Component from HostInfoProvider.

Returns:

Component entity representing the local host, or nullopt if not enabled

inline DiscoveryMode get_mode() const

Get current discovery mode.

Returns:

Active discovery mode

std::string get_strategy_name() const

Get a human-readable name for the active discovery configuration.

Returns:

One of “runtime”, “manifest”, “hybrid”.

std::optional<discovery::MergeReport> get_merge_report() const

Get the last merge pipeline report (hybrid mode only)

Returns:

MergeReport if in hybrid mode, nullopt otherwise

std::optional<discovery::LinkingResult> get_linking_result() const

Get the last linking result (hybrid mode only)

Returns:

LinkingResult if in hybrid mode, nullopt otherwise