10#ifndef _TOPIC_STATUS_CHECK_BASE_HPP
11#define _TOPIC_STATUS_CHECK_BASE_HPP
13#include <rclcpp/rclcpp.hpp>
14#include <rclcpp/wait_for_message.hpp>
25template <
typename MessageT>
35 void set_config(
const std::string topic_name,
const uint32_t timeout_ms)
37 topic_name_ = topic_name;
38 timeout_ms_ = timeout_ms;
48 virtual bool validate([[maybe_unused]]
const MessageT & msg) {
return true; }
51 std::string topic_name_;
52 uint32_t timeout_ms_ = 0;
53 std::string status_msg_;
55 std::string status_id_ =
"";
56 std::string get_unique_id()
const override
58 if (status_id_.empty()) {
61 return "TopicStatusCheckBase::" + topic_name_ +
"::" + status_id_;
64 bool check_impl(rclcpp::Node::SharedPtr node)
override
66 if (topic_name_.empty() || timeout_ms_ == 0) {
67 status_msg_ =
"Not set topic_name or timeout. Please invoke `set_config()` function.";
74 bool received = rclcpp::wait_for_message<MessageT>(
75 msg, node, topic_name_,
76 std::chrono::duration_cast<std::chrono::nanoseconds>(
77 std::chrono::duration<double>(timeout_ms_ * 1e-3)));
81 status_msg_ =
"Received & Validated";
84 status_msg_ =
"Received but invalid content";
88 status_msg_ =
"Timeout";
93 std::string report_impl([[maybe_unused]] rclcpp::Node::SharedPtr node)
override
95 return "Topic: " + topic_name_ +
" | " + status_msg_;
Abstract base class for all system check plugins.
Definition: system_check_base.hpp:24
Template class for checking topic reception.
Definition: topic_status_check_base.hpp:27
void set_config(const std::string topic_name, const uint32_t timeout_ms)
Definition: topic_status_check_base.hpp:35
void set_status_id(const std::string id)
Set the status id for cache check.
Definition: topic_status_check_base.hpp:33
virtual bool validate(const MessageT &msg)
Virtual function to verify message content. Defaults to "OK if received". Override in a derived class...
Definition: topic_status_check_base.hpp:48
virtual void prepare_check(rclcpp::Node::SharedPtr node) override=0
Prepares the check before execution.
Definition: action_server_check_base.hpp:25
Abstruct Class of check process.