Radix Relay
Hybrid mesh communications with Signal Protocol encryption
Loading...
Searching...
No Matches
event_handler.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <core/events.hpp>
5#include <memory>
6#include <variant>
7
8namespace radix_relay::core {
9
20template<typename CommandHandler, typename CommandParser> struct event_handler
21{
23
25 {
26 std::shared_ptr<async::async_queue<events::display_filter_input_t>> display;
27 std::shared_ptr<async::async_queue<events::transport::in_t>> transport;
28 std::shared_ptr<async::async_queue<events::session_orchestrator::in_t>> session;
29 std::shared_ptr<async::async_queue<events::connection_monitor::in_t>> connection_monitor;
30 };
31
39 explicit event_handler(std::shared_ptr<CommandHandler> command_handler,
40 std::shared_ptr<CommandParser> parser,
41 const out_queues_t & /*queues*/)
42 : command_handler_(std::move(command_handler)), parser_(std::move(parser))
43 {}
44
52 auto handle(const events::raw_command &event) const -> void
53 {
54 auto command = parser_->parse(event.input);
55 std::visit(*command_handler_, command);
56 }
57
58private:
59 std::shared_ptr<CommandHandler> command_handler_;
60 std::shared_ptr<CommandParser> parser_;
61};
62
63}// namespace radix_relay::core
Thread-safe asynchronous queue for message passing between coroutines.
decltype(make_command_handler(std::declval< std::shared_ptr< Bridge > >(), std::declval< std::shared_ptr< async::async_queue< events::display_filter_input_t > > >(), std::declval< std::shared_ptr< async::async_queue< events::transport::in_t > > >(), std::declval< std::shared_ptr< async::async_queue< events::session_orchestrator::in_t > > >(), std::declval< std::shared_ptr< async::async_queue< events::connection_monitor::in_t > > >())) command_handler
std::shared_ptr< async::async_queue< events::session_orchestrator::in_t > > session
std::shared_ptr< async::async_queue< events::connection_monitor::in_t > > connection_monitor
std::shared_ptr< async::async_queue< events::display_filter_input_t > > display
std::shared_ptr< async::async_queue< events::transport::in_t > > transport
Dispatches parsed command events to the command handler.
auto handle(const events::raw_command &event) const -> void
Parses and handles a raw command string.
event_handler(std::shared_ptr< CommandHandler > command_handler, std::shared_ptr< CommandParser > parser, const out_queues_t &)
Constructs an event handler with command handler and parser.
Raw unparsed command input.
Definition events.hpp:142