SMACC2
Loading...
Searching...
No Matches
smacc_client_behavior_base.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
21#pragma once
22
23#include <functional>
24#include <string>
25
26#include <string>
27
28#include <smacc2/common.hpp>
29
30namespace smacc2
31{
32
34{
35public:
37
38 virtual ~ISmaccClientBehavior();
39
40 // Not copyable or movable. This turns an accidental copy, such as a missing & in
41 // "auto & cb = *behavior;", into a compile error instead of calls on a detached copy.
46
48
49 std::string getName() const;
50
51 template <typename SmaccClientType>
52 void requiresClient(SmaccClientType *& storage);
53
54 template <typename SmaccComponentType>
56 SmaccComponentType *& storage,
58
59 // named variant: resolves the component instance created with this name
60 // (e.g. createComponent<CpActionClient<Spin>>("/spin")), for clients holding
61 // several components of the same type
62 template <typename SmaccComponentType>
64 const std::string & name, SmaccComponentType *& storage,
66
67 virtual void onEntry() {}
68
69 virtual void onExit() {}
70
71 //internal visibility (private + friend)
72 virtual void executeOnEntry();
73
74 //internal visibility (private + friend)
75 virtual void executeOnExit();
76
77protected:
78 virtual void runtimeConfigure();
79
80 template <typename EventType>
81 void postEvent(const EventType & ev);
82
83 template <typename EventType>
84 void postEvent();
85
87
88 // Posts EvCbInitializationFailure for this behavior; the core calls it when user code throws.
89 void postInitializationFailureEvent(const std::string & what);
90
91 virtual void dispose();
92
93 virtual rclcpp::Node::SharedPtr getNode() const;
94
95 virtual rclcpp::Logger getLogger() const;
96
97 // The state and orthogonal names the tracepoints carry. Call on the state machine thread only.
98 std::string getTraceStateName() const;
99 std::string getTraceOrthogonalName() const;
100
101private:
102 template <typename TOrthogonal, typename TSourceObject>
104
105 // Set by ISmaccState::configure, which knows the behavior's and the orthogonal's types.
106 std::function<void(const std::string &)> postInitializationFailureEventFn_;
107
108 // a reference to the owner state machine
110
111 // a reference to the state where the client behavior is being executed
114
115 friend class ISmaccState;
116 friend class ISmaccOrthogonal;
118};
119} // namespace smacc2
smacc2::ISmaccOrthogonal * currentOrthogonal
ISmaccClientBehavior & operator=(ISmaccClientBehavior &&)=delete
ISmaccClientBehavior(ISmaccClientBehavior &&)=delete
virtual rclcpp::Logger getLogger() const
void postInitializationFailureEvent(const std::string &what)
virtual rclcpp::Node::SharedPtr getNode() const
ISmaccClientBehavior(const ISmaccClientBehavior &)=delete
std::function< void(const std::string &)> postInitializationFailureEventFn_
ISmaccClientBehavior & operator=(const ISmaccClientBehavior &)=delete
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
ComponentRequirement
Definition common.hpp:82