SMACC2
Loading...
Searching...
No Matches
state_reactor.cpp
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/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#include <memory>
22
25#include "rclcpp/rclcpp.hpp"
26
27namespace smacc2
28{
30
32
34{
35 this->ownerState = ownerState;
36 this->onInitialized();
37}
38
40
41void StateReactor::onEventNotified(const std::type_info * /*eventType*/) {}
42
44
46
48{
49 if (this->triggers())
50 {
51 RCLCPP_INFO(getLogger(), "State reactor base REALLY TRIGGERS!!");
52 this->postEventFn();
53 }
54}
55
56rclcpp::Node::SharedPtr & StateReactor::getNode() { return ownerState->getNode(); }
57
58rclcpp::Logger StateReactor::getLogger() { return ownerState->getLogger(); }
59
60namespace introspection
61{
62void StateReactorHandler::configureStateReactor(std::shared_ptr<smacc2::StateReactor> sb)
63{
64 for (auto callback : this->callbacks_)
65 {
66 callback.fn(sb);
67 }
68}
69
70void EventGeneratorHandler::configureEventGenerator(std::shared_ptr<smacc2::SmaccEventGenerator> eg)
71{
72 for (auto callback : this->callbacks_)
73 {
74 callback.fn(eg);
75 }
76}
77} // namespace introspection
78} // namespace smacc2
rclcpp::Logger getLogger()
Definition: smacc_state.hpp:36
rclcpp::Node::SharedPtr & getNode()
Definition: smacc_state.hpp:34
void initialize(ISmaccState *ownerState)
virtual void onEventNotified(const std::type_info *eventType)
virtual void onEntry()
virtual void onInitialized()
virtual void onExit()
std::function< void()> postEventFn
rclcpp::Node::SharedPtr & getNode()
rclcpp::Logger getLogger()
virtual bool triggers()=0
std::vector< EventGeneratorCallbackFunctor > callbacks_
void configureEventGenerator(std::shared_ptr< smacc2::SmaccEventGenerator > eg)
void configureStateReactor(std::shared_ptr< smacc2::StateReactor > sr)
std::vector< StateReactorCallbackFunctor > callbacks_