Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
2338a09
refactor(gateway): the core builds the plugin context
bburda Oct 26, 2026
0c520e1
refactor(gateway): the core builds the fault-trigger engine and its loop
bburda Oct 26, 2026
51b0fbd
fix(gateway): the unresolved data point notice names no ROS 2 topic
bburda Oct 26, 2026
2200062
build(gateway): the core check prints the build log when the build fails
bburda Oct 26, 2026
62f92c8
test(gateway): a plugin and the fault-trigger engine run on a host wi…
bburda Oct 26, 2026
f5717dd
docs(gateway): host contract for the plugin context and the fault-tri…
bburda Oct 26, 2026
2ca7b84
fix(gateway): the plugin context of a null node does not dereference it
bburda Oct 27, 2026
389c01e
refactor(gateway): subscribe the plugin-context check's consumers str…
bburda Nov 5, 2026
38efa27
fix(action_status_bridge): exit 0 when SIGINT lands in a timer or sta…
bburda Nov 5, 2026
a5114d7
fix(action_status_bridge): wait for the action server's node name bef…
bburda Nov 5, 2026
04fddbf
fix(action_status_bridge): exit 0 when SIGINT lands during startup
bburda Nov 5, 2026
e531b3f
fix(fault_reporter): confirm delivery of every report and send it aga…
bburda Nov 6, 2026
732bc7e
fix(fault_reporter): keep retrying on every constructor and after the…
bburda Nov 6, 2026
37b5bd2
test(action_status_bridge): wait for the server publishers to match b…
bburda Nov 6, 2026
b0df145
fix(action_status_bridge): hold SIGINT and SIGTERM until the node is …
bburda Nov 6, 2026
05c6e68
fix(action_status_bridge): build the executor before restoring the si…
bburda Nov 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/config/action-status-bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Parameters
The bridge also declares ``fault_reporter.local_filtering.enabled`` (default
``false``) on its own node. See :doc:`fault-manager` for what the reporter-side
filter does.
Its reports are also confirmed and sent again when the manager does not answer; see the
``fault_reporter.delivery.*`` parameters in the ``ros2_medkit_fault_reporter`` README.

See Also
--------
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/plugin-system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Plugin Lifecycle
3. ``create_plugin()`` factory function creates the plugin instance
4. Provider interfaces are queried via ``get_update_provider()`` / ``get_introspection_provider()`` / ``get_log_provider()`` / ``get_script_provider()`` / ``get_data_provider()`` / ``get_operation_provider()`` / ``get_fault_provider()``
5. ``configure()`` is called with per-plugin JSON config
6. ``set_context()`` provides ``PluginContext`` with ROS 2 node, entity cache, faults, and HTTP utilities
6. ``set_context()`` provides ``PluginContext`` with entity cache, faults, locks, and HTTP utilities, and the ROS 2 node when the host has one
7. ``get_routes()`` returns custom REST endpoint definitions as ``vector<PluginRoute>``
8. Runtime: subsystem managers call provider methods as needed
9. ``shutdown()`` is called before the plugin is destroyed
Expand All @@ -263,7 +263,7 @@ PluginContext
After ``configure()``, the gateway calls ``set_context()`` with a ``PluginContext`` reference
providing access to gateway data and utilities:

- ``node()`` - ROS 2 node pointer for service clients, timers, and parameter access.
- ``node()`` - ROS 2 node pointer for service clients, timers, and parameter access. Null when the host is a program that hosts the core without a ROS 2 node (see ``CorePluginContext`` in the gateway README). A plugin that needs ROS checks it and declines to start; a plugin that needs no ROS never calls it. ``as_ros_plugin_context()`` is valid on every host.

.. warning::

Expand Down
7 changes: 7 additions & 0 deletions scripts/check_cores_without_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ include(${CMAKE_CURRENT_LIST_DIR}/../../src/ros2_medkit_gateway/cmake/gateway_co

add_executable(check_cores_without_ros main.cpp)
target_link_libraries(check_cores_without_ros PRIVATE fault_reporter_core fault_manager_core gateway_core)

# A plugin with no ROS dependency, loaded by the check through the core PluginManager.
add_library(check_context_plugin MODULE context_plugin.cpp)
target_link_libraries(check_context_plugin PRIVATE gateway_core)
target_compile_definitions(check_cores_without_ros PRIVATE
CHECK_CONTEXT_PLUGIN_PATH="$<TARGET_FILE:check_context_plugin>")
add_dependencies(check_cores_without_ros check_context_plugin)
2 changes: 1 addition & 1 deletion scripts/check_cores_without_ros/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ COPY src/ros2_medkit_gateway src/ros2_medkit_gateway
COPY scripts/check_cores_without_ros scripts/check_cores_without_ros
RUN CXX=g++-9 cmake -S scripts/check_cores_without_ros -B /tmp/b && cmake --build /tmp/b --parallel "$(nproc)"
RUN CXX=g++-9 scripts/check_cores_without_ros/hosts/run.sh
RUN ldd /tmp/b/check_cores_without_ros | tee /tmp/ldd.txt && ! grep -q rclcpp /tmp/ldd.txt
RUN ldd /tmp/b/check_cores_without_ros /tmp/b/libcheck_context_plugin.so | tee /tmp/ldd.txt && ! grep -q rclcpp /tmp/ldd.txt
CMD ["sh", "-c", "ldd /tmp/b/check_cores_without_ros; /tmp/b/check_cores_without_ros"]
15 changes: 13 additions & 2 deletions scripts/check_cores_without_ros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ not installed, so the PostgreSQL backend is not built.
trigger's event stream, the fault SSE stream gets the confirmation and the capture holds a frame for it. A data trigger on a plugin-served item does not fire while the value is below its range, fires once when the value
enters it, and the item is read again and again by the core's polling source. A fourth trigger with `max_triggers = 3` answers
503. A limit below 1 or past `INT_MAX` and a polling interval outside 100-60000 ms fall back with a notice.
- Plugin context: `context_plugin.cpp` builds as a shared object without ROS. The core `PluginManager` loads it, a
`make_core_plugin_context()` context goes to it, and its routes and `DataProvider` answer over HTTP. The plugin gets a null
`node()`, reads the host's entities, registers a capability, takes, checks and releases a lock, lists faults, reaches the
notifier and the condition registry, and its entity change notification reaches the host's callback. A route on an unknown
entity answers 404.
- Fault-trigger engine: a host built by `make_fault_trigger_host()` over that plugin. A rule created over HTTP reports nothing
while the plugin's value is below the threshold. When the value crosses it, the fault goes through the host's fault manager
into the host's single event source, and the fault SSE stream and the freeze-frame capture (which holds the value that crossed
the threshold) both get the confirmation. When the value comes back the engine clears the fault. A rule on an unknown app
answers 404, a disabled configuration or a host with no plugin builds no engine, and a polling interval below 50 ms is raised
and one past `INT_MAX` is capped, each with a notice.
- Bulk data: a store built by `make_bulk_data_store()` takes an upload over HTTP, lists it, returns it byte-equal and deletes
it; an upload past `max_upload_size` is refused; the categories do not contain `rosbags` when the fault manager serves none.
- `GET /` capabilities: `bulk_data` and `cyclic_subscriptions` are false for services without a store, rosbags, transport or
Expand Down Expand Up @@ -59,8 +70,8 @@ not installed, so the PostgreSQL backend is not built.

`hosts/` holds two more plain-CMake hosts that build `gateway_core` with their own `httplib::httplib` target and compile their own code as C++14: one with a version 0.26 target whose include directory has no `httplib.h` (the vendored header must be used), one with an unversioned non-global target (CMake 3.16 cannot alias it). `hosts/run.sh` builds both and runs in the Dockerfile and in the CI job.

The Dockerfile also runs `ldd` on the binary and fails when `rclcpp` appears.
The Dockerfile also runs `ldd` on the binary and on the plugin and fails when `rclcpp` appears.

The script sends only the needed source directories to `docker build` as the build
context. CI runs the same CMake steps in an `ubuntu:20.04` container (job `cores-without-ros`).
context. The build runs with `-q`; when it fails, the script repeats it with the full log, so the compiler message is printed. CI runs the same CMake steps in an `ubuntu:20.04` container (job `cores-without-ros`).
`COLCON_IGNORE` keeps colcon from treating this directory as a package.
131 changes: 131 additions & 0 deletions scripts/check_cores_without_ros/context_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright 2026 bburda
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// A plugin with no ROS dependency. The check loads it as a shared object through the core PluginManager.

#include <atomic>
#include <string>
#include <vector>

#include <nlohmann/json.hpp>

#include "ros2_medkit_gateway/core/plugins/gateway_plugin.hpp"
#include "ros2_medkit_gateway/core/plugins/plugin_context.hpp"
#include "ros2_medkit_gateway/core/plugins/plugin_types.hpp"
#include "ros2_medkit_gateway/core/providers/data_provider.hpp"
#include "ros2_medkit_gateway/core/resource_change_notifier.hpp"
#include "ros2_medkit_gateway/plugins/ros_plugin_context.hpp"

using namespace ros2_medkit_gateway;

namespace {

class ContextPlugin : public GatewayPlugin, public DataProvider {
public:
std::string name() const override {
return "check_context_plugin";
}

void configure(const nlohmann::json & /*config*/) override {
}

void set_context(PluginContext & context) override {
ctx_ = &context;
// The cast is valid on every host: a host without a ROS node gives a null node().
ros_ctx_ = as_ros_plugin_context(context);
ctx_->register_capability(SovdEntityType::APP, "x-check-context");
}

std::vector<PluginRoute> get_routes() override {
return {
{"GET", "x-check/context",
[this](const PluginRequest &, PluginResponse & res) {
res.send_json(describe_context());
}},
{"GET", "x-check/set",
[this](const PluginRequest & req, PluginResponse & res) {
value_ = std::stoi(req.query_param("value"));
res.send_json({{"value", value_.load()}});
}},
{"GET", R"(apps/([^/]+)/x-check-context)",
[this](const PluginRequest & req, PluginResponse & res) {
auto entity = ctx_->validate_entity_for_route(req, res, req.path_param(1));
if (!entity) {
return;
}
res.send_json({{"entity_id", entity->id}, {"capabilities", ctx_->get_entity_capabilities(entity->id)}});
}},
// The route the core reads the values of a plugin-served entity from.
{"GET", R"(apps/([^/]+)/x-plc-data)",
[this](const PluginRequest &, PluginResponse & res) {
res.send_json({{"connected", true}, {"items", items()}});
}},
};
}

tl::expected<dto::DataListResult, DataProviderErrorInfo> list_data(const std::string & /*entity_id*/) override {
return dto::DataListResult{{{"items", items()}}};
}
tl::expected<dto::DataValue, DataProviderErrorInfo> read_data(const std::string & /*entity_id*/,
const std::string & resource_name) override {
return dto::DataValue{{{"source", "plugin"}, {"name", resource_name}, {"value", value_.load()}}};
}
tl::expected<dto::DataWriteResult, DataProviderErrorInfo> write_data(const std::string & /*entity_id*/,
const std::string & /*resource_name*/,
const nlohmann::json & /*value*/) override {
return tl::make_unexpected(DataProviderErrorInfo{DataProviderError::ReadOnly, "read only", 405});
}

private:
nlohmann::json items() const {
return nlohmann::json::array({{{"id", "speed"}, {"name", "speed"}, {"value", value_.load()}}});
}

// What the plugin can reach through the context, as the plugin sees it.
nlohmann::json describe_context() {
nlohmann::json out;
out["node_is_null"] = ros_ctx_ != nullptr && ros_ctx_->node() == nullptr;
const auto entity = ctx_->get_entity("plugin_app");
out["entity_found"] = entity.has_value() && entity->type == SovdEntityType::APP;
out["snapshot_apps"] = ctx_->get_entity_snapshot().apps.size();
out["type_capabilities"] = ctx_->get_type_capabilities(SovdEntityType::APP);
out["notifier"] = ctx_->get_resource_change_notifier() != nullptr;
out["conditions"] = ctx_->get_condition_registry() != nullptr;
const auto lock = ctx_->acquire_lock("plugin_app", "plugin_client", {}, 60);
out["lock_acquired"] = lock.has_value();
out["lock_denies_other_client"] = !ctx_->check_lock("plugin_app", "other_client", "data").allowed;
out["lock_released"] = ctx_->release_lock("plugin_app", "plugin_client").has_value();
out["faults"] = ctx_->list_all_faults();
ctx_->notify_entities_changed(EntityChangeScope::full_refresh());
return out;
}

PluginContext * ctx_{nullptr};
RosPluginContext * ros_ctx_{nullptr};
std::atomic<int> value_{10};
};

} // namespace

extern "C" GATEWAY_PLUGIN_EXPORT int plugin_api_version() {
return PLUGIN_API_VERSION;
}

extern "C" GATEWAY_PLUGIN_EXPORT GatewayPlugin * create_plugin() {
return new ContextPlugin();
}

extern "C" GATEWAY_PLUGIN_EXPORT DataProvider * get_data_provider(GatewayPlugin * plugin) {
return static_cast<ContextPlugin *>(plugin);
}
Loading
Loading