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

View File

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

View File

@ -54,6 +54,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
}
MessageHandlerMap EventDispatcher::message_map_;
Thread* EventDispatcher::thread_event_loop = nullptr;
EventDispatcher::EventDispatcher(
@ -118,7 +119,7 @@ void EventDispatcher::dispatch(const eventmask_t events) {
void EventDispatcher::handle_application_queue() {
std::array<uint8_t, Message::MAX_SIZE> 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() {
DisplayFrameSyncMessage message;
context.message_map().send(&message);
message_map().send(&message);
painter.paint_widget_tree(top_widget);
}

View File

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

View File

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

View File

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

View File

@ -21,12 +21,14 @@
#include "ui_audio.hpp"
#include "event_m0.hpp"
#include <algorithm>
namespace ui {
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->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
}
@ -34,7 +36,7 @@ void Audio::on_show() {
}
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) {

View File

@ -21,6 +21,8 @@
#include "ui_baseband_stats_view.hpp"
#include "event_m0.hpp"
#include <string>
#include <algorithm>
@ -40,7 +42,7 @@ BasebandStatsView::BasebandStatsView() {
}
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->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
}
@ -48,7 +50,7 @@ void BasebandStatsView::on_show() {
}
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 "event_m0.hpp"
#include <algorithm>
namespace ui {
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->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
}
@ -34,7 +36,7 @@ void Channel::on_show() {
}
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) {

View File

@ -21,12 +21,14 @@
#include "ui_rssi.hpp"
#include "event_m0.hpp"
#include <algorithm>
namespace ui {
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->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
}
@ -34,7 +36,7 @@ void RSSI::on_show() {
}
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) {

View File

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

View File

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