Remove Signal use, register message handler in View.

Changed my mind from earlier commit...
This commit is contained in:
Jared Boone 2016-01-13 17:00:53 -08:00
parent 94b73d7825
commit 8c34e116af
2 changed files with 13 additions and 32 deletions

View File

@ -89,27 +89,11 @@ AISModel::AISModel() {
receiver_model.set_baseband_bandwidth(1750000);
log_file.open_for_append("ais.txt");
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 };
this->on_packet(packet);
}
);
}
AISModel::~AISModel() {
EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
}
bool AISModel::on_packet(const ais::Packet& packet) {
// TODO: Unstuff here, not in baseband!
if( !packet.is_valid() ) {
return false;
}
if( log_file.is_ready() ) {
std::string entry;
entry.reserve((packet.length() + 3) / 4);
@ -122,8 +106,6 @@ bool AISModel::on_packet(const ais::Packet& packet) {
log_file.write_entry(packet.received_at(), entry);
}
packet_signal.emit(packet);
return true;
}
@ -132,13 +114,20 @@ namespace ui {
AISView::AISView() {
flags.focusable = true;
packet_signal_token = model.packet_signal += [this](const ais::Packet& packet) {
this->on_packet(packet);
};
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 };
if( packet.is_valid() ) {
this->model.on_packet(packet);
this->on_packet(packet);
}
}
);
}
AISView::~AISView() {
model.packet_signal -= packet_signal_token;
EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
}
void AISView::truncate_entries() {

View File

@ -25,12 +25,8 @@
#include "ui_widget.hpp"
#include "log_file.hpp"
#include "message.hpp"
#include "ais_packet.hpp"
#include "signal.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
@ -70,14 +66,11 @@ struct AISRecentEntry {
class AISModel {
public:
AISModel();
~AISModel();
Signal<const ais::Packet&> packet_signal;
bool on_packet(const ais::Packet& packet);
private:
LogFile log_file;
bool on_packet(const ais::Packet& packet);
};
namespace ui {
@ -86,7 +79,7 @@ class AISView : public View {
public:
AISView();
~AISView();
void paint(Painter& painter) override;
void on_focus() override;
@ -96,7 +89,6 @@ public:
private:
AISModel model;
SignalToken packet_signal_token;
using EntryKey = ais::MMSI;
EntryKey selected_key;