SMACC2
Loading...
Searching...
No Matches
component.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
22#include <string>
23
24#include <boost/optional.hpp>
25#include <smacc2/common.hpp>
26
27namespace smacc2
28{
30{
31public:
33
34 virtual ~ISmaccComponent();
35
36 // Returns a custom identifier defined by the specific plugin implementation
37 virtual std::string getName() const;
38
39protected:
40 // this is the basic initialization method that each specific component should
41 // implement. The owner and the node are already available when it is invoked by the client.
42 virtual void onInitialize();
43
44 // component initialization with type information of the orthogonal and client that owns it
45 template <typename TOrthogonal, typename TClient>
47
48 template <typename EventType>
49 void postEvent(const EventType & ev);
50
51 template <typename EventType>
52 void postEvent();
53
54 template <typename TOrthogonal, typename TSourceObject>
55 [[deprecated(
56 "Use onStateOrthogonalAllocation instead. onOrthogonalAllocation will be removed in future "
57 "versions.")]] void
61
62 // New method: called when the component is allocated to a state (replaces onOrthogonalAllocation)
63 template <typename TOrthogonal, typename TSourceObject>
67
68 template <typename TComponent>
69 [[deprecated(
70 "Use requiresComponent with ComponentRequirement argument instead. This method will be removed "
71 "in future "
72 "versions.")]] void
73 requiresComponent(TComponent *& requiredComponentStorage, bool throwExceptionIfNotExist);
74
75 template <typename TComponent>
76 [[deprecated(
77 "Use requiresComponent with ComponentRequirement argument instead. This method will be removed "
78 "in future "
79 "versions.")]] void
81 std::string name, TComponent *& requiredComponentStorage, bool throwExceptionIfNotExist);
82
83 template <typename TComponent>
85 TComponent *& requiredComponentStorage,
87
88 template <typename TComponent>
90 std::string name, TComponent *& requiredComponentStorage,
92
93 template <typename TClient>
94 void requiresClient(TClient *& requiredClientStorage);
95
96 template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
97 SmaccComponentType * createSiblingComponent(TArgs... targs);
98
99 template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
100 SmaccComponentType * createSiblingNamedComponent(std::string name, TArgs... targs);
101
102 rclcpp::Node::SharedPtr getNode();
103
104 rclcpp::Logger getLogger() const;
105
106 //inline
108
109 // A reference to the state machine object that owns this resource
111
113
114private:
115 // friend method invoked by the client.
116 void initialize(ISmaccClient * owner);
117
118 // friend method invoked by the client.
119 // Assigns the owner of this resource to the given state machine parameter object
120 void setStateMachine(ISmaccStateMachine * stateMachine);
121
122 friend class ISmaccOrthogonal;
123 friend class ISmaccClient;
124};
125} // namespace smacc2
ISmaccClient * owner_
ISmaccStateMachine * getStateMachine()
void requiresClient(TClient *&requiredClientStorage)
SmaccComponentType * createSiblingComponent(TArgs... targs)
SmaccComponentType * createSiblingNamedComponent(std::string name, TArgs... targs)
virtual std::string getName() const
void initialize(ISmaccClient *owner)
rclcpp::Logger getLogger() const
ISmaccStateMachine * stateMachine_
rclcpp::Node::SharedPtr getNode()
void requiresComponent(TComponent *&requiredComponentStorage, bool throwExceptionIfNotExist)
void setStateMachine(ISmaccStateMachine *stateMachine)
ComponentRequirement
Definition common.hpp:75