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