10#ifndef _ACTION_SERVER_CHECK_BASE_HPP
11#define _ACTION_SERVER_CHECK_BASE_HPP
13#include <rclcpp/rclcpp.hpp>
17#include <rcl/allocator.h>
19#include <rcl_action/graph.h>
39 const std::string action_name,
const uint32_t timeout_ms,
size_t expected_count = 1)
49 rcl_node_t * rcl_node, rcl_allocator_t * allocator,
const std::string & node_name,
50 const std::string & node_ns) = 0;
55 std::string status_msg_;
57 bool check_impl(rclcpp::Node::SharedPtr node)
override
60 status_msg_ =
"Action name not set. Please invoke `set_config()` function.";
64 auto start_time = std::chrono::steady_clock::now();
65 auto timeout_duration = std::chrono::milliseconds(
timeout_ms_);
68 rcl_node_t * rcl_node = node->get_node_base_interface()->get_rcl_node_handle();
69 rcl_allocator_t allocator = rcl_get_default_allocator();
72 std::string current_node_name = node->get_fully_qualified_name();
78 auto node_names = node->get_node_names();
81 for (
const auto & full_node_name : node_names) {
83 if (full_node_name == current_node_name) {
88 std::string target_node_name;
89 std::string target_node_ns;
91 size_t last_slash = full_node_name.find_last_of(
'/');
92 if (last_slash == std::string::npos || last_slash == 0) {
94 target_node_name = (last_slash == 0) ? full_node_name.substr(1) : full_node_name;
96 target_node_ns = full_node_name.substr(0, last_slash);
97 target_node_name = full_node_name.substr(last_slash + 1);
108 status_msg_ =
"Found " + std::to_string(count) +
" Action " +
get_target_type() +
"(s).";
113 auto elapsed = std::chrono::steady_clock::now() - start_time;
114 if (elapsed > timeout_duration) {
115 status_msg_ =
"Timeout. Found " + std::to_string(count) +
" Action " +
get_target_type() +
120 std::this_thread::sleep_for(std::chrono::milliseconds(100));
124 std::string report_impl([[maybe_unused]] rclcpp::Node::SharedPtr node)
override
136 std::string get_unique_id()
const override
141 std::string get_target_type()
const override {
return "Server"; }
143 bool check_entity_in_node(
144 rcl_node_t * rcl_node, rcl_allocator_t * allocator,
const std::string & node_name,
145 const std::string & node_ns)
override
147 rcl_names_and_types_t names_and_types = rcl_get_zero_initialized_names_and_types();
151 rcl_ret_t ret = rcl_action_get_server_names_and_types_by_node(
152 rcl_node, allocator, node_name.c_str(), node_ns.c_str(), &names_and_types);
154 if (ret == RCL_RET_OK) {
155 for (
size_t i = 0; i < names_and_types.names.size; ++i) {
156 if (std::string(names_and_types.names.data[i]) ==
action_name_) {
163 rcl_ret_t fini_ret = rcl_names_and_types_fini(&names_and_types);
176 std::string get_unique_id()
const override
181 std::string get_target_type()
const override {
return "Client"; }
183 bool check_entity_in_node(
184 rcl_node_t * rcl_node, rcl_allocator_t * allocator,
const std::string & node_name,
185 const std::string & node_ns)
override
187 rcl_names_and_types_t names_and_types = rcl_get_zero_initialized_names_and_types();
191 rcl_ret_t ret = rcl_action_get_client_names_and_types_by_node(
192 rcl_node, allocator, node_name.c_str(), node_ns.c_str(), &names_and_types);
194 if (ret == RCL_RET_OK) {
195 for (
size_t i = 0; i < names_and_types.names.size; ++i) {
196 if (std::string(names_and_types.names.data[i]) ==
action_name_) {
203 rcl_ret_t fini_ret = rcl_names_and_types_fini(&names_and_types);
Checks specifically for Action CLIENTS.
Definition: action_server_check_base.hpp:174
Abstract base class for checking Action Server/Client existence. Handles node iteration,...
Definition: action_server_check_base.hpp:32
virtual void prepare_check(rclcpp::Node::SharedPtr node) override=0
Prepares the check before execution.
uint32_t timeout_ms_
Definition: action_server_check_base.hpp:35
void set_config(const std::string action_name, const uint32_t timeout_ms, size_t expected_count=1)
Definition: action_server_check_base.hpp:38
std::string action_name_
Definition: action_server_check_base.hpp:34
virtual bool check_entity_in_node(rcl_node_t *rcl_node, rcl_allocator_t *allocator, const std::string &node_name, const std::string &node_ns)=0
size_t expected_count_
Definition: action_server_check_base.hpp:36
virtual std::string get_target_type() const =0
Checks specifically for Action SERVERS.
Definition: action_server_check_base.hpp:134
Abstract base class for all system check plugins.
Definition: system_check_base.hpp:24
Definition: action_server_check_base.hpp:25
Abstruct Class of check process.