mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Hide implementation of MessageHandlerMap.
This commit is contained in:
parent
2aa8ae0d1f
commit
a7226820d0
@ -184,10 +184,7 @@ private:
|
||||
while( !shared_memory.application_queue.is_empty() ) {
|
||||
auto message = shared_memory.application_queue.pop();
|
||||
|
||||
auto& fn = context.message_map[message->id];
|
||||
if( fn ) {
|
||||
fn(message);
|
||||
}
|
||||
context.message_map.send(message);
|
||||
|
||||
message->state = Message::State::Free;
|
||||
}
|
||||
|
@ -26,13 +26,15 @@
|
||||
namespace ui {
|
||||
|
||||
void Audio::on_show() {
|
||||
context().message_map[Message::ID::AudioStatistics] = [this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
||||
};
|
||||
context().message_map.register_handler(Message::ID::AudioStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const AudioStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Audio::on_hide() {
|
||||
context().message_map[Message::ID::AudioStatistics] = nullptr;
|
||||
context().message_map.unregister_handler(Message::ID::AudioStatistics);
|
||||
}
|
||||
|
||||
void Audio::paint(Painter& painter) {
|
||||
|
@ -26,13 +26,15 @@
|
||||
namespace ui {
|
||||
|
||||
void Channel::on_show() {
|
||||
context().message_map[Message::ID::ChannelStatistics] = [this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
||||
};
|
||||
context().message_map.register_handler(Message::ID::ChannelStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const ChannelStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Channel::on_hide() {
|
||||
context().message_map[Message::ID::ChannelStatistics] = nullptr;
|
||||
context().message_map.unregister_handler(Message::ID::ChannelStatistics);
|
||||
}
|
||||
|
||||
void Channel::paint(Painter& painter) {
|
||||
|
@ -40,13 +40,15 @@ BasebandStatsView::BasebandStatsView() {
|
||||
}
|
||||
|
||||
void BasebandStatsView::on_show() {
|
||||
context().message_map[Message::ID::BasebandStatistics] = [this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
||||
};
|
||||
context().message_map.register_handler(Message::ID::BasebandStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const BasebandStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void BasebandStatsView::on_hide() {
|
||||
context().message_map[Message::ID::BasebandStatistics] = nullptr;
|
||||
context().message_map.unregister_handler(Message::ID::BasebandStatistics);
|
||||
}
|
||||
|
||||
|
||||
|
@ -481,15 +481,17 @@ ReceiverView::ReceiverView(
|
||||
|
||||
receiver_model.enable();
|
||||
|
||||
context().message_map[Message::ID::FSKPacket] = [](const Message* const p) {
|
||||
const auto message = static_cast<const FSKPacketMessage*>(p);
|
||||
(void)message;
|
||||
};
|
||||
context().message_map.register_handler(Message::ID::FSKPacket,
|
||||
[](const Message* const p) {
|
||||
const auto message = static_cast<const FSKPacketMessage*>(p);
|
||||
(void)message;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
// both?
|
||||
audio_codec.headphone_mute();
|
||||
|
@ -26,13 +26,15 @@
|
||||
namespace ui {
|
||||
|
||||
void RSSI::on_show() {
|
||||
context().message_map[Message::ID::RSSIStatistics] = [this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||
};
|
||||
context().message_map.register_handler(Message::ID::RSSIStatistics,
|
||||
[this](const Message* const p) {
|
||||
this->on_statistics_update(static_cast<const RSSIStatisticsMessage*>(p)->statistics);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void RSSI::on_hide() {
|
||||
context().message_map[Message::ID::RSSIStatistics] = nullptr;
|
||||
context().message_map.unregister_handler(Message::ID::RSSIStatistics);
|
||||
}
|
||||
|
||||
void RSSI::paint(Painter& painter) {
|
||||
|
@ -233,13 +233,15 @@ public:
|
||||
}
|
||||
|
||||
void on_show() override {
|
||||
context().message_map[Message::ID::ChannelSpectrum] = [this](const Message* const p) {
|
||||
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
||||
};
|
||||
context().message_map.register_handler(Message::ID::ChannelSpectrum,
|
||||
[this](const Message* const p) {
|
||||
this->on_channel_spectrum(reinterpret_cast<const ChannelSpectrumMessage*>(p)->spectrum);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -481,14 +481,16 @@ public:
|
||||
MessageHandlerMap& message_handlers
|
||||
) : message_handlers(message_handlers)
|
||||
{
|
||||
message_handlers[Message::ID::FSKConfiguration] = [this](const Message* const p) {
|
||||
auto m = reinterpret_cast<const FSKConfigurationMessage*>(p);
|
||||
this->configure(m->configuration);
|
||||
};
|
||||
message_handlers.register_handler(Message::ID::FSKConfiguration,
|
||||
[this](const Message* const p) {
|
||||
auto m = reinterpret_cast<const FSKConfigurationMessage*>(p);
|
||||
this->configure(m->configuration);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
~FSKProcessor() {
|
||||
message_handlers[Message::ID::FSKConfiguration] = nullptr;
|
||||
message_handlers.unregister_handler(Message::ID::FSKConfiguration);
|
||||
}
|
||||
|
||||
void configure(const FSKConfiguration new_configuration) {
|
||||
@ -736,10 +738,7 @@ private:
|
||||
while( !shared_memory.baseband_queue.is_empty() ) {
|
||||
auto message = shared_memory.baseband_queue.pop();
|
||||
|
||||
auto& fn = message_map[message->id];
|
||||
if( fn ) {
|
||||
fn(message);
|
||||
}
|
||||
message_map.send(message);
|
||||
|
||||
message->state = Message::State::Free;
|
||||
}
|
||||
@ -804,49 +803,51 @@ int main(void) {
|
||||
EventDispatcher event_dispatcher;
|
||||
auto& message_handlers = event_dispatcher.message_handlers();
|
||||
|
||||
message_handlers[Message::ID::BasebandConfiguration] = [&message_handlers](const Message* const p) {
|
||||
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
||||
if( message->configuration.mode != baseband_configuration.mode ) {
|
||||
message_handlers.register_handler(Message::ID::BasebandConfiguration,
|
||||
[&message_handlers](const Message* const p) {
|
||||
auto message = reinterpret_cast<const BasebandConfigurationMessage*>(p);
|
||||
if( message->configuration.mode != baseband_configuration.mode ) {
|
||||
|
||||
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
|
||||
auto old_p = baseband_processor;
|
||||
baseband_processor = nullptr;
|
||||
delete old_p;
|
||||
// TODO: Timing problem around disabling DMA and nulling and deleting old processor
|
||||
auto old_p = baseband_processor;
|
||||
baseband_processor = nullptr;
|
||||
delete old_p;
|
||||
|
||||
switch(message->configuration.mode) {
|
||||
case 0:
|
||||
baseband_processor = new NarrowbandAMAudio();
|
||||
break;
|
||||
switch(message->configuration.mode) {
|
||||
case 0:
|
||||
baseband_processor = new NarrowbandAMAudio();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
baseband_processor = new NarrowbandFMAudio();
|
||||
break;
|
||||
case 1:
|
||||
baseband_processor = new NarrowbandFMAudio();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
baseband_processor = new WidebandFMAudio();
|
||||
break;
|
||||
case 2:
|
||||
baseband_processor = new WidebandFMAudio();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
baseband_processor = new FSKProcessor(message_handlers);
|
||||
break;
|
||||
case 3:
|
||||
baseband_processor = new FSKProcessor(message_handlers);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if( baseband_processor ) {
|
||||
if( direction == baseband::Direction::Receive ) {
|
||||
rf::rssi::start();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
baseband::dma::enable(direction);
|
||||
} else {
|
||||
baseband::dma::disable();
|
||||
rf::rssi::stop();
|
||||
}
|
||||
}
|
||||
|
||||
baseband_configuration = message->configuration;
|
||||
};
|
||||
if( baseband_processor ) {
|
||||
if( direction == baseband::Direction::Receive ) {
|
||||
rf::rssi::start();
|
||||
}
|
||||
baseband::dma::enable(direction);
|
||||
} else {
|
||||
baseband::dma::disable();
|
||||
rf::rssi::stop();
|
||||
}
|
||||
}
|
||||
|
||||
baseband_configuration = message->configuration;
|
||||
}
|
||||
);
|
||||
|
||||
/* TODO: Ensure DMAs are configured to point at first LLI in chain. */
|
||||
|
||||
|
@ -246,12 +246,19 @@ class MessageHandlerMap {
|
||||
public:
|
||||
using MessageHandler = std::function<void(const Message* const p)>;
|
||||
|
||||
MessageHandler& operator[](Message::ID n) {
|
||||
return map_[toUType(n)];
|
||||
void register_handler(const Message::ID id, MessageHandler&& handler) {
|
||||
map_[toUType(id)] = std::move(handler);
|
||||
}
|
||||
|
||||
const MessageHandler& operator[](Message::ID n) const {
|
||||
return map_[toUType(n)];
|
||||
void unregister_handler(const Message::ID id) {
|
||||
map_[toUType(id)] = nullptr;
|
||||
}
|
||||
|
||||
void send(const Message* const message) {
|
||||
auto& fn = map_[toUType(message->id)];
|
||||
if( fn ) {
|
||||
fn(message);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user