SMACC2
Loading...
Searching...
No Matches
smacc_client_behavior_impl.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 <type_traits>
24
27
28namespace smacc2
29{
30template <typename EventType>
31void ISmaccClientBehavior::postEvent(const EventType & ev)
32{
33 if (stateMachine_ == nullptr)
34 {
35 RCLCPP_ERROR(
36 getLogger(),
37 "The client behavior cannot post events before being assigned to an orthogonal. Ignoring "
38 "post event call.");
39 // A raw event pointer is ours to free (EventType deduces to the pointer type): adopt it and let it go.
40 if constexpr (std::is_pointer_v<EventType>)
41 {
42 boost::intrusive_ptr<std::remove_pointer_t<EventType>> discarded(ev);
43 }
44 }
45 else
46 {
48 }
49}
50
51template <typename EventType>
53{
54 if (stateMachine_ == nullptr)
55 {
56 RCLCPP_ERROR(
57 getLogger(),
58 "The client behavior cannot post events before being assigned to an orthogonal. Ignoring "
59 "post event call.");
60 }
61 else
62 {
64 }
65}
66
67//inline
69
70//inline
72
73template <typename SmaccClientType>
74void ISmaccClientBehavior::requiresClient(SmaccClientType *& storage)
75{
77}
78
79template <typename SmaccComponentType>
81 SmaccComponentType *& storage, ComponentRequirement requirementType)
82{
83 if (stateMachine_ == nullptr)
84 {
85 RCLCPP_ERROR(
86 getLogger(),
87 "Cannot use the requiresComponent functionality before assigning the client behavior to an "
88 "orthogonal. Try using the OnEntry method to capture required components.");
89 }
90 else
91 {
92 stateMachine_->requiresComponent(storage, requirementType, currentOrthogonal);
93 }
94}
95
96template <typename SmaccComponentType>
98 const std::string & name, SmaccComponentType *& storage, ComponentRequirement requirementType)
99{
100 if (stateMachine_ == nullptr)
101 {
102 RCLCPP_ERROR(
103 getLogger(),
104 "Cannot use the requiresComponent functionality before assigning the client behavior to an "
105 "orthogonal. Try using the OnEntry method to capture required components.");
106 }
107 else
108 {
109 stateMachine_->requiresComponent(name, storage, requirementType, currentOrthogonal);
110 }
111}
112
113template <typename TOrthogonal, typename TSourceObject>
117
118} // namespace smacc2
smacc2::ISmaccOrthogonal * currentOrthogonal
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
bool requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType, ISmaccOrthogonal *first=nullptr)
void postEvent(EventType *ev, EventLifeTime evlifetime=EventLifeTime::ABSOLUTE)
ComponentRequirement
Definition common.hpp:82