REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
handler.h
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
4
5#pragma once
6
7#include <ArduinoJson.h>
8
9// Forward declaration to avoid dependency
10namespace utils { struct StreamingJson; }
11namespace net { namespace auth { struct AuthentificationContext; }}
12
13namespace msg {
14
15namespace handlers {
16
22public:
23 constexpr static int not_implemented = -99;
24 constexpr static int success = 0;
25
32 constexpr int error(int internal_code) { return internal_code == success ? success : result_prefix + internal_code; }
33
42 virtual int handle(JsonObjectConst msg_in, JsonObject &msg_out) {
43 return not_implemented;
44 }
45
49 virtual int handle(JsonObjectConst msg_in, JsonObject &msg_out, net::auth::AuthentificationContext& user_context) {
50 return not_implemented;
51 }
52
56 virtual int handle(JsonObjectConst msg_in, utils::StreamingJson& msg_out) {
57 return not_implemented;
58 }
59
60};
61
62
63} // namespace handlers
64
65} // namespace msg
A MessageHandler is a functor/closure like event handler.
Definition handler.h:21
constexpr int error(int internal_code)
Definition handler.h:32
int result_prefix
Following the HRESULT idiom, this number is an assigned prefix by the registry.
Definition handler.h:31
static constexpr int not_implemented
Definition handler.h:23
static constexpr int success
Definition handler.h:24
virtual int handle(JsonObjectConst msg_in, utils::StreamingJson &msg_out)
Handler for streaming responses.
Definition handler.h:56
virtual int handle(JsonObjectConst msg_in, JsonObject &msg_out)
The actual handler method gets a message and returns a message next to the status code.
Definition handler.h:42
virtual int handle(JsonObjectConst msg_in, JsonObject &msg_out, net::auth::AuthentificationContext &user_context)
A handler variant that allows access to the authentification context of the client.
Definition handler.h:49
A thin wrapper around the username.
Definition auth.h:231
The Streaming JSON API provides a way of constructing (writing) JSON messages without RAM overhead.
Definition carrier.h:12
Definition auth.h:22