SMACC2
Loading...
Searching...
No Matches
cl_lifecycle_node::CpLifecycleStateTracker Class Reference

Component that tracks the current lifecycle state. More...

#include <cp_lifecycle_state_tracker.hpp>

Inheritance diagram for cl_lifecycle_node::CpLifecycleStateTracker:
Inheritance graph
Collaboration diagram for cl_lifecycle_node::CpLifecycleStateTracker:
Collaboration graph

Public Member Functions

 CpLifecycleStateTracker ()=default
 
virtual ~CpLifecycleStateTracker ()=default
 
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.
 
std::optional< std::string > getCurrentStateLabel () const
 Get the current state label as string.
 
uint8_t getCurrentStateId () const
 Get the current state ID.
 
void onInitialize () override
 Component initialization.
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Private Attributes

std::optional< lifecycle_msgs::msg::State > currentState_
 
std::mutex stateMutex_
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
template<typename TOrthogonal , typename TClient >
void onComponentInitialization ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TComponent >
void requiresComponent (std::string name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger () const
 
ISmaccStateMachinegetStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Component that tracks the current lifecycle state.

CpLifecycleStateTracker maintains knowledge of the current lifecycle node state, providing thread-safe query methods for state information.

Definition at line 33 of file cp_lifecycle_state_tracker.hpp.

Constructor & Destructor Documentation

◆ CpLifecycleStateTracker()

cl_lifecycle_node::CpLifecycleStateTracker::CpLifecycleStateTracker ( )
default

◆ ~CpLifecycleStateTracker()

virtual cl_lifecycle_node::CpLifecycleStateTracker::~CpLifecycleStateTracker ( )
virtualdefault

Member Function Documentation

◆ getCurrentState()

std::optional< lifecycle_msgs::msg::State > cl_lifecycle_node::CpLifecycleStateTracker::getCurrentState ( ) const

Get the current lifecycle state.

Returns
Optional state (empty if not yet initialized)

Definition at line 34 of file cp_lifecycle_state_tracker.cpp.

35{
36 std::lock_guard<std::mutex> lock(stateMutex_);
37 return currentState_;
38}
std::optional< lifecycle_msgs::msg::State > currentState_

References currentState_, and stateMutex_.

◆ getCurrentStateId()

uint8_t cl_lifecycle_node::CpLifecycleStateTracker::getCurrentStateId ( ) const

Get the current state ID.

Returns
State ID (0 if not yet initialized)

Definition at line 50 of file cp_lifecycle_state_tracker.cpp.

51{
52 std::lock_guard<std::mutex> lock(stateMutex_);
53 if (currentState_)
54 {
55 return currentState_->id;
56 }
57 return 0;
58}

References currentState_, and stateMutex_.

◆ getCurrentStateLabel()

std::optional< std::string > cl_lifecycle_node::CpLifecycleStateTracker::getCurrentStateLabel ( ) const

Get the current state label as string.

Returns
Optional state label (empty if not yet initialized)

Definition at line 40 of file cp_lifecycle_state_tracker.cpp.

41{
42 std::lock_guard<std::mutex> lock(stateMutex_);
43 if (currentState_)
44 {
45 return currentState_->label;
46 }
47 return std::nullopt;
48}

References currentState_, and stateMutex_.

◆ onInitialize()

void cl_lifecycle_node::CpLifecycleStateTracker::onInitialize ( )
overridevirtual

Component initialization.

Reimplemented from smacc2::ISmaccComponent.

Definition at line 19 of file cp_lifecycle_state_tracker.cpp.

20{
21 // Initialize with empty state
22 RCLCPP_INFO(getLogger(), "[CpLifecycleStateTracker] Component initialized");
23}
rclcpp::Logger getLogger() const

References smacc2::ISmaccComponent::getLogger().

Here is the call graph for this function:

◆ updateState()

void cl_lifecycle_node::CpLifecycleStateTracker::updateState ( const lifecycle_msgs::msg::State & state)

Update the current state.

Parameters
stateNew lifecycle state

Definition at line 25 of file cp_lifecycle_state_tracker.cpp.

26{
27 std::lock_guard<std::mutex> lock(stateMutex_);
28 currentState_ = state;
29 RCLCPP_DEBUG(
30 getLogger(), "[CpLifecycleStateTracker] State updated to: %s (id: %d)", state.label.c_str(),
31 state.id);
32}

References currentState_, smacc2::ISmaccComponent::getLogger(), and stateMutex_.

Here is the call graph for this function:

Member Data Documentation

◆ currentState_

std::optional<lifecycle_msgs::msg::State> cl_lifecycle_node::CpLifecycleStateTracker::currentState_
private

◆ stateMutex_

std::mutex cl_lifecycle_node::CpLifecycleStateTracker::stateMutex_
mutableprivate

The documentation for this class was generated from the following files: