IRSOL
C++ code implementing socket server for interacting with Baumer camera.
lambda_handler.hpp
Go to the documentation of this file.
1
39#pragma once
40
42#include "irsol/traits.hpp"
43
44namespace irsol {
45namespace server {
46namespace handlers {
47
58template<
59 typename T,
60 std::enable_if_t<irsol::traits::is_type_in_variant<T, irsol::protocol::InMessage>::value, int> =
61 0>
63{
64public:
65 using lambda_function_t = std::function<std::vector<
66 out_message_t>(std::shared_ptr<Context>, std::shared_ptr<irsol::server::ClientSession>, T&&)>;
67
73 LambdaHandler(std::shared_ptr<irsol::server::handlers::Context> ctx, lambda_function_t callback)
74 : internal::HandlerBase<T>(ctx), m_callback(callback)
75 {}
76
77protected:
84 std::vector<out_message_t> process(
85 std::shared_ptr<irsol::server::ClientSession> session,
86 T&& message) final override
87 {
88 return m_callback(this->ctx, session, std::move(message));
89 }
90
91private:
94};
95
96}
97}
98}
Base handler templates for protocol message processing.
Handler class that delegates protocol message processing to a lambda or callable.
LambdaHandler(std::shared_ptr< irsol::server::handlers::Context > ctx, lambda_function_t callback)
Constructs a LambdaHandler with the given context and callback.
std::function< std::vector< out_message_t >(std::shared_ptr< Context >, std::shared_ptr< irsol::server::ClientSession >, T &&)> lambda_function_t
std::vector< out_message_t > process(std::shared_ptr< irsol::server::ClientSession > session, T &&message) final override
Processes the protocol message by invoking the stored lambda/callable.
lambda_function_t m_callback
The lambda or callable to invoke for each message.
Generic handler base class for protocol messages.
Definition base.hpp:39
std::shared_ptr< Context > ctx
Handler context (provides access to app and utilities).
Definition base.hpp:81
HandlerBase(std::shared_ptr< Context > ctx)
Constructs the handler base.
Definition base.hpp:68
protocol::OutMessage out_message_t
Definition base.hpp:23
constexpr auto makeHandler(std::shared_ptr< Context > ctx, Args &&... args)
Constructs a handler instance of the given type.
Definition factory.hpp:28
Template metaprogramming traits for type introspection in the irsol library.