SMACC2
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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 // Not copyable or movable. This turns an accidental copy, such as a missing & in
37 // "auto & cp = *component;", into a compile error instead of calls on a detached copy.
42
43 // Returns a custom identifier defined by the specific plugin implementation
44 virtual std::string getName() const;
45
46protected:
47 // this is the basic initialization method that each specific component should
48 // implement. The owner and the node are already available when it is invoked by the client.
49 virtual void onInitialize();
50
51 // component initialization with type information of the orthogonal and client that owns it
52 template <typename TOrthogonal, typename TClient>
54
55 template <typename EventType>
56 void postEvent(const EventType & ev);
57
58 template <typename EventType>
59 void postEvent();
60
61 template <typename TOrthogonal, typename TSourceObject>
65
66 template <typename TComponent>
68 TComponent *& requiredComponentStorage,
70
71 template <typename TComponent>
73 const std::string & name, TComponent *& requiredComponentStorage,
75
76 template <typename TClient>
77 void requiresClient(TClient *& requiredClientStorage);
78
79 template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
80 SmaccComponentType * createSiblingComponent(const TArgs &... targs);
81
82 template <typename SmaccComponentType, typename TOrthogonal, typename TClient, typename... TArgs>
83 SmaccComponentType * createSiblingNamedComponent(
84 const std::string & name, const TArgs &... targs);
85
86 rclcpp::Node::SharedPtr getNode();
87
88 rclcpp::Logger getLogger() const;
89
90 //inline
92
93 // A reference to the state machine object that owns this resource
95
96 ISmaccClient * owner_ = nullptr;
97
98private:
99 // friend method invoked by the client.
100 void initialize(ISmaccClient * owner);
101
102 // friend method invoked by the client.
103 // Assigns the owner of this resource to the given state machine parameter object
104 void setStateMachine(ISmaccStateMachine * stateMachine);
105
106 friend class ISmaccOrthogonal;
107 friend class ISmaccClient;
108};
109} // namespace smacc2
ISmaccClient * owner_
Definition component.hpp:96
ISmaccStateMachine * getStateMachine()
ISmaccComponent(const ISmaccComponent &)=delete
void requiresClient(TClient *&requiredClientStorage)
SmaccComponentType * createSiblingNamedComponent(const std::string &name, const TArgs &... targs)
SmaccComponentType * createSiblingComponent(const TArgs &... targs)
ISmaccComponent & operator=(const ISmaccComponent &)=delete
virtual std::string getName() const
void initialize(ISmaccClient *owner)
rclcpp::Logger getLogger() const
ISmaccComponent & operator=(ISmaccComponent &&)=delete
ISmaccStateMachine * stateMachine_
Definition component.hpp:94
void requiresComponent(TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
rclcpp::Node::SharedPtr getNode()
ISmaccComponent(ISmaccComponent &&)=delete
void setStateMachine(ISmaccStateMachine *stateMachine)
ComponentRequirement
Definition common.hpp:82