SMACC2
Loading...
Searching...
No Matches
cb_deactivate_on_exit.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:
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 onExit() override
52 {
53 // Runs on this behavior's onExit thread; the wait ends on the response, on a finish request
54 // or on ROS shutdown. A rejection is logged by the client; the state is already leaving, so
55 // nothing is posted here.
56 lifecycleNodeClient_->deactivate([this]() { return this->isShutdownRequested(); });
57 }
58
60 {
61 RCLCPP_INFO(getLogger(), "[CbDeactivateOnExit] Deactivate transition succeeded");
62 this->postSuccessEvent();
63 }
64
66 {
67 RCLCPP_WARN(getLogger(), "[CbDeactivateOnExit] Deactivate transition failed or errored");
68 this->postFailureEvent();
69 }
70
71private:
74};
75} // namespace cl_lifecycle_node
bool deactivate(const CancelPredicate &cancelled=CancelPredicate())
Component that monitors ROS2 lifecycle node transition events.
smacc2::SmaccSignalConnection onTransitionOnDeactivateSuccess(void(T::*callback)(), T *object)
smacc2::SmaccSignalConnection onTransitionOnDeactivateFailure(void(T::*callback)(), T *object)
smacc2::SmaccSignalConnection onTransitionOnDeactivateError(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...