mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-27 06:47:13 -05:00
Hide MessageHandlerMap.
Definitely didn't belong in message.hpp, saw no reason to expose it outside translation unit (.cpp file).
This commit is contained in:
parent
f731366248
commit
6bd191349a
@ -57,7 +57,36 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
|
||||
|
||||
}
|
||||
|
||||
MessageHandlerMap EventDispatcher::message_map_;
|
||||
class MessageHandlerMap {
|
||||
public:
|
||||
using MessageHandler = std::function<void(Message* const p)>;
|
||||
|
||||
void register_handler(const Message::ID id, MessageHandler&& handler) {
|
||||
if( map_[toUType(id)] != nullptr ) {
|
||||
chDbgPanic("MsgDblReg");
|
||||
}
|
||||
map_[toUType(id)] = std::move(handler);
|
||||
}
|
||||
|
||||
void unregister_handler(const Message::ID id) {
|
||||
map_[toUType(id)] = nullptr;
|
||||
}
|
||||
|
||||
void send(Message* const message) {
|
||||
if( message->id < Message::ID::MAX ) {
|
||||
auto& fn = map_[toUType(message->id)];
|
||||
if( fn ) {
|
||||
fn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
using MapType = std::array<MessageHandler, toUType(Message::ID::MAX)>;
|
||||
MapType map_;
|
||||
};
|
||||
|
||||
static MessageHandlerMap message_map;
|
||||
Thread* EventDispatcher::thread_event_loop = nullptr;
|
||||
|
||||
EventDispatcher::EventDispatcher(
|
||||
@ -90,6 +119,10 @@ void EventDispatcher::request_stop() {
|
||||
is_running = false;
|
||||
}
|
||||
|
||||
void EventDispatcher::send_message(Message* const message) {
|
||||
message_map.send(message);
|
||||
}
|
||||
|
||||
void EventDispatcher::set_display_sleep(const bool sleep) {
|
||||
// TODO: Distribute display sleep message more broadly, shut down data generation
|
||||
// on baseband side, since all that data is being discarded during sleep.
|
||||
@ -137,7 +170,7 @@ void EventDispatcher::dispatch(const eventmask_t events) {
|
||||
|
||||
void EventDispatcher::handle_application_queue() {
|
||||
shared_memory.application_queue.handle([](Message* const message) {
|
||||
message_map().send(message);
|
||||
message_map.send(message);
|
||||
});
|
||||
}
|
||||
|
||||
@ -193,7 +226,7 @@ void EventDispatcher::on_touch_event(ui::TouchEvent event) {
|
||||
|
||||
void EventDispatcher::handle_lcd_frame_sync() {
|
||||
DisplayFrameSyncMessage message;
|
||||
message_map().send(&message);
|
||||
message_map.send(&message);
|
||||
painter.paint_widget_tree(top_widget);
|
||||
}
|
||||
|
||||
@ -262,9 +295,9 @@ MessageHandlerRegistration::MessageHandlerRegistration(
|
||||
MessageHandlerMap::MessageHandler&& callback
|
||||
) : message_id { message_id }
|
||||
{
|
||||
EventDispatcher::message_map().register_handler(message_id, std::move(callback));
|
||||
message_map.register_handler(message_id, std::move(callback));
|
||||
}
|
||||
|
||||
MessageHandlerRegistration::~MessageHandlerRegistration() {
|
||||
EventDispatcher::message_map().unregister_handler(message_id);
|
||||
message_map.unregister_handler(message_id);
|
||||
}
|
||||
|
@ -80,16 +80,13 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static MessageHandlerMap& message_map() {
|
||||
return message_map_;
|
||||
}
|
||||
static void send_message(Message* const message);
|
||||
|
||||
private:
|
||||
static constexpr auto EVT_MASK_RTC_TICK = EVENT_MASK(0);
|
||||
static constexpr auto EVT_MASK_LCD_FRAME_SYNC = EVENT_MASK(1);
|
||||
static constexpr auto EVT_MASK_APPLICATION = EVENT_MASK(6);
|
||||
|
||||
static MessageHandlerMap message_map_;
|
||||
static Thread* thread_event_loop;
|
||||
|
||||
touch::Manager touch_manager;
|
||||
@ -128,7 +125,7 @@ class MessageHandlerRegistration {
|
||||
public:
|
||||
MessageHandlerRegistration(
|
||||
const Message::ID message_id,
|
||||
MessageHandlerMap::MessageHandler&& callback
|
||||
std::function<void(Message* const p)>&& callback
|
||||
);
|
||||
|
||||
~MessageHandlerRegistration();
|
||||
|
@ -63,7 +63,7 @@ SystemStatusView::SystemStatusView() {
|
||||
|
||||
button_sleep.on_select = [this](ImageButton&) {
|
||||
DisplaySleepMessage message;
|
||||
EventDispatcher::message_map().send(&message);
|
||||
EventDispatcher::send_message(&message);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -494,33 +494,4 @@ public:
|
||||
CaptureConfig* const config;
|
||||
};
|
||||
|
||||
class MessageHandlerMap {
|
||||
public:
|
||||
using MessageHandler = std::function<void(Message* const p)>;
|
||||
|
||||
void register_handler(const Message::ID id, MessageHandler&& handler) {
|
||||
if( map_[toUType(id)] != nullptr ) {
|
||||
chDbgPanic("MsgDblReg");
|
||||
}
|
||||
map_[toUType(id)] = std::move(handler);
|
||||
}
|
||||
|
||||
void unregister_handler(const Message::ID id) {
|
||||
map_[toUType(id)] = nullptr;
|
||||
}
|
||||
|
||||
void send(Message* const message) {
|
||||
if( message->id < Message::ID::MAX ) {
|
||||
auto& fn = map_[toUType(message->id)];
|
||||
if( fn ) {
|
||||
fn(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
using MapType = std::array<MessageHandler, toUType(Message::ID::MAX)>;
|
||||
MapType map_;
|
||||
};
|
||||
|
||||
#endif/*__MESSAGE_H__*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user