IRSOL
C++ code implementing socket server for interacting with Baumer camera.
assignment_image_size.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include "irsol/macros.hpp"
13#include "irsol/server/app.hpp"
15#include "irsol/types.hpp"
16#include "irsol/utils.hpp"
17
18#include <string_view>
19namespace irsol {
20namespace server {
21namespace handlers {
22namespace internal {
23
28{
29 static constexpr std::string_view name = "OffsetX";
30};
31
36{
37 static constexpr std::string_view name = "Width";
38};
39
44{
45 static constexpr std::string_view name = "OffsetY";
46};
47
52{
53 static constexpr std::string_view name = "Height";
54};
55
63template<typename AssignmentCameraImageAttribute>
65{
66 static constexpr std::string_view name = AssignmentCameraImageAttribute::name;
67
68public:
73 AssignmentImgHandlerBase(std::shared_ptr<Context> ctx): AssignmentHandler(ctx) {}
74
75protected:
82 std::vector<out_message_t> process(
83 IRSOL_MAYBE_UNUSED std::shared_ptr<irsol::server::ClientSession> session,
84 protocol::Assignment&& message) final override
85 {
86 auto& cam = ctx->app.camera();
87 auto resValue = cam.setParam(std::string(name), irsol::utils::toInt(message.value));
88 std::vector<out_message_t> result;
89
90 // Update the message value with the resulting value after setting the camera parameter.
91 // In this way, the resulting value is included in the response message that we broadcast to all
92 // clients.
94 ctx->broadcastMessage(protocol::Success::from(message));
95 return {};
96 }
97};
98} // namespace internal
99
120
121} // namespace handlers
122} // namespace server
123} // namespace irsol
Main server application managing client connections and camera streaming.
Base handler templates for protocol message processing.
Base handler template for assigning a camera image region parameter.
std::vector< out_message_t > process(IRSOL_MAYBE_UNUSED std::shared_ptr< irsol::server::ClientSession > session, protocol::Assignment &&message) final override
Processes an assignment message to set the camera image parameter.
AssignmentImgHandlerBase(std::shared_ptr< Context > ctx)
Constructs the handler.
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
Common portability and diagnostic macros for the irsol library.
#define IRSOL_MAYBE_UNUSED
Suppresses compiler warnings about unused variables or parameters.
Definition macros.hpp:39
constexpr auto makeHandler(std::shared_ptr< Context > ctx, Args &&... args)
Constructs a handler instance of the given type.
Definition factory.hpp:28
std::variant< int, double, std::string > protocol_value_t
Variant type representing protocol values that can be one of several types.
Definition types.hpp:150
int toInt(const irsol::types::protocol_value_t &x)
Converts a protocol value to an integer.
Definition utils.hpp:39
Represents an assignment operation in the protocol.
static Success from(const Assignment &msg, std::optional< irsol::types::protocol_value_t > overrideValue=std::nullopt)
Creates a success message from an Assignment.
Definition success.hpp:75
Tag type for the camera image height parameter ("Height").
Tag type for the camera image left offset parameter ("OffsetX").
Tag type for the camera image top offset parameter ("OffsetY").
Tag type for the camera image width parameter ("Width").
auto result
Core type definitions for networking, time handling, and protocol values used throughout the irsol li...
General utility functions used throughout the irsol library.