Capabilities2 0.3.0
Loading...
Searching...
No Matches
multiplex_base_runner.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <thread>
4#include <string>
5#include <map>
7
9{
11{
12public:
19
26 virtual void start(rclcpp::Node::SharedPtr node, const runner_opts& run_config) override
27 {
28 init_base(node, run_config);
29 }
30
36 virtual void execution(int id)
37 {
38 info_("execution started for id: " + std::to_string(id));
39
40 // check if the id is already completed
42 {
43 info_("execution already completed for id: " + std::to_string(id));
44 return;
45 }
46 else
47 {
48 // trigger the events related to on_success state
49 if (events[id].on_success.interface != "")
50 {
51 event_(EventType::SUCCEEDED, id, events[id].on_success.interface, events[id].on_success.provider);
52 triggerFunction_(events[id].on_success.interface, update_on_success(events[id].on_success.parameters));
53 }
54 // trigger the events related to on_failure state
55 else if (events[id].on_failure.interface != "")
56 {
57 event_(EventType::FAILED, id, events[id].on_failure.interface, events[id].on_failure.provider);
58 triggerFunction_(events[id].on_failure.interface, update_on_failure(events[id].on_failure.parameters));
59 }
60 }
61
62 // track the execution as completed
63 completed_executions[id] = true;
64
65 info_("multiplexing complete. Thread closing.", id);
66 }
67
72 virtual void stop() override
73 {
74 // if the node pointer is empty then throw an error
75 // this means that the runner was not started and is being used out of order
76
77 if (!node_)
78 throw runner_exception("cannot stop runner that was not started");
79
80 info_("stopping runner");
81 }
82
83protected:
84 // input count tracker
85 std::map<int, int> input_count_tracker;
86
87 // expected input count
88 std::map<int, int> expected_input_count;
89
90 // completed executions
91 std::map<int, bool> completed_executions;
92};
93} // namespace capabilities2_runner
Definition multiplex_base_runner.hpp:11
std::map< int, bool > completed_executions
Definition multiplex_base_runner.hpp:91
virtual void execution(int id)
Trigger process to be executed.
Definition multiplex_base_runner.hpp:36
std::map< int, int > expected_input_count
Definition multiplex_base_runner.hpp:88
MultiplexBaseRunner()
Constructor which needs to be empty due to plugin semantics.
Definition multiplex_base_runner.hpp:16
virtual void stop() override
stop function to cease functionality and shutdown
Definition multiplex_base_runner.hpp:72
virtual void start(rclcpp::Node::SharedPtr node, const runner_opts &run_config) override
Starter function for starting the action runner.
Definition multiplex_base_runner.hpp:26
std::map< int, int > input_count_tracker
Definition multiplex_base_runner.hpp:85
base class for all runners
Definition runner_base.hpp:74
void init_base(rclcpp::Node::SharedPtr node, const runner_opts &run_config)
Initializer function for initializing the base runner in place of constructor due to plugin semantics...
Definition runner_base.hpp:126
rclcpp::Node::SharedPtr node_
shared pointer to the capabilities node Allows to use ros node related functionalities
Definition runner_base.hpp:469
Definition action_runner.hpp:19
runner exception
Definition runner_base.hpp:24
runner options
Definition runner_base.hpp:56