Modulo 4.2.2
Loading...
Searching...
No Matches
SubscriptionHandler.cpp
1#include "modulo_core/communication/SubscriptionHandler.hpp"
2
3#include <utility>
4
6
7template<>
8std::function<void(const std::shared_ptr<std_msgs::msg::Bool>)>
9SubscriptionHandler<std_msgs::msg::Bool>::get_translated_callback() {
10 return [this](const std::shared_ptr<std_msgs::msg::Bool> message) {
11 try {
12 this->get_message_pair()->template read<std_msgs::msg::Bool, bool>(*message);
13 this->user_callback_();
14 } catch (...) {
15 this->handle_callback_exceptions();
16 }
17 };
18}
19
20template<>
21std::function<void(const std::shared_ptr<std_msgs::msg::Float64>)>
22SubscriptionHandler<std_msgs::msg::Float64>::get_translated_callback() {
23 return [this](const std::shared_ptr<std_msgs::msg::Float64> message) {
24 try {
25 this->get_message_pair()->template read<std_msgs::msg::Float64, double>(*message);
26 this->user_callback_();
27 } catch (...) {
28 this->handle_callback_exceptions();
29 }
30 };
31}
32
33template<>
34std::function<void(const std::shared_ptr<std_msgs::msg::Float64MultiArray>)>
35SubscriptionHandler<std_msgs::msg::Float64MultiArray>::get_translated_callback() {
36 return [this](const std::shared_ptr<std_msgs::msg::Float64MultiArray> message) {
37 try {
38 this->get_message_pair()->template read<std_msgs::msg::Float64MultiArray, std::vector<double>>(*message);
39 this->user_callback_();
40 } catch (...) {
41 this->handle_callback_exceptions();
42 }
43 };
44}
45
46template<>
47std::function<void(const std::shared_ptr<std_msgs::msg::Int32>)>
48SubscriptionHandler<std_msgs::msg::Int32>::get_translated_callback() {
49 return [this](const std::shared_ptr<std_msgs::msg::Int32> message) {
50 try {
51 this->get_message_pair()->template read<std_msgs::msg::Int32, int>(*message);
52 this->user_callback_();
53 } catch (...) {
54 this->handle_callback_exceptions();
55 }
56 };
57}
58
59template<>
60std::function<void(const std::shared_ptr<std_msgs::msg::String>)>
61SubscriptionHandler<std_msgs::msg::String>::get_translated_callback() {
62 return [this](const std::shared_ptr<std_msgs::msg::String> message) {
63 try {
64 this->get_message_pair()->template read<std_msgs::msg::String, std::string>(*message);
65 this->user_callback_();
66 } catch (...) {
67 this->handle_callback_exceptions();
68 }
69 };
70}
71
72template<>
73std::function<void(const std::shared_ptr<EncodedState>)> SubscriptionHandler<EncodedState>::get_translated_callback() {
74 return [this](const std::shared_ptr<EncodedState> message) {
75 try {
76 this->get_message_pair()->template read<EncodedState, state_representation::State>(*message);
77 this->user_callback_();
78 } catch (...) {
79 this->handle_callback_exceptions();
80 }
81 };
82}
83
84}// namespace modulo_core::communication
Modulo Core communication module for handling messages on publication and subscription interfaces.