SMACC2
Loading...
Searching...
No Matches
smacc_orthogonal.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
21#pragma once
22#include <smacc2/common.hpp>
23#include <utility>
24
25namespace smacc2
26{
28{
29public:
31
33
34 void initState(ISmaccState * state);
35
36 void addClientBehavior(std::shared_ptr<smacc2::ISmaccClientBehavior> clientBehavior);
37
38 void runtimeConfigure();
39
40 void onEntry();
41
42 void onExit();
43
44 void onDispose();
45
46 virtual std::string getName() const;
47
48 template <typename SmaccComponentType>
49 void requiresComponent(SmaccComponentType *& storage);
50
51 template <typename SmaccClientType>
52 bool requiresClient(SmaccClientType *& storage);
53
54 inline const std::vector<std::shared_ptr<smacc2::ISmaccClient>> & getClients();
55
56 inline const std::vector<std::vector<std::shared_ptr<smacc2::ISmaccClientBehavior>>> &
57 getClientBehaviors() const;
58
59 template <typename T>
60 void setGlobalSMData(std::string name, T value);
61
62 template <typename T>
63 bool getGlobalSMData(std::string name, T & ret);
64
65 // returns a client behavior of a given type. If the client behavior is not found, it returns nullptr
66 // the index parameter is used to specify the client behavior in case there are more than one
67 template <typename TClientBehavior>
68 TClientBehavior * getClientBehavior(int index = 0);
69
70 rclcpp::Node::SharedPtr getNode();
71 inline rclcpp::Logger getLogger() { return getNode()->get_logger(); }
72
73protected:
74 virtual void onInitialize();
75
76 void initializeClients();
77
78 template <typename TOrthogonal, typename TClient>
79 void assignClientToOrthogonal(TClient * client);
80
81 std::vector<std::shared_ptr<smacc2::ISmaccClient>> clients_;
82
83private:
85
86 std::vector<std::vector<std::shared_ptr<smacc2::ISmaccClientBehavior>>> clientBehaviors_;
87 friend class ISmaccStateMachine;
88
89 std::mutex mutex_;
90};
91
92} // namespace smacc2
ISmaccStateMachine * getStateMachine()
void setStateMachine(ISmaccStateMachine *value)
Definition: orthogonal.cpp:32
void setGlobalSMData(std::string name, T value)
bool getGlobalSMData(std::string name, T &ret)
virtual void onInitialize()
Definition: orthogonal.cpp:71
void requiresComponent(SmaccComponentType *&storage)
void addClientBehavior(std::shared_ptr< smacc2::ISmaccClientBehavior > clientBehavior)
Definition: orthogonal.cpp:49
std::vector< std::shared_ptr< smacc2::ISmaccClient > > clients_
void initState(ISmaccState *state)
Definition: orthogonal.cpp:73
ISmaccStateMachine * stateMachine_
bool requiresClient(SmaccClientType *&storage)
void assignClientToOrthogonal(TClient *client)
std::vector< std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > > clientBehaviors_
virtual std::string getName() const
Definition: orthogonal.cpp:81
rclcpp::Node::SharedPtr getNode()
Definition: orthogonal.cpp:47
const std::vector< std::vector< std::shared_ptr< smacc2::ISmaccClientBehavior > > > & getClientBehaviors() const
TClientBehavior * getClientBehavior(int index=0)
const std::vector< std::shared_ptr< smacc2::ISmaccClient > > & getClients()