REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
registry.cpp
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#include <proto/main.pb.h>
6#include "protocol/registry.h"
7
8#include "handlers/authenticate.h"
9#include "utils/logging.h"
10
11#include <handlers/carrier.h>
12#include <handlers/login_lock.h>
13#include <handlers/ping.h>
14#include <handlers/run_manager.h>
15#include <handlers/sys.h>
16#include <handlers/calibration.h>
17
18void msg::handlers::DynamicRegistry::init(carrier::Carrier &c) {
19 using namespace net::auth;
20 using namespace msg::handlers;
21
22 // Stateless protocol basics
23 set(pb_Envelope_generic_tag, pb_GenericMessage_ping_command_tag, new PingRequestHandler{});
24 //set("help", 200, new HelpHandler(), SecurityLevel::RequiresNothing);
25
26 // Carrier and RunManager things
27 set(pb_Envelope_message_v1_tag, pb_MessageV1_udp_data_streaming_command_tag, new UdpDataStreamingHandler());
28 set(pb_Envelope_message_v1_tag, pb_MessageV1_stand_by_command_tag, new StandByRequestHandler(c));
29 set(pb_Envelope_message_v1_tag, pb_MessageV1_reset_command_tag, new ResetRequestHandler(c));
30 set(pb_Envelope_message_v1_tag, pb_MessageV1_config_command_tag, new ConfigMessageHandler(c));
31 set(pb_Envelope_message_v1_tag, pb_MessageV1_extract_command_tag, new ExtractMessageHandler(c));
32 set(pb_Envelope_message_v1_tag, pb_MessageV1_describe_command_tag, new DescribeRequestHandler(c));
33 set(pb_Envelope_message_v1_tag, pb_MessageV1_register_external_entities_command_tag,
34 new RegisterExternalEntitiesRequestHandler());
35 set(pb_Envelope_message_v1_tag, pb_MessageV1_start_run_command_tag, new StartRunRequestHandler());
36 set(pb_Envelope_message_v1_tag, pb_MessageV1_stop_run_command_tag, new StopRunRequestHandler());
37
38 set(pb_Envelope_message_v1_tag, pb_MessageV1_read_temperature_command_tag, new ReadTemperaturesHandler(c));
39 set(pb_Envelope_message_v1_tag, pb_MessageV1_auth_request_tag, new AuthRequestHandler());
40
41 //TODO: remove or implement with protobuf
42 // manual hardware access
43 //set("manual_mode", 900, new ManualControlHandler(), SecurityLevel::RequiresNothing);
44 //set("overload_status", 1000, new GetOverloadStatusHandler(c), SecurityLevel::RequiresLogin);
45//
46 //set("net_get", 6000, new GetNetworkSettingsHandler(), SecurityLevel::RequiresAdmin);
47 //set("net_set", 6100, new SetNetworkSettingsHandler(), SecurityLevel::RequiresAdmin);
48 //set("net_reset", 6200, new ResetNetworkSettingsHandler(), SecurityLevel::RequiresAdmin);
49 //set("net_status", 6300, new NetworkStatusHandler(), SecurityLevel::RequiresNothing);
50 // ^ this net_status won't contain sensitive information...
51
52 // set("status", 3000, new GetSystemStatus(), SecurityLevel::RequiresNothing);
53 //set("login", 3100, new LoginHandler(), SecurityLevel::RequiresNothing);
54 //set("lock_acquire", 3200, new LockAcquire(), SecurityLevel::RequiresLogin);
55 //set("lock_release", 3300, new LockRelease(), SecurityLevel::RequiresLogin);
56
57 //set("sys_ident", 3400, new GetSystemIdent(), SecurityLevel::RequiresNothing);
58 //set("sys_reboot", 3500, new RebootHandler(), SecurityLevel::RequiresAdmin);
59 //set("sys_log", 3600, new SyslogHandler(), SecurityLevel::RequiresLogin);
60 //set("sys_stats", 3700, new SystemStats(), SecurityLevel::RequiresLogin);
61 //
62//
63 //set("load_plugin", 4100, new LoadPluginHandler(), SecurityLevel::RequiresAdmin);
64 //set("unload_plugin", 4200, new UnloadPluginHandler(), SecurityLevel::RequiresAdmin);
65//
66 //#ifdef ANABRID_WRITE_EEPROM
68 //set("sys_read_permanent", 4300, new ReadSystemIdent(), SecurityLevel::RequiresAdmin);
69 //set("sys_reset_permanent", 4400, new ResetSystemIdent(), SecurityLevel::RequiresAdmin);
70 //set("sys_write_permanent", 4500, new WriteSystemIdent(), SecurityLevel::RequiresAdmin);
71 //#endif
72//
73 //set("ota_update_status", 5000, new FlasherStatusHandler(), SecurityLevel::RequiresAdmin);
74 //set("ota_update_init", 5000, new FlasherInitHandler(), SecurityLevel::RequiresAdmin);
75 //set("ota_update_stream", 5100, new FlasherDataHandler(), SecurityLevel::RequiresAdmin);
76 //set("ota_update_abort", 5200, new FlasherAbortHandler(), SecurityLevel::RequiresAdmin);
77 //set("ota_update_complete", 5300, new FlasherCompleteHandler(), SecurityLevel::RequiresAdmin);
78}
79
80static uint64_t kind2key(uint32_t envelope_kind, uint32_t message_kind) {
81 return static_cast<uint64_t>(envelope_kind) << 32 | message_kind;
82}
83
84msg::handlers::MessageHandler *msg::handlers::DynamicRegistry::lookup(uint32_t envelope_kind,
85 uint32_t message_kind) {
86 auto found = protobuf_entries.find(kind2key(envelope_kind, message_kind));
87 if (found == protobuf_entries.end())
88 return nullptr;
89
90 return found->second.handler;
91}
92
93bool msg::handlers::DynamicRegistry::set(uint32_t envelope_kind, uint32_t message_kind,
94 MessageHandler *handler) {
95 protobuf_entries.emplace(
96 kind2key(envelope_kind, message_kind),
97 RegistryEntry{handler}
98 );
99 return true;
100}
uint32_t
Definition flasher.cpp:195
static uint64_t kind2key(uint32_t envelope_kind, uint32_t message_kind)
Definition registry.cpp:80