ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
message_dispatcher Class Referencefinal

Dispatches incoming messages to registered subsystem handlers. More...

#include <message_dispatcher.hpp>

Collaboration diagram for message_dispatcher:
Collaboration graph

Public Member Functions

 message_dispatcher (std::shared_ptr< service::auth_session_service > sessions)
 Construct a message dispatcher with auth session service.
 
void register_handler (message_type_range range, std::shared_ptr< message_handler > handler)
 Register a handler for a range of message types.
 
boost::asio::awaitable< std::expected< frame, error_code > > dispatch (const frame &request_frame, std::uint32_t sequence, const std::string &remote_address, compression_type response_compression=compression_type::none)
 Dispatch a request frame to the appropriate handler.
 

Detailed Description

Dispatches incoming messages to registered subsystem handlers.

The dispatcher maintains a registry of message handlers for different message type ranges. When a message arrives, it routes it to the appropriate handler based on the message type, and converts the handler's response back into a frame.

Thread-safety: This class is not thread-safe. Registration should happen during initialization before concurrent access begins.

Constructor & Destructor Documentation

◆ message_dispatcher()

message_dispatcher ( std::shared_ptr< service::auth_session_service sessions)
explicit

Construct a message dispatcher with auth session service.

Parameters
sessionsShared auth session service for authorization

Member Function Documentation

◆ register_handler()

void register_handler ( message_type_range  range,
std::shared_ptr< message_handler handler 
)

Register a handler for a range of message types.

Parameters
rangeThe range of message types this handler processes
handlerThe handler implementation

Note: Ranges must not overlap. Behavior is undefined if overlapping ranges are registered.

◆ dispatch()

boost::asio::awaitable< std::expected< frame, error_code > > dispatch ( const frame request_frame,
std::uint32_t  sequence,
const std::string &  remote_address,
compression_type  response_compression = compression_type::none 
)

Dispatch a request frame to the appropriate handler.

Finds the registered handler for the message type, invokes it, and wraps the response payload in a frame with the appropriate response message type.

Parameters
request_frameThe incoming request frame
sequenceThe sequence number for the response frame
remote_addressThe remote endpoint address of the client connection
response_compressionCompression type to use for response frame
Returns
Expected containing response frame, or error_code if:
  • No handler is registered for this message type
  • Handler returns an error