SMACC2
Loading...
Searching...
No Matches
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>
45
46 template <typename SmaccClientType>
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>
89
90 // gets the client behavior given the client type and orthogonal type
91 // if the client behavior is not found, it returns nullptr
92 // the index parameter is used to specify the client behavior in case there are more than one
93 template <typename TOrthogonal, typename TClientBehavior>
94 TClientBehavior * getClientBehavior(int index = 0);
95
96 template <typename TEventGenerator>
98
99 template <typename TStateReactor>
101
102protected:
103 rclcpp::Node::SharedPtr node_;
104 std::shared_ptr<rclcpp::Logger> logger_;
105 std::vector<std::shared_ptr<StateReactor>> stateReactors_;
106 std::vector<std::shared_ptr<smacc2::SmaccEventGenerator>> eventGenerators_;
107
109
111};
112} // namespace smacc2
std::shared_ptr< rclcpp::Logger > logger_
rclcpp::Logger getLogger()
TClientBehavior * getClientBehavior(int index=0)
std::shared_ptr< TEventGenerator > createEventGenerator(TEvArgs... args)
ISmaccState * getParentState()
std::vector< std::shared_ptr< StateReactor > > stateReactors_
bool getGlobalSMData(std::string name, T &ret)
std::shared_ptr< TBehavior > configure(Args &&... args)
rclcpp::Node::SharedPtr node_
virtual std::string getClassName()
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()
TOrthogonal * getOrthogonal()
void requiresComponent(SmaccComponentType *&storage)
TStateReactor * getStateReactor()
std::vector< std::shared_ptr< SmaccEventGenerator > > & getEventGenerators()
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()
TEventGenerator * getEventGenerator()
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)