17#define PROGRAM_NAME "message-handlers-demo"
27 :
irsol::server::handlers::AssignmentHandler(
ctx)
32 std::vector<irsol::server::handlers::out_message_t>
operator()(
36 return process(
nullptr, std::move(message));
40 std::vector<irsol::server::handlers::out_message_t>
process(
44 IRSOL_LOG_INFO(
"[MyAssignmentHandler] Called with {}.", message.toString());
49 std::vector<irsol::server::handlers::out_message_t>
result;
60 std::shared_ptr<irsol::server::handlers::Context> ctx =
nullptr;
77 auto fooResult = msgHandler.
handle(clientId, std::move(fooMsg));
79 for(
const auto&
msg : fooResult) {
86 auto unknownResult = msgHandler.
handle(clientId, std::move(unknownMsg));
88 for(
const auto&
msg : unknownResult) {
Example custom handler for Assignment messages.
std::vector< irsol::server::handlers::out_message_t > process(IRSOL_MAYBE_UNUSED std::shared_ptr< irsol::server::ClientSession > client, irsol::protocol::Assignment &&message) override
std::vector< irsol::server::handlers::out_message_t > operator()(IRSOL_MAYBE_UNUSED const irsol::types::client_id_t &clientId, irsol::protocol::Assignment &&message) override
MyAssignmentHandler(std::shared_ptr< irsol::server::handlers::Context > ctx)
Binds incoming protocol messages to the appropriate per-client logic.
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.
bool registerHandler(const std::string &identifier, handler_function_t< T > handler)
Registers a user-defined handler for a specific message type and identifier.
Generic handler base class for protocol messages.
std::shared_ptr< Context > ctx
Handler context (provides access to app and utilities).
const std::string getProgramName()
Returns the program name, typically used for logging. If PROGRAM_NAME is not defined at compile time,...
void demoHandlers()
Demonstrates handler creation, registration, and dispatch.
void initAssertHandler()
Initializes the assertion handler system.
#define IRSOL_LOG_INFO(...)
Logs an info-level message using the default logger.
void initLogging(const char *fileSinkFilename="logs/irsol.log", std::optional< spdlog::level::level_enum > minLogLevel=std::nullopt)
Initializes the irsol logging system.
std::string toString(const InMessage &msg)
Converts an incoming message variant to a human-readable string.
#define IRSOL_MAYBE_UNUSED
Suppresses compiler warnings about unused variables or parameters.
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.
std::string uuid()
Generates a new UUID string.
Represents an assignment operation in the protocol.
std::string toString() const
Converts the assignment to a human-readable string.
static Success from(const Assignment &msg, std::optional< irsol::types::protocol_value_t > overrideValue=std::nullopt)
Creates a success message from an Assignment.