SMACC2
Loading...
Searching...
No Matches
cb_default_multirole_sensor_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
16
18
19#include <string>
20
22
23namespace cl_multirole_sensor
24{
25template <typename ClientType>
27{
28public:
29 typedef typename ClientType::TMessageType TMessageType;
30
31 ClientType * sensor_;
32
34
35 static std::string getEventLabel()
36 {
37 // show ros message type
38 return demangleSymbol(typeid(TMessageType).name());
39 }
40
41 std::function<void()> deferedEventPropagation;
42
43 template <typename TOrthogonal, typename TSourceObject>
45 {
47 {
48 RCLCPP_INFO(
49 getLogger(), "[CbDefaultMultiRoleSensorBehavior] onEntry. Requires client of type '%s'",
50 demangleSymbol<ClientType>().c_str());
51
52 // just propagate the client events from this client behavior source.
53 sensor_->onMessageReceived(
56 this);
57 sensor_->onFirstMessageReceived(
60 this);
61 sensor_->onMessageTimeout(
64 this);
65 };
66 }
67
68 template <typename EvType>
69 void propagateEvent(const TMessageType & /*msg*/)
70 {
71 // TODO: copy event concept fields
72 this->postEvent<EvType>();
73 }
74
75 template <typename EvType>
77 {
78 this->postEvent<EvType>();
79 }
80
81 void onEntry() override
82 {
83 RCLCPP_INFO(
84 getLogger(), "[CbDefaultMultiRoleSensorBehavior] onEntry. Requires client of type '%s'",
85 demangleSymbol<ClientType>().c_str());
86
87 if (sensor_ == nullptr)
88 {
89 this->requiresClient(sensor_);
90 }
91
92 if (sensor_ == nullptr)
93 {
94 RCLCPP_FATAL_STREAM(
95 getLogger(),
96 "[CbDefaultMultiRoleSensorBehavior]Sensor client behavior needs a client of type: "
97 << demangleSymbol<ClientType>() << " but it is not found.");
98 }
99 else
100 {
102 RCLCPP_INFO(getLogger(), "[CbDefaultMultiRoleSensorBehavior] onEntry. sensor initialize");
103 }
104 }
105
106 void onExit() {}
107
108 virtual void onMessageCallback(const TMessageType & /*msg*/)
109 {
110 // empty to fill by sensor customization based on inheritance
111 }
112};
113} // namespace cl_multirole_sensor
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)
std::string demangleSymbol()