IRSOL
C++ code implementing socket server for interacting with Baumer camera.
irsol::server::handlers::LambdaHandler< T, > Class Template Reference

Handler class that delegates protocol message processing to a lambda or callable. More...

#include <lambda_handler.hpp>

Inheritance diagram for irsol::server::handlers::LambdaHandler< T, >:
irsol::server::handlers::internal::HandlerBase< T, >

Public Types

using lambda_function_t = std::function< std::vector< out_message_t >(std::shared_ptr< Context >, std::shared_ptr< irsol::server::ClientSession >, T &&)>
 

Public Member Functions

 LambdaHandler (std::shared_ptr< irsol::server::handlers::Context > ctx, lambda_function_t callback)
 Constructs a LambdaHandler with the given context and callback.
 
- Public Member Functions inherited from irsol::server::handlers::internal::HandlerBase< T, >
virtual std::vector< out_message_toperator() (const irsol::types::client_id_t &clientId, T &&message)
 Invokes the handler for a given client and message.
 

Protected Member Functions

std::vector< out_message_tprocess (std::shared_ptr< irsol::server::ClientSession > session, T &&message) final override
 Processes the protocol message by invoking the stored lambda/callable.
 
- Protected Member Functions inherited from irsol::server::handlers::internal::HandlerBase< T, >
 HandlerBase (std::shared_ptr< Context > ctx)
 Constructs the handler base.
 

Private Attributes

lambda_function_t m_callback
 The lambda or callable to invoke for each message.
 

Additional Inherited Members

- Protected Attributes inherited from irsol::server::handlers::internal::HandlerBase< T, >
std::shared_ptr< Contextctx
 Handler context (provides access to app and utilities).
 

Detailed Description

template<typename T, std::enable_if_t< irsol::traits::is_type_in_variant< T, irsol::protocol::InMessage >::value, int > = 0>
class irsol::server::handlers::LambdaHandler< T, >

Handler class that delegates protocol message processing to a lambda or callable.

Template Parameters
TProtocol message type (Assignment, Inquiry, Command).

LambdaHandler enables protocol message handlers to be implemented as lambda functions or other callable objects, rather than requiring a dedicated handler class.

The lambda receives the handler context, the client session pointer, and the protocol message.

Definition at line 62 of file lambda_handler.hpp.

Member Typedef Documentation

◆ lambda_function_t

using irsol::server::handlers::LambdaHandler< T, >::lambda_function_t = std::function<std::vector< out_message_t>(std::shared_ptr<Context>, std::shared_ptr<irsol::server::ClientSession>, T&&)>

Definition at line 65 of file lambda_handler.hpp.

Constructor & Destructor Documentation

◆ LambdaHandler()

irsol::server::handlers::LambdaHandler< T, >::LambdaHandler ( std::shared_ptr< irsol::server::handlers::Context ctx,
lambda_function_t  callback 
)
inline

Constructs a LambdaHandler with the given context and callback.

Parameters
ctxHandler context.
callbackLambda or callable to invoke for each message.

Definition at line 73 of file lambda_handler.hpp.

74 : internal::HandlerBase<T>(ctx), m_callback(callback)
75 {}
lambda_function_t m_callback
The lambda or callable to invoke for each message.
std::shared_ptr< Context > ctx
Handler context (provides access to app and utilities).
Definition base.hpp:81
constexpr auto makeHandler(std::shared_ptr< Context > ctx, Args &&... args)
Constructs a handler instance of the given type.
Definition factory.hpp:28

Member Function Documentation

◆ process()

std::vector< out_message_t > irsol::server::handlers::LambdaHandler< T, >::process ( std::shared_ptr< irsol::server::ClientSession session,
T &&  message 
)
inlinefinaloverrideprotectedvirtual

Processes the protocol message by invoking the stored lambda/callable.

Parameters
sessionThe client session.
messageThe protocol message.
Returns
Vector of outbound messages (success or error).

Implements irsol::server::handlers::internal::HandlerBase< T, >.

Definition at line 84 of file lambda_handler.hpp.

87 {
88 return m_callback(this->ctx, session, std::move(message));
89 }

Member Data Documentation

◆ m_callback

The lambda or callable to invoke for each message.

Definition at line 93 of file lambda_handler.hpp.


The documentation for this class was generated from the following file: