SMACC2
cb_my_subscriber_behavior.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
17
18namespace sm_pubsub_1
19{
20namespace cl_subscriber
21{
22template <typename TSource, typename TOrthogonal>
23struct EvMyBehavior : sc::event<EvMyBehavior<TSource, TOrthogonal>>
24{
25};
26
28{
29public:
30 void onEntry()
31 {
32 ClSubscriber * client;
33 this->requiresClient(client);
34
36 }
37
38 template <typename TOrthogonal, typename TSourceObject>
40 {
41 postMyEvent_ = [=] { this->postEvent<EvMyBehavior<TSourceObject, TOrthogonal>>(); };
42 }
43
44 void onMessageReceived(const std_msgs::msg::Float32 & msg)
45 {
46 if (msg.data > 30)
47 {
48 RCLCPP_INFO(
49 getLogger(),
50 "[CbMySubscriberBehavior] received message from topic with value > 30. "
51 "Posting event!");
52 this->postMyEvent_();
53 }
54 }
55
56 std::function<void()> postMyEvent_;
57};
58} // namespace cl_subscriber
59} // namespace sm_pubsub_1
void onMessageReceived(const std_msgs::msg::Float32 &msg)
void requiresClient(SmaccClientType *&storage)
boost::signals2::connection onMessageReceived(void(T::*callback)(const MessageType &), T *object)