IRSOL
C++ code implementing socket server for interacting with Baumer camera.
lambda_handler.hpp File Reference

Declaration of the LambdaHandler class for protocol message handling. More...

Go to the source code of this file.

Classes

class  irsol::server::handlers::LambdaHandler< T, >
 Handler class that delegates protocol message processing to a lambda or callable. More...
 

Namespaces

namespace  irsol
 
namespace  irsol::server
 Core server features. TOBE DEFINED FURTHER.
 
namespace  irsol::server::handlers
 Contains all logic for dispatching and implementing protocol message handlers.
 

Detailed Description

Declaration of the LambdaHandler class for protocol message handling.

Defines the irsol::server::handlers::LambdaHandler class, which allows protocol message handlers to be implemented as lambda functions or other callable objects.

When to use LambdaHandler

LambdaHandler is ideal for situations where:

  • You want to quickly implement a handler for a protocol message without creating a new class.
  • The handler logic is simple, stateless, or only used in a specific context.
  • You want to register handlers dynamically at runtime, e.g., for testing, scripting, or plugin systems.
  • You wish to encapsulate handler logic inline, close to where the handler is registered.

LambdaHandler is especially useful for:

  • Prototyping new protocol features.
  • Writing one-off or ad-hoc handlers for custom commands.
  • Unit/integration testing with mock handlers.
  • Reducing boilerplate for trivial handlers.

Example usage:

ctx->registerLambdaHandler<protocol::Command>(
"my_custom_cmd",
ctx,
[](handlers::Context& ctx, const irsol::types::client_id_t& clientId, protocol::Command&& cmd)
{
// Custom logic here
std::vector<out_message_t> result;
result.emplace_back(protocol::Success::from(cmd));
return result;
);
std::string client_id_t
Represents a unique client identifier. Typically used to identify connected clients by string IDs.
Definition types.hpp:55
auto result

Definition in file lambda_handler.hpp.