Removing baseband MessageHandlerMap.

It's a bit heavy (362 bytes smaller with switch/case implementation), hard to access to add/remove handlers, doesn't bubble events like I'd like. (I'm going to bubble events to the baseband processor shortly.)
This commit is contained in:
Jared Boone 2016-01-02 22:54:09 -08:00
parent fea5dd536f
commit 07cd99d85d

View File

@ -121,24 +121,7 @@ static void shutdown() {
class EventDispatcher {
public:
MessageHandlerMap& message_handlers() {
return message_map;
}
void run() {
message_map.register_handler(Message::ID::BasebandConfiguration,
[this](const Message* const p) {
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
this->baseband_thread.set_configuration(message->configuration);
}
);
message_map.register_handler(Message::ID::Shutdown,
[this](const Message* const) {
this->request_stop();
}
);
events_initialize(chThdSelf());
m0apptxevent_interrupt_enable();
@ -159,7 +142,6 @@ public:
}
private:
MessageHandlerMap message_map;
BasebandThread baseband_thread;
RSSIThread rssi_thread;
@ -182,10 +164,38 @@ private:
void handle_baseband_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = shared_memory.baseband_queue.pop(message_buffer)) {
message_map.send(message);
on_message(message);
}
}
void on_message(const Message* const message) {
switch(message->id) {
case Message::ID::BasebandConfiguration:
on_message_baseband_configuration(*reinterpret_cast<const BasebandConfigurationMessage*>(message));
break;
case Message::ID::Shutdown:
on_message_shutdown(*reinterpret_cast<const ShutdownMessage*>(message));
break;
default:
on_message_default(message);
break;
}
}
void on_message_baseband_configuration(const BasebandConfigurationMessage& message) {
baseband_thread.set_configuration(message.configuration);
}
void on_message_shutdown(const ShutdownMessage&) {
request_stop();
}
void on_message_default(const Message* const) {
// TODO: Pass to active baseband processor.
}
void handle_spectrum() {
// TODO: Send this via another message?!
baseband_thread.on_update_spectrum();