|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
Thread-safe callback storage and invocation utility. More...
#include <callback_manager.h>


Public Member Functions | |
| callback_manager ()=default | |
| Default constructor. | |
| ~callback_manager ()=default | |
| Destructor. | |
| callback_manager (const callback_manager &)=delete | |
| callback_manager & | operator= (const callback_manager &)=delete |
| callback_manager (callback_manager &&) noexcept=default | |
| callback_manager & | operator= (callback_manager &&) noexcept=default |
| template<std::size_t Index> | |
| auto | set (std::tuple_element_t< Index, std::tuple< CallbackTypes... > > callback) -> void |
| Sets a callback at the specified index. | |
| template<typename T > | |
| auto | set (T callback) -> void |
| Sets a callback by type. | |
| template<std::size_t Index> | |
| auto | get () const -> std::tuple_element_t< Index, std::tuple< CallbackTypes... > > |
| Gets a callback at the specified index. | |
| template<typename T > | |
| auto | get () const -> T |
| Gets a callback by type. | |
| template<std::size_t Index, typename... Args> | |
| auto | invoke (Args &&... args) -> void |
| Invokes a callback at the specified index if set. | |
| template<typename T , typename... Args> | |
| auto | invoke (Args &&... args) -> void |
| Invokes a callback by type if set. | |
| template<std::size_t Index, typename... Args> | |
| auto | invoke_if (bool condition, Args &&... args) -> void |
| Invokes a callback conditionally. | |
| auto | clear () -> void |
| Clears all callbacks. | |
| template<std::size_t Index> | |
| auto | clear () -> void |
| Clears a specific callback. | |
Private Attributes | |
| std::mutex | mutex_ |
| std::tuple< CallbackTypes... > | callbacks_ |
Thread-safe callback storage and invocation utility.
This template class provides a centralized way to store and invoke multiple callback types with thread safety. It replaces the repeated callback handling code in CRTP base classes.
| CallbackTypes | The callback function types to manage. |
Definition at line 61 of file callback_manager.h.
|
default |
Default constructor.
|
default |
Destructor.
|
delete |
|
defaultnoexcept |
|
inline |
Clears all callbacks.
Definition at line 183 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::callbacks_, and kcenon::network::utils::callback_manager< CallbackTypes >::mutex_.
|
inline |
Clears a specific callback.
| Index | The index of the callback to clear. |
Definition at line 194 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::callbacks_, and kcenon::network::utils::callback_manager< CallbackTypes >::mutex_.
|
inlinenodiscard |
Gets a callback at the specified index.
| Index | The index of the callback type. |
Definition at line 110 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::callbacks_, and kcenon::network::utils::callback_manager< CallbackTypes >::mutex_.
Referenced by kcenon::network::core::messaging_server::get_connection_callback(), kcenon::network::core::secure_messaging_server::get_connection_callback(), kcenon::network::core::messaging_server::get_disconnection_callback(), kcenon::network::core::secure_messaging_server::get_disconnection_callback(), kcenon::network::core::messaging_server::get_error_callback(), kcenon::network::core::messaging_udp_client::get_error_callback(), kcenon::network::core::messaging_udp_server::get_error_callback(), kcenon::network::core::secure_messaging_server::get_error_callback(), kcenon::network::core::messaging_server::get_receive_callback(), kcenon::network::core::messaging_udp_client::get_receive_callback(), kcenon::network::core::messaging_udp_server::get_receive_callback(), kcenon::network::core::secure_messaging_server::get_receive_callback(), and kcenon::network::utils::callback_manager< CallbackTypes >::invoke().

|
inlinenodiscard |
Gets a callback by type.
| T | The callback type. |
Definition at line 122 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::callbacks_, and kcenon::network::utils::callback_manager< CallbackTypes >::mutex_.
|
inline |
Invokes a callback at the specified index if set.
| Index | The index of the callback type. |
| Args | The argument types. |
| args | The arguments to pass to the callback. |
The callback is copied under lock, then invoked without lock. This prevents deadlocks if the callback triggers set() calls.
Definition at line 139 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::get().
Referenced by kcenon::network::utils::callback_manager< CallbackTypes >::invoke_if().


|
inline |
Invokes a callback by type if set.
| T | The callback type. |
| Args | The argument types. |
| args | The arguments to pass to the callback. |
Definition at line 155 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::get().

|
inline |
Invokes a callback conditionally.
| Index | The index of the callback type. |
| Args | The argument types. |
| condition | If false, the callback is not invoked. |
| args | The arguments to pass to the callback. |
Definition at line 172 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::invoke().

|
defaultnoexcept |
|
delete |
|
inline |
Sets a callback at the specified index.
| Index | The index of the callback type. |
| callback | The callback function to store. |
Definition at line 86 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::callbacks_, and kcenon::network::utils::callback_manager< CallbackTypes >::mutex_.
|
inline |
Sets a callback by type.
| T | The callback type (must be unique in CallbackTypes). |
| callback | The callback function to store. |
Definition at line 98 of file callback_manager.h.
References kcenon::network::utils::callback_manager< CallbackTypes >::callbacks_, and kcenon::network::utils::callback_manager< CallbackTypes >::mutex_.
|
private |
Definition at line 202 of file callback_manager.h.
Referenced by kcenon::network::utils::callback_manager< CallbackTypes >::clear(), kcenon::network::utils::callback_manager< CallbackTypes >::get(), kcenon::network::utils::callback_manager< CallbackTypes >::get(), kcenon::network::utils::callback_manager< CallbackTypes >::set(), and kcenon::network::utils::callback_manager< CallbackTypes >::set().
|
mutableprivate |
Definition at line 201 of file callback_manager.h.
Referenced by kcenon::network::utils::callback_manager< CallbackTypes >::clear(), kcenon::network::utils::callback_manager< CallbackTypes >::get(), kcenon::network::utils::callback_manager< CallbackTypes >::get(), kcenon::network::utils::callback_manager< CallbackTypes >::set(), and kcenon::network::utils::callback_manager< CallbackTypes >::set().