SMACC2
Loading...
Searching...
No Matches
cp_lifecycle_state_tracker.hpp
Go to the documentation of this file.
1// Copyright 2024 RobosoftAI 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#pragma once
16
17#include <smacc2/component.hpp>
18
19#include <lifecycle_msgs/msg/state.hpp>
20
21#include <mutex>
22#include <optional>
23#include <string>
24
25namespace cl_lifecycle_node
26{
34{
35public:
37 virtual ~CpLifecycleStateTracker() = default;
38
43 void updateState(const lifecycle_msgs::msg::State & state);
44
49 std::optional<lifecycle_msgs::msg::State> getCurrentState() const;
50
55 std::optional<std::string> getCurrentStateLabel() const;
56
61 uint8_t getCurrentStateId() const;
62
66 void onInitialize() override;
67
68private:
69 std::optional<lifecycle_msgs::msg::State> currentState_;
70 mutable std::mutex stateMutex_;
71};
72
73} // namespace cl_lifecycle_node
Component that tracks the current lifecycle state.
std::optional< lifecycle_msgs::msg::State > currentState_
void onInitialize() override
Component initialization.
void updateState(const lifecycle_msgs::msg::State &state)
Update the current state.
std::optional< lifecycle_msgs::msg::State > getCurrentState() const
Get the current lifecycle state.
uint8_t getCurrentStateId() const
Get the current state ID.
std::optional< std::string > getCurrentStateLabel() const
Get the current state label as string.