SMACC2
smacc_state.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/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20#pragma once
21#include <smacc2/common.hpp>
22
23namespace smacc2
24{
26{
27public:
29
30 virtual std::string getName() = 0;
31
33
34 inline rclcpp::Node::SharedPtr & getNode() { return node_; }
35
36 inline rclcpp::Logger getLogger() { return *logger_; }
37
38 virtual std::string getClassName();
39
40 template <typename TOrthogonal, typename TBehavior, typename... Args>
41 std::shared_ptr<TBehavior> configure(Args &&... args);
42
43 template <typename SmaccComponentType>
44 void requiresComponent(SmaccComponentType *& storage);
45
46 template <typename SmaccClientType>
47 void requiresClient(SmaccClientType *& storage);
48
49 template <typename T>
50 bool getGlobalSMData(std::string name, T & ret);
51
52 // Store globally in this state machine. (By value parameter )
53 template <typename T>
54 void setGlobalSMData(std::string name, T value);
55
56 template <
57 typename TStateReactor, typename TTriggerEvent, typename TEventList, typename... TEvArgs>
58 std::shared_ptr<TStateReactor> createStateReactor(TEvArgs... args);
59
60 template <typename TStateReactor, typename... TEvArgs>
61 std::shared_ptr<TStateReactor> createStateReactor(TEvArgs... args);
62
63 template <typename TEventGenerator, typename... TEvArgs>
64 std::shared_ptr<TEventGenerator> createEventGenerator(TEvArgs... args);
65
66 template <typename EventType>
67 void postEvent(const EventType & ev);
68
69 template <typename EventType>
70 void postEvent();
71
72 // used for transition logging
73 template <typename TransitionType>
74 void notifyTransition();
75
76 // used for transition logging
78 std::shared_ptr<smacc2::introspection::TypeInfo> & transitionTypeInfo);
79
80 inline std::vector<std::shared_ptr<StateReactor>> & getStateReactors() { return stateReactors_; }
81
82 inline std::vector<std::shared_ptr<SmaccEventGenerator>> & getEventGenerators()
83 {
84 return eventGenerators_;
85 }
86
87 template <typename TOrthogonal>
88 TOrthogonal * getOrthogonal();
89
90 template <typename TEventGenerator>
91 TEventGenerator * getEventGenerator();
92
93 template <typename TStateReactor>
94 TStateReactor * getStateReactor();
95
96protected:
97 rclcpp::Node::SharedPtr node_;
98 std::shared_ptr<rclcpp::Logger> logger_;
99 std::vector<std::shared_ptr<StateReactor>> stateReactors_;
100 std::vector<std::shared_ptr<smacc2::SmaccEventGenerator>> eventGenerators_;
101
103
105};
106} // namespace smacc2
std::shared_ptr< rclcpp::Logger > logger_
Definition: smacc_state.hpp:98
rclcpp::Logger getLogger()
Definition: smacc_state.hpp:36
std::shared_ptr< TEventGenerator > createEventGenerator(TEvArgs... args)
ISmaccState * getParentState()
Definition: smacc_state.hpp:32
std::vector< std::shared_ptr< StateReactor > > stateReactors_
Definition: smacc_state.hpp:99
bool getGlobalSMData(std::string name, T &ret)
std::shared_ptr< TBehavior > configure(Args &&... args)
rclcpp::Node::SharedPtr node_
Definition: smacc_state.hpp:97
virtual std::string getClassName()
Definition: smacc_state.cpp:26
ISmaccState * parentState_
void requiresClient(SmaccClientType *&storage)
virtual std::string getName()=0
std::shared_ptr< TStateReactor > createStateReactor(TEvArgs... args)
std::vector< std::shared_ptr< StateReactor > > & getStateReactors()
Definition: smacc_state.hpp:80
TOrthogonal * getOrthogonal()
void requiresComponent(SmaccComponentType *&storage)
TStateReactor * getStateReactor()
std::vector< std::shared_ptr< SmaccEventGenerator > > & getEventGenerators()
Definition: smacc_state.hpp:82
virtual ISmaccStateMachine & getStateMachine()=0
std::vector< std::shared_ptr< smacc2::SmaccEventGenerator > > eventGenerators_
void setGlobalSMData(std::string name, T value)
const smacc2::introspection::SmaccStateInfo * stateInfo_
rclcpp::Node::SharedPtr & getNode()
Definition: smacc_state.hpp:34
TEventGenerator * getEventGenerator()
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)
Definition: smacc_state.cpp:28