REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
registry.h
Go to the documentation of this file.
1// Copyright (c) 2023 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#ifdef ARDUINO
8
9#include <ArduinoJson.h>
10#include <map>
11#include <string>
12
13#include "carrier/carrier.h"
14#include "handler.h"
15#include "net/auth.h"
16#include "utils/singleton.h"
17
18namespace msg {
19
20namespace handlers {
21
30class DynamicRegistry : public utils::HeapSingleton<DynamicRegistry> {
31 struct RegistryEntry { // "named tuple"
32 MessageHandler *handler;
34 };
35
36 std::map<std::string, RegistryEntry> entries;
37
38 int result_code_counter = 1, result_code_increment = 100;
39
40public:
41 MessageHandler *lookup(const std::string &msg_type);
42 net::auth::SecurityLevel requiredClearance(const std::string &msg_type);
43
44 bool set(const std::string &msg_type, MessageHandler *handler, net::auth::SecurityLevel minimumClearance);
45 bool set(const std::string &msg_type, int result_code_prefix, MessageHandler *handler,
46 net::auth::SecurityLevel minimumClearance);
47
48 void dump(); //< for debugging: Print Registry configuration to Serial
49 void write_handler_names_to(JsonArray &target);
50
51 void init(carrier::Carrier &c);
52};
53
55
56} // namespace handlers
57
58} // namespace msg
59
60#endif // ARDUINO
Top-level hierarchy controlled by a single microcontroller.
Definition carrier.h:38
The Message Registry holds the list of all known message types.
Definition registry.h:30
bool set(const std::string &msg_type, MessageHandler *handler, net::auth::SecurityLevel minimumClearance)
Definition registry.cpp:97
void init(carrier::Carrier &c)
Actual registration of all handlers in code.
Definition registry.cpp:23
net::auth::SecurityLevel requiredClearance(const std::string &msg_type)
Definition registry.cpp:87
void write_handler_names_to(JsonArray &target)
for structured output
Definition registry.cpp:136
MessageHandler * lookup(const std::string &msg_type)
Returns nullptr if not found.
Definition registry.cpp:77
A MessageHandler is a functor/closure like event handler.
Definition handler.h:21
Define singletons which are not static-space allocated (and thus consume valuable ICTM space).
Definition singleton.h:46
Definition carrier.h:12
SecurityLevel
Simple security levels for the message handlers.
Definition auth.h:35