SMACC2
Loading...
Searching...
No Matches
cb_configure.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
26
27namespace cl_lifecycle_node
28{
30{
31public:
33 virtual ~CbConfigure() {}
34
35 template <typename TOrthogonal, typename TSourceObject>
37 {
39
42 // State-scoped signal connections, made on the state machine thread. Each is tracked by this
43 // behavior's address and finalized when the behavior is disposed at state exit, so a
44 // transition event that arrives after the exit cannot call into a destroyed behavior. The
45 // raw connect() calls this replaces were never disconnected (finding T).
49 }
50
51 virtual void onEntry() override
52 {
53 // Runs on this behavior's thread. The wait inside the client ends when the request is
54 // answered, when this behavior is asked to finish (state exit, shutdown) or when ROS shuts
55 // down. If the request was abandoned nothing is posted: the state is already leaving. If the
56 // node rejected it, no transition event will ever arrive for this attempt, so the behavior
57 // reports the failure itself.
58 const bool accepted =
59 lifecycleNodeClient_->configure([this]() { return this->isShutdownRequested(); });
60 if (!accepted && !this->isShutdownRequested())
61 {
62 this->postFailureEvent();
63 }
64 }
65
67 {
68 RCLCPP_INFO(getLogger(), "[CbConfigure] Configure transition succeeded");
69 this->postSuccessEvent();
70 }
71
73 {
74 RCLCPP_WARN(getLogger(), "[CbConfigure] Configure transition failed or errored");
75 this->postFailureEvent();
76 }
77
78private:
81};
82} // namespace cl_lifecycle_node
ClLifecycleNode * lifecycleNodeClient_
virtual void onEntry() override
CpLifecycleEventMonitor * eventMonitor_
bool configure(const CancelPredicate &cancelled=CancelPredicate())
Component that monitors ROS2 lifecycle node transition events.
smacc2::SmaccSignalConnection onTransitionOnConfigureFailure(void(T::*callback)(), T *object)
smacc2::SmaccSignalConnection onTransitionOnConfigureError(void(T::*callback)(), T *object)
smacc2::SmaccSignalConnection onTransitionOnConfigureSuccess(void(T::*callback)(), T *object)
virtual rclcpp::Logger getLogger() const
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
bool isShutdownRequested()
onEntry is executed in a new thread. However the current state cannot be left until the onEntry threa...