11#include <capabilities2_msgs/msg/capability_event_code.hpp>
33 size_t slash_pos = thread_id.find(
'/');
34 std::string bond_id = (slash_pos != std::string::npos) ? thread_id.substr(0, slash_pos) : thread_id;
47 size_t slash_pos = thread_id.find(
'/');
48 std::string instance_id = (slash_pos != std::string::npos) ? thread_id.substr(slash_pos + 1) :
"";
74 const std::string& instance_id)
override
78 std::string thread_id = bond_id +
"/" + instance_id;
82 std::scoped_lock lock(
mutex_);
89 emit_event(bond_id, instance_id, capabilities2_msgs::msg::CapabilityEventCode::TRIGGERED);
96 RCLCPP_DEBUG(
node_->get_logger(),
"started execution thread for thread id: %s", thread_id.c_str());
114 void stop_execution(std::chrono::milliseconds timeout = std::chrono::milliseconds(500))
121 std::scoped_lock lock(
mutex_);
124 if (exec_thread.joinable())
void emit_event(const std::string &bond_id, const std::string &instance_id, const uint8_t &event_type, capabilities2_events::EventParameters parameters=capabilities2_events::EventParameters())
emit an event from this event node to all matching connections
Definition event_node.hpp:64
base class for all runners
Definition runner_base.hpp:74
rclcpp::Node::SharedPtr node_
shared pointer to the capabilities node Allows to use ros node related functionalities
Definition runner_base.hpp:469
add threaded trigger execution to the runner
Definition threadtrigger_runner.hpp:21
static const std::string bond_from_thread_id(const std::string &thread_id)
helper function to extract bond_id from thread_id
Definition threadtrigger_runner.hpp:30
void stop_execution(std::chrono::milliseconds timeout=std::chrono::milliseconds(500))
Definition threadtrigger_runner.hpp:114
ThreadTriggerRunner()
Definition threadtrigger_runner.hpp:53
~ThreadTriggerRunner()
Definition threadtrigger_runner.hpp:57
virtual void execution(capabilities2_events::EventParameters parameters, const std::string &thread_id)=0
Trigger process to be executed.
virtual void trigger(capabilities2_events::EventParameters ¶meters, const std::string &bond_id, const std::string &instance_id) override
Trigger the runner.
Definition threadtrigger_runner.hpp:73
std::atomic< bool > execution_should_stop_
flag to signal execution threads to stop.
Definition threadtrigger_runner.hpp:150
std::map< std::string, std::thread > execution_thread_pool_
dictionary of threads that executes the execute function
Definition threadtrigger_runner.hpp:140
std::mutex mutex_
mutex for threadpool synchronisation.
Definition threadtrigger_runner.hpp:145
static const std::string instance_from_thread_id(const std::string &thread_id)
helper function to extract instance_id from thread_id
Definition threadtrigger_runner.hpp:44
Definition action_runner.hpp:19
capability options for a capability runner given by interface and provider
Definition event_parameters.hpp:167