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 auto& updater = loader::Updater::get();
43 set(pb_Envelope_message_v1_tag, pb_MessageV1_update_command_tag, new UpdateHandler(updater));
44}
45
46static uint64_t kind2key(uint32_t envelope_kind, uint32_t message_kind) {
47 return static_cast<uint64_t>(envelope_kind) << 32 | message_kind;
48}
49
50FASTRUN
51msg::handlers::MessageHandler *msg::handlers::DynamicRegistry::lookup(uint32_t envelope_kind,
52 uint32_t message_kind) {
53 auto found = protobuf_entries.find(kind2key(envelope_kind, message_kind));
54 if (found == protobuf_entries.end())
55 return nullptr;
56
57 return found->second.handler;
58}
59
60bool msg::handlers::DynamicRegistry::set(uint32_t envelope_kind, uint32_t message_kind,
61 MessageHandler *handler) {
62 protobuf_entries.emplace(
63 kind2key(envelope_kind, message_kind),
64 RegistryEntry{handler}
65 );
66 return true;
67}
static uint64_t kind2key(uint32_t envelope_kind, uint32_t message_kind)
Definition registry.cpp:46