27#include <unordered_map>
73 variant<assignment_handler_function_t, inquiry_handler_function_t, command_handler_function_t>;
104 std::enable_if_t<irsol::traits::is_type_in_variant<T, irsol::protocol::InMessage>::value,
int> =
110 if constexpr(std::is_same_v<T, protocol::Assignment>) {
112 "Duplicate handler registered for identifier '{}' and Assignment type", identifier);
113 }
else if constexpr(std::is_same_v<T, protocol::Inquiry>) {
115 "Duplicate handler registered for identifier '{}' and Inquiry type", identifier);
116 }
else if constexpr(std::is_same_v<T, protocol::Command>) {
118 "Duplicate handler registered for identifier '{}' and Command type", identifier);
126 if constexpr(std::is_same_v<T, protocol::Assignment>) {
127 IRSOL_LOG_INFO(
"Registering handler for 'Assignment(\"{}\")'", identifier);
129 }
else if constexpr(std::is_same_v<T, protocol::Inquiry>) {
130 IRSOL_LOG_INFO(
"Registering handler for 'Inquiry(\"{}\")'", identifier);
132 }
else if constexpr(std::is_same_v<T, protocol::Command>) {
133 IRSOL_LOG_INFO(
"Registering handler for 'Command(\"{}\")'", identifier);
158 std::enable_if_t<irsol::traits::is_type_in_variant<T, irsol::protocol::InMessage>::value,
int> =
162 if constexpr(std::is_same_v<T, protocol::Assignment>) {
165 : std::make_optional(
it->second);
166 }
else if constexpr(std::is_same_v<T, protocol::Inquiry>) {
169 }
else if constexpr(std::is_same_v<T, protocol::Command>) {
Binds incoming protocol messages to the appropriate per-client logic.
std::function< handling_function_response_t(const irsol::types::client_id_t &, T &&)> handler_function_t
handler_function_t< protocol::Assignment && > assignment_handler_function_t
handler_function_t< protocol::Inquiry && > inquiry_handler_function_t
handler_function_t< protocol::Command && > command_handler_function_t
handling_function_response_t handle(const irsol::types::client_id_t &clientId, protocol::InMessage &&message) const
Dispatches an incoming message to the correct user-defined handler.
assignment_message_handler_map_t m_assignmentMessageHandlers
Registered handlers for Assignment messages, keyed by identifier.
std::optional< handler_function_t< T > > findHandler(const handler_identifier_t &identifier) const
Locates a handler of a specific message type and identifier.
bool registerHandler(const std::string &identifier, handler_function_t< T > handler)
Registers a user-defined handler for a specific message type and identifier.
std::string handler_identifier_t
std::optional< any_handler_function_t > findHandlerForMessage(const protocol::InMessage &msg) const
Locates a registered handler (of any message type) for a given message.
inquiry_message_handler_map_t m_inquiryMessageHandlers
Registered handlers for Inquiry messages, keyed by identifier.
command_message_handler_map_t m_commandMessageHandlers
Registered handlers for Command messages, keyed by identifier.
std::variant< assignment_handler_function_t, inquiry_handler_function_t, command_handler_function_t > any_handler_function_t
message_handler_map_t< inquiry_handler_function_t > inquiry_message_handler_map_t
message_handler_map_t< command_handler_function_t > command_message_handler_map_t
message_handler_map_t< assignment_handler_function_t > assignment_message_handler_map_t
std::unordered_map< handler_identifier_t, T > message_handler_map_t
std::vector< protocol::OutMessage > handling_function_response_t
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
#define IRSOL_LOG_ERROR(...)
Logs an error-level message using the default logger.
std::variant< Assignment, Inquiry, Command > InMessage
Variant type representing any incoming message.
Common portability and diagnostic macros for the irsol library.
#define IRSOL_MISSING_TEMPLATE_SPECIALIZATION(T, funcNameLiteral)
Emits a compile-time error when no template specialization is available.
constexpr auto makeHandler(std::shared_ptr< Context > ctx, Args &&... args)
Constructs a handler instance of the given type.
std::string client_id_t
Represents a unique client identifier. Typically used to identify connected clients by string IDs.
Template metaprogramming traits for type introspection in the irsol library.
Core type definitions for networking, time handling, and protocol values used throughout the irsol li...