IRSOL
C++ code implementing socket server for interacting with Baumer camera.
assignment_frame_rate.cpp
Go to the documentation of this file.
2
4#include "irsol/utils.hpp"
5
6namespace irsol {
7namespace server {
8namespace handlers {
12
13std::vector<out_message_t>
15 std::shared_ptr<irsol::server::ClientSession> session,
17{
18 auto& frameListeningState = session->userData().frameListeningState;
19 if(frameListeningState.running()) {
21 session->id(), "Session is already listening to frames. Cannot set a frameRate.");
22 std::vector<out_message_t> result;
24 message, "Session is already listening to frames. Cannot set a frameRate."));
25 return result;
26 }
27 const double frameRate = irsol::utils::toDouble(message.value);
28 if(frameRate <= 0) {
29 IRSOL_NAMED_LOG_WARN(session->id(), "frameRate ({}) must be positive.", frameRate);
30 std::vector<out_message_t> result;
31 result.emplace_back(irsol::protocol::Error::from(message, "frameRate must be positive."));
32 return result;
33 }
34 IRSOL_NAMED_LOG_INFO(session->id(), "Setting 'frameRate' to {}", frameRate);
35
36 frameListeningState.gisParams.frameRate = frameRate;
37 std::vector<out_message_t> result;
39 return result;
40}
41} // namespace handlers
42} // namespace server
43} // namespace irsol
Declaration of the AssignmentFrameRateHandler class.
std::vector< out_message_t > process(std::shared_ptr< irsol::server::ClientSession > session, protocol::Assignment &&message) final override
Processes an assignment message to set the frame rate.
AssignmentFrameRateHandler(std::shared_ptr< Context > ctx)
Constructs the AssignmentFrameRateHandler.
Generic handler base class for protocol messages.
Definition base.hpp:39
#define IRSOL_NAMED_LOG_INFO(name,...)
Logs an info-level message using a named logger.
Definition logging.hpp:176
#define IRSOL_NAMED_LOG_WARN(name,...)
Logs a warning-level message using a named logger.
Definition logging.hpp:178
constexpr auto makeHandler(std::shared_ptr< Context > ctx, Args &&... args)
Constructs a handler instance of the given type.
Definition factory.hpp:28
double toDouble(const irsol::types::protocol_value_t &x)
Converts a protocol value to a double.
Definition utils.hpp:55
Declaration of the ClientSession class.
Represents an assignment operation in the protocol.
static Error from(const T &msg, const std::string &description)
Creates an error from a specific incoming message type.
Definition error.hpp:63
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
auto result
General utility functions used throughout the irsol library.