mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-13 17:17:40 +00:00
Hide implementation of MessageHandlerMap.
This commit is contained in:
@@ -184,10 +184,7 @@ private:
|
|||||||
while( !shared_memory.application_queue.is_empty() ) {
|
while( !shared_memory.application_queue.is_empty() ) {
|
||||||
auto message = shared_memory.application_queue.pop();
|
auto message = shared_memory.application_queue.pop();
|
||||||
|
|
||||||
auto& fn = context.message_map[message->id];
|
context.message_map.send(message);
|
||||||
if( fn ) {
|
|
||||||
fn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
message->state = Message::State::Free;
|
message->state = Message::State::Free;
|
||||||
}
|
}
|
||||||
|
@@ -26,13 +26,15 @@
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void Audio::on_show() {
|
void Audio::on_show() {
|
||||||
context().message_map[Message::ID::AudioStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::AudioStatistics,
|
||||||
|
[this](const Message* const p) {
|
||||||
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::on_hide() {
|
void Audio::on_hide() {
|
||||||
context().message_map[Message::ID::AudioStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::AudioStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::paint(Painter& painter) {
|
void Audio::paint(Painter& painter) {
|
||||||
|
@@ -26,13 +26,15 @@
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void Channel::on_show() {
|
void Channel::on_show() {
|
||||||
context().message_map[Message::ID::ChannelStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::ChannelStatistics,
|
||||||
|
[this](const Message* const p) {
|
||||||
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::on_hide() {
|
void Channel::on_hide() {
|
||||||
context().message_map[Message::ID::ChannelStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::ChannelStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Channel::paint(Painter& painter) {
|
void Channel::paint(Painter& painter) {
|
||||||
|
@@ -40,13 +40,15 @@ BasebandStatsView::BasebandStatsView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BasebandStatsView::on_show() {
|
void BasebandStatsView::on_show() {
|
||||||
context().message_map[Message::ID::BasebandStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::BasebandStatistics,
|
||||||
|
[this](const Message* const p) {
|
||||||
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasebandStatsView::on_hide() {
|
void BasebandStatsView::on_hide() {
|
||||||
context().message_map[Message::ID::BasebandStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::BasebandStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -481,14 +481,16 @@ ReceiverView::ReceiverView(
|
|||||||
|
|
||||||
receiver_model.enable();
|
receiver_model.enable();
|
||||||
|
|
||||||
context().message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
context().message_map.register_handler(Message::ID::FSKPacket,
|
||||||
|
[](const Message* const p) {
|
||||||
const auto message = static_cast<const FSKPacketMessage*>(p);
|
const auto message = static_cast<const FSKPacketMessage*>(p);
|
||||||
(void)message;
|
(void)message;
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiverView::~ReceiverView() {
|
ReceiverView::~ReceiverView() {
|
||||||
context().message_map[Message::ID::FSKPacket] = nullptr;
|
context().message_map.unregister_handler(Message::ID::FSKPacket);
|
||||||
|
|
||||||
// TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do
|
// TODO: Manipulating audio codec here, and in ui_receiver.cpp. Good to do
|
||||||
// both?
|
// both?
|
||||||
|
@@ -26,13 +26,15 @@
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
void RSSI::on_show() {
|
void RSSI::on_show() {
|
||||||
context().message_map[Message::ID::RSSIStatistics] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::RSSIStatistics,
|
||||||
|
[this](const Message* const p) {
|
||||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSI::on_hide() {
|
void RSSI::on_hide() {
|
||||||
context().message_map[Message::ID::RSSIStatistics] = nullptr;
|
context().message_map.unregister_handler(Message::ID::RSSIStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSSI::paint(Painter& painter) {
|
void RSSI::paint(Painter& painter) {
|
||||||
|
@@ -233,13 +233,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void on_show() override {
|
void on_show() override {
|
||||||
context().message_map[Message::ID::ChannelSpectrum] = [this](const Message* const p) {
|
context().message_map.register_handler(Message::ID::ChannelSpectrum,
|
||||||
|
[this](const Message* const p) {
|
||||||
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_hide() override {
|
void on_hide() override {
|
||||||
context().message_map[Message::ID::ChannelSpectrum] = nullptr;
|
context().message_map.unregister_handler(Message::ID::ChannelSpectrum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_parent_rect(const Rect new_parent_rect) override {
|
void set_parent_rect(const Rect new_parent_rect) override {
|
||||||
|
@@ -481,14 +481,16 @@ public:
|
|||||||
MessageHandlerMap& message_handlers
|
MessageHandlerMap& message_handlers
|
||||||
) : message_handlers(message_handlers)
|
) : message_handlers(message_handlers)
|
||||||
{
|
{
|
||||||
message_handlers[Message::ID::FSKConfiguration] = [this](const Message* const p) {
|
message_handlers.register_handler(Message::ID::FSKConfiguration,
|
||||||
|
[this](const Message* const p) {
|
||||||
auto m = reinterpret_cast<const FSKConfigurationMessage*>(p);
|
auto m = reinterpret_cast<const FSKConfigurationMessage*>(p);
|
||||||
this->configure(m->configuration);
|
this->configure(m->configuration);
|
||||||
};
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
~FSKProcessor() {
|
~FSKProcessor() {
|
||||||
message_handlers[Message::ID::FSKConfiguration] = nullptr;
|
message_handlers.unregister_handler(Message::ID::FSKConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
void configure(const FSKConfiguration new_configuration) {
|
void configure(const FSKConfiguration new_configuration) {
|
||||||
@@ -736,10 +738,7 @@ private:
|
|||||||
while( !shared_memory.baseband_queue.is_empty() ) {
|
while( !shared_memory.baseband_queue.is_empty() ) {
|
||||||
auto message = shared_memory.baseband_queue.pop();
|
auto message = shared_memory.baseband_queue.pop();
|
||||||
|
|
||||||
auto& fn = message_map[message->id];
|
message_map.send(message);
|
||||||
if( fn ) {
|
|
||||||
fn(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
message->state = Message::State::Free;
|
message->state = Message::State::Free;
|
||||||
}
|
}
|
||||||
@@ -804,7 +803,8 @@ int main(void) {
|
|||||||
EventDispatcher event_dispatcher;
|
EventDispatcher event_dispatcher;
|
||||||
auto& message_handlers = event_dispatcher.message_handlers();
|
auto& message_handlers = event_dispatcher.message_handlers();
|
||||||
|
|
||||||
message_handlers[Message::ID::BasebandConfiguration] = [&message_handlers](const Message* const p) {
|
message_handlers.register_handler(Message::ID::BasebandConfiguration,
|
||||||
|
[&message_handlers](const Message* const p) {
|
||||||
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
||||||
if( message->configuration.mode != baseband_configuration.mode ) {
|
if( message->configuration.mode != baseband_configuration.mode ) {
|
||||||
|
|
||||||
@@ -846,7 +846,8 @@ int main(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
baseband_configuration = message->configuration;
|
baseband_configuration = message->configuration;
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
||||||
|
|
||||||
|
@@ -246,12 +246,19 @@ class MessageHandlerMap {
|
|||||||
public:
|
public:
|
||||||
using MessageHandler = std::function<void(const Message* const p)>;
|
using MessageHandler = std::function<void(const Message* const p)>;
|
||||||
|
|
||||||
MessageHandler& operator[](Message::ID n) {
|
void register_handler(const Message::ID id, MessageHandler&& handler) {
|
||||||
return map_[toUType(n)];
|
map_[toUType(id)] = std::move(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
const MessageHandler& operator[](Message::ID n) const {
|
void unregister_handler(const Message::ID id) {
|
||||||
return map_[toUType(n)];
|
map_[toUType(id)] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(const Message* const message) {
|
||||||
|
auto& fn = map_[toUType(message->id)];
|
||||||
|
if( fn ) {
|
||||||
|
fn(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Reference in New Issue
Block a user