Remove message_map from Context.

It doesn't belong in a display/rendering context object, it has much broader significance, mostly distributing messages via the M4->M0 IPC mechanism.
This commit is contained in:
Jared Boone 2016-01-13 15:46:04 -08:00
parent d380ffe52b
commit 9cab3c9978
12 changed files with 45 additions and 35 deletions

View File

@ -21,6 +21,8 @@
#include "ais_app.hpp" #include "ais_app.hpp"
#include "event_m0.hpp"
#include "string_format.hpp" #include "string_format.hpp"
#include "portapack.hpp" #include "portapack.hpp"
@ -116,8 +118,7 @@ namespace ui {
void AISView::on_show() { void AISView::on_show() {
View::on_show(); View::on_show();
auto& message_map = context().message_map(); EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
message_map.register_handler(Message::ID::AISPacket,
[this](Message* const p) { [this](Message* const p) {
const auto message = static_cast<const AISPacketMessage*>(p); const auto message = static_cast<const AISPacketMessage*>(p);
const ais::Packet packet { message->packet }; const ais::Packet packet { message->packet };
@ -129,8 +130,7 @@ void AISView::on_show() {
} }
void AISView::on_hide() { void AISView::on_hide() {
auto& message_map = context().message_map(); EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
message_map.unregister_handler(Message::ID::AISPacket);
View::on_hide(); View::on_hide();
} }

View File

@ -21,6 +21,8 @@
#include "ert_app.hpp" #include "ert_app.hpp"
#include "event_m0.hpp"
#include "portapack.hpp" #include "portapack.hpp"
using namespace portapack; using namespace portapack;
@ -54,8 +56,7 @@ namespace ui {
void ERTView::on_show() { void ERTView::on_show() {
Console::on_show(); Console::on_show();
auto& message_map = context().message_map(); EventDispatcher::message_map().register_handler(Message::ID::ERTPacket,
message_map.register_handler(Message::ID::ERTPacket,
[this](Message* const p) { [this](Message* const p) {
const auto message = static_cast<const ERTPacketMessage*>(p); const auto message = static_cast<const ERTPacketMessage*>(p);
const ert::Packet packet { message->type, message->packet }; const ert::Packet packet { message->type, message->packet };
@ -67,8 +68,7 @@ void ERTView::on_show() {
} }
void ERTView::on_hide() { void ERTView::on_hide() {
auto& message_map = context().message_map(); EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket);
message_map.unregister_handler(Message::ID::ERTPacket);
Console::on_hide(); Console::on_hide();
} }

View File

@ -54,6 +54,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
} }
MessageHandlerMap EventDispatcher::message_map_;
Thread* EventDispatcher::thread_event_loop = nullptr; Thread* EventDispatcher::thread_event_loop = nullptr;
EventDispatcher::EventDispatcher( EventDispatcher::EventDispatcher(
@ -118,7 +119,7 @@ void EventDispatcher::dispatch(const eventmask_t events) {
void EventDispatcher::handle_application_queue() { void EventDispatcher::handle_application_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer; std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = shared_memory.application_queue.pop(message_buffer)) { while(Message* const message = shared_memory.application_queue.pop(message_buffer)) {
context.message_map().send(message); message_map().send(message);
} }
} }
@ -172,7 +173,7 @@ void EventDispatcher::on_touch_event(ui::TouchEvent event) {
void EventDispatcher::handle_lcd_frame_sync() { void EventDispatcher::handle_lcd_frame_sync() {
DisplayFrameSyncMessage message; DisplayFrameSyncMessage message;
context.message_map().send(&message); message_map().send(&message);
painter.paint_widget_tree(top_widget); painter.paint_widget_tree(top_widget);
} }

View File

@ -27,6 +27,8 @@
#include "ui_widget.hpp" #include "ui_widget.hpp"
#include "ui_painter.hpp" #include "ui_painter.hpp"
#include "message.hpp"
#include "touch.hpp" #include "touch.hpp"
#include "ch.h" #include "ch.h"
@ -63,7 +65,12 @@ public:
} }
} }
static MessageHandlerMap& message_map() {
return message_map_;
}
private: private:
static MessageHandlerMap message_map_;
static Thread* thread_event_loop; static Thread* thread_event_loop;
touch::Manager touch_manager; touch::Manager touch_manager;

View File

@ -76,8 +76,7 @@ int main(void) {
ui::Painter painter; ui::Painter painter;
EventDispatcher event_dispatcher { &system_view, painter, context }; EventDispatcher event_dispatcher { &system_view, painter, context };
auto& message_handlers = context.message_map(); EventDispatcher::message_map().register_handler(Message::ID::Shutdown,
message_handlers.register_handler(Message::ID::Shutdown,
[&event_dispatcher](const Message* const) { [&event_dispatcher](const Message* const) {
event_dispatcher.request_stop(); event_dispatcher.request_stop();
} }

View File

@ -21,6 +21,8 @@
#include "tpms_app.hpp" #include "tpms_app.hpp"
#include "event_m0.hpp"
#include "portapack.hpp" #include "portapack.hpp"
using namespace portapack; using namespace portapack;
@ -58,8 +60,7 @@ namespace ui {
void TPMSView::on_show() { void TPMSView::on_show() {
Console::on_show(); Console::on_show();
auto& message_map = context().message_map(); EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket,
message_map.register_handler(Message::ID::TPMSPacket,
[this](Message* const p) { [this](Message* const p) {
const auto message = static_cast<const TPMSPacketMessage*>(p); const auto message = static_cast<const TPMSPacketMessage*>(p);
this->log(this->model.on_packet(*message)); this->log(this->model.on_packet(*message));
@ -68,8 +69,7 @@ void TPMSView::on_show() {
} }
void TPMSView::on_hide() { void TPMSView::on_hide() {
auto& message_map = context().message_map(); EventDispatcher::message_map().unregister_handler(Message::ID::TPMSPacket);
message_map.unregister_handler(Message::ID::TPMSPacket);
Console::on_hide(); Console::on_hide();
} }

View File

@ -21,12 +21,14 @@
#include "ui_audio.hpp" #include "ui_audio.hpp"
#include "event_m0.hpp"
#include <algorithm> #include <algorithm>
namespace ui { namespace ui {
void Audio::on_show() { void Audio::on_show() {
context().message_map().register_handler(Message::ID::AudioStatistics, EventDispatcher::message_map().register_handler(Message::ID::AudioStatistics,
[this](const Message* const p) { [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);
} }
@ -34,7 +36,7 @@ void Audio::on_show() {
} }
void Audio::on_hide() { void Audio::on_hide() {
context().message_map().unregister_handler(Message::ID::AudioStatistics); EventDispatcher::message_map().unregister_handler(Message::ID::AudioStatistics);
} }
void Audio::paint(Painter& painter) { void Audio::paint(Painter& painter) {

View File

@ -21,6 +21,8 @@
#include "ui_baseband_stats_view.hpp" #include "ui_baseband_stats_view.hpp"
#include "event_m0.hpp"
#include <string> #include <string>
#include <algorithm> #include <algorithm>
@ -40,7 +42,7 @@ BasebandStatsView::BasebandStatsView() {
} }
void BasebandStatsView::on_show() { void BasebandStatsView::on_show() {
context().message_map().register_handler(Message::ID::BasebandStatistics, EventDispatcher::message_map().register_handler(Message::ID::BasebandStatistics,
[this](const Message* const p) { [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);
} }
@ -48,7 +50,7 @@ void BasebandStatsView::on_show() {
} }
void BasebandStatsView::on_hide() { void BasebandStatsView::on_hide() {
context().message_map().unregister_handler(Message::ID::BasebandStatistics); EventDispatcher::message_map().unregister_handler(Message::ID::BasebandStatistics);
} }

View File

@ -21,12 +21,14 @@
#include "ui_channel.hpp" #include "ui_channel.hpp"
#include "event_m0.hpp"
#include <algorithm> #include <algorithm>
namespace ui { namespace ui {
void Channel::on_show() { void Channel::on_show() {
context().message_map().register_handler(Message::ID::ChannelStatistics, EventDispatcher::message_map().register_handler(Message::ID::ChannelStatistics,
[this](const Message* const p) { [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);
} }
@ -34,7 +36,7 @@ void Channel::on_show() {
} }
void Channel::on_hide() { void Channel::on_hide() {
context().message_map().unregister_handler(Message::ID::ChannelStatistics); EventDispatcher::message_map().unregister_handler(Message::ID::ChannelStatistics);
} }
void Channel::paint(Painter& painter) { void Channel::paint(Painter& painter) {

View File

@ -21,12 +21,14 @@
#include "ui_rssi.hpp" #include "ui_rssi.hpp"
#include "event_m0.hpp"
#include <algorithm> #include <algorithm>
namespace ui { namespace ui {
void RSSI::on_show() { void RSSI::on_show() {
context().message_map().register_handler(Message::ID::RSSIStatistics, EventDispatcher::message_map().register_handler(Message::ID::RSSIStatistics,
[this](const Message* const p) { [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);
} }
@ -34,7 +36,7 @@ void RSSI::on_show() {
} }
void RSSI::on_hide() { void RSSI::on_hide() {
context().message_map().unregister_handler(Message::ID::RSSIStatistics); EventDispatcher::message_map().unregister_handler(Message::ID::RSSIStatistics);
} }
void RSSI::paint(Painter& painter) { void RSSI::paint(Painter& painter) {

View File

@ -21,6 +21,8 @@
#include "ui_spectrum.hpp" #include "ui_spectrum.hpp"
#include "event_m0.hpp"
#include "spectrum_color_lut.hpp" #include "spectrum_color_lut.hpp"
#include "portapack.hpp" #include "portapack.hpp"
@ -235,13 +237,13 @@ WaterfallWidget::WaterfallWidget() {
} }
void WaterfallWidget::on_show() { void WaterfallWidget::on_show() {
context().message_map().register_handler(Message::ID::ChannelSpectrumConfig, EventDispatcher::message_map().register_handler(Message::ID::ChannelSpectrumConfig,
[this](const Message* const p) { [this](const Message* const p) {
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p); const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
this->fifo = message.fifo; this->fifo = message.fifo;
} }
); );
context().message_map().register_handler(Message::ID::DisplayFrameSync, EventDispatcher::message_map().register_handler(Message::ID::DisplayFrameSync,
[this](const Message* const) { [this](const Message* const) {
if( this->fifo ) { if( this->fifo ) {
ChannelSpectrum channel_spectrum; ChannelSpectrum channel_spectrum;
@ -266,8 +268,8 @@ void WaterfallWidget::on_hide() {
} }
); );
context().message_map().unregister_handler(Message::ID::DisplayFrameSync); EventDispatcher::message_map().unregister_handler(Message::ID::DisplayFrameSync);
context().message_map().unregister_handler(Message::ID::ChannelSpectrumConfig); EventDispatcher::message_map().unregister_handler(Message::ID::ChannelSpectrumConfig);
} }
void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) { void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {

View File

@ -29,8 +29,6 @@
#include "utility.hpp" #include "utility.hpp"
#include "message.hpp"
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <string> #include <string>
@ -47,13 +45,8 @@ public:
return focus_manager_; return focus_manager_;
} }
MessageHandlerMap& message_map() {
return message_map_;
}
private: private:
FocusManager focus_manager_; FocusManager focus_manager_;
MessageHandlerMap message_map_;
}; };
class Widget { class Widget {