|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Thread-safe lifecycle state management for network components. More...
#include <lifecycle_manager.h>

Public Member Functions | |
| lifecycle_manager ()=default | |
| Default constructor. | |
| ~lifecycle_manager ()=default | |
| Destructor. | |
| lifecycle_manager (const lifecycle_manager &)=delete | |
| lifecycle_manager & | operator= (const lifecycle_manager &)=delete |
| lifecycle_manager (lifecycle_manager &&other) noexcept | |
| lifecycle_manager & | operator= (lifecycle_manager &&other) noexcept |
| auto | is_running () const -> bool |
| Checks if the component is currently running. | |
| auto | try_start () -> bool |
| Attempts to transition from stopped to running state. | |
| auto | set_running () -> void |
| Marks the component as running. | |
| auto | mark_stopped () -> void |
| Marks the component as stopped and signals waiters. | |
| auto | wait_for_stop () -> void |
| Blocks until the component has stopped. | |
| auto | prepare_stop () -> bool |
| Prepares for stop operation. | |
| auto | reset () -> void |
| Resets the lifecycle manager to initial state. | |
Private Attributes | |
| std::atomic< bool > | is_running_ {false} |
| std::atomic< bool > | stop_initiated_ {false} |
| std::optional< std::promise< void > > | stop_promise_ |
| std::future< void > | stop_future_ |
Thread-safe lifecycle state management for network components.
This utility class encapsulates the common lifecycle management logic that was previously duplicated across all CRTP base classes. It handles:
All methods are thread-safe and use atomic operations for state changes.
Definition at line 65 of file lifecycle_manager.h.
|
default |
Default constructor.
|
default |
Destructor.
|
delete |
|
inlinenoexcept |
Definition at line 83 of file lifecycle_manager.h.
|
inlinenodiscard |
Checks if the component is currently running.
Definition at line 114 of file lifecycle_manager.h.
References is_running_.
Referenced by kcenon::network::utils::startable_base< Derived >::do_stop(), kcenon::network::core::messaging_quic_client::is_running(), kcenon::network::core::messaging_quic_server::is_running(), kcenon::network::core::messaging_udp_client::is_running(), kcenon::network::core::messaging_udp_server::is_running(), kcenon::network::core::messaging_ws_client::is_running(), kcenon::network::core::messaging_ws_server::is_running(), kcenon::network::core::secure_messaging_client::is_running(), kcenon::network::core::secure_messaging_server::is_running(), kcenon::network::core::secure_messaging_udp_client::is_running(), kcenon::network::utils::startable_base< Derived >::is_running(), kcenon::network::core::messaging_quic_client::~messaging_quic_client(), kcenon::network::core::messaging_quic_server::~messaging_quic_server(), kcenon::network::core::messaging_udp_client::~messaging_udp_client(), kcenon::network::core::messaging_udp_server::~messaging_udp_server(), kcenon::network::core::messaging_ws_client::~messaging_ws_client(), kcenon::network::core::messaging_ws_server::~messaging_ws_server(), kcenon::network::core::secure_messaging_client::~secure_messaging_client(), kcenon::network::core::secure_messaging_server::~secure_messaging_server(), and kcenon::network::core::secure_messaging_udp_client::~secure_messaging_udp_client().

|
inline |
Marks the component as stopped and signals waiters.
This method:
Definition at line 152 of file lifecycle_manager.h.
References is_running_, stop_initiated_, and stop_promise_.
Referenced by kcenon::network::utils::startable_base< Derived >::do_start(), and kcenon::network::utils::startable_base< Derived >::do_stop().

|
delete |
|
inlinenoexcept |
Definition at line 93 of file lifecycle_manager.h.
References is_running_, stop_future_, stop_initiated_, and stop_promise_.
|
inlinenodiscard |
Prepares for stop operation.
This method:
Definition at line 186 of file lifecycle_manager.h.
References is_running_, stop_future_, stop_initiated_, and stop_promise_.
|
inline |
Resets the lifecycle manager to initial state.
Use this to prepare for reuse after a stop operation.
Definition at line 214 of file lifecycle_manager.h.
References is_running_, stop_future_, stop_initiated_, and stop_promise_.
|
inline |
Marks the component as running.
Use this when you need to set running state without the atomic check (e.g., after successful initialization).
Definition at line 139 of file lifecycle_manager.h.
References is_running_.
|
inlinenodiscard |
Attempts to transition from stopped to running state.
This method uses compare-and-exchange to ensure only one caller can successfully start the component.
Definition at line 126 of file lifecycle_manager.h.
References is_running_.
Referenced by kcenon::network::utils::startable_base< Derived >::do_start().

|
inline |
Blocks until the component has stopped.
If prepare_stop() was called, this will block until mark_stopped() is called. Returns immediately if no stop is in progress.
Definition at line 169 of file lifecycle_manager.h.
References stop_future_.
Referenced by kcenon::network::utils::startable_base< Derived >::wait_for_stop().

|
private |
Definition at line 223 of file lifecycle_manager.h.
Referenced by is_running(), mark_stopped(), operator=(), prepare_stop(), reset(), set_running(), and try_start().
|
private |
Definition at line 226 of file lifecycle_manager.h.
Referenced by operator=(), prepare_stop(), reset(), and wait_for_stop().
|
private |
Definition at line 224 of file lifecycle_manager.h.
Referenced by mark_stopped(), operator=(), prepare_stop(), and reset().
|
private |
Definition at line 225 of file lifecycle_manager.h.
Referenced by mark_stopped(), operator=(), prepare_stop(), and reset().