![]() |
IRSOL
C++ code implementing socket server for interacting with Baumer camera.
|
Binds incoming protocol messages to the appropriate per-client logic. More...
#include <message_handler.hpp>
Public Member Functions | |
| 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. | |
| template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant< T, irsol::protocol::InMessage >::value, int > = 0> | |
| bool | registerHandler (const std::string &identifier, handler_function_t< T > handler) |
| Registers a user-defined handler for a specific message type and identifier. | |
Private Member Functions | |
| std::optional< any_handler_function_t > | findHandlerForMessage (const protocol::InMessage &msg) const |
| Locates a registered handler (of any message type) for a given message. | |
| template<typename T , std::enable_if_t< irsol::traits::is_type_in_variant< T, irsol::protocol::InMessage >::value, int > = 0> | |
| std::optional< handler_function_t< T > > | findHandler (const handler_identifier_t &identifier) const |
| Locates a handler of a specific message type and identifier. | |
Private Attributes | |
| assignment_message_handler_map_t | m_assignmentMessageHandlers {} |
Registered handlers for Assignment messages, keyed by identifier. | |
| 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. | |
Binds incoming protocol messages to the appropriate per-client logic.
This class acts as a central dispatcher used by the application layer irsol::server::App to process structured incoming messages irsol::protocol::InMessage. Each message is handled by a user-registered callback function based on its type and identifier.
Messages are categorized into three types:
For each type, client-specific logic is registered using registerHandler(). When a message arrives, handle() invokes the matching callback and returns the generated response messages to be sent back to the client.
Definition at line 52 of file message_handler.hpp.
|
private |
Definition at line 72 of file message_handler.hpp.
|
private |
Definition at line 61 of file message_handler.hpp.
|
private |
Definition at line 68 of file message_handler.hpp.
|
private |
Definition at line 63 of file message_handler.hpp.
|
private |
Definition at line 70 of file message_handler.hpp.
|
private |
Definition at line 58 of file message_handler.hpp.
|
private |
Definition at line 55 of file message_handler.hpp.
|
private |
Definition at line 54 of file message_handler.hpp.
|
private |
Definition at line 62 of file message_handler.hpp.
|
private |
Definition at line 69 of file message_handler.hpp.
|
private |
Definition at line 66 of file message_handler.hpp.
|
inlineprivate |
Locates a handler of a specific message type and identifier.
| T | Message type (Assignment, Inquiry, or Command). |
| identifier | Identifier of the message to match. |
std::nullopt if no handler is registered. Definition at line 160 of file message_handler.hpp.
|
private |
Locates a registered handler (of any message type) for a given message.
| msg | The message whose identifier and type are used for lookup. |
std::variant, or std::nullopt if not found. Definition at line 42 of file message_handler.cpp.
| MessageHandler::handling_function_response_t irsol::server::handlers::MessageHandler::handle | ( | const irsol::types::client_id_t & | clientId, |
| protocol::InMessage && | message | ||
| ) | const |
Dispatches an incoming message to the correct user-defined handler.
This method extracts the message type and identifier from the parsed InMessage, then finds the corresponding callback registered via registerHandler(). The appropriate handler is invoked with the clientId and the message payload.
| clientId | Unique identifier of the client sending the message. |
| message | The parsed incoming message to handle. |
OutMessage responses to be sent back to the client. Definition at line 11 of file message_handler.cpp.
|
inline |
Registers a user-defined handler for a specific message type and identifier.
Handlers must be registered per message identifier (e.g., "start_stream", "set_param"), and per message kind (Assignment, Inquiry, Command). Duplicate registrations are rejected.
| T | One of protocol::Assignment, protocol::Inquiry, or protocol::Command. |
| identifier | The string identifier of the message (e.g., the name field). |
| handler | A callable accepting (client_id_t, T&&) and returning response messages. |
true if the handler was successfully registered, false if a duplicate exists. Definition at line 106 of file message_handler.hpp.
|
private |
Registered handlers for Assignment messages, keyed by identifier.
Definition at line 178 of file message_handler.hpp.
|
private |
Registered handlers for Command messages, keyed by identifier.
Definition at line 184 of file message_handler.hpp.
|
private |
Registered handlers for Inquiry messages, keyed by identifier.
Definition at line 181 of file message_handler.hpp.