Un-const Message in message handler interfaces.

I want to modify in place the messages that are received. Naughty, but oh well.
This commit is contained in:
Jared Boone 2015-09-26 11:48:30 -07:00
parent 5469a3a31d
commit 31ff13f1c0
5 changed files with 8 additions and 8 deletions

View File

@ -124,7 +124,7 @@ private:
void handle_application_queue() { void handle_application_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer; std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(const Message* const message = shared_memory.application_queue.pop(message_buffer)) { while(Message* const message = shared_memory.application_queue.pop(message_buffer)) {
context.message_map.send(message); context.message_map.send(message);
} }
} }

View File

@ -493,8 +493,8 @@ ReceiverView::~ReceiverView() {
void ReceiverView::on_show() { void ReceiverView::on_show() {
context().message_map.register_handler(Message::ID::FSKPacket, context().message_map.register_handler(Message::ID::FSKPacket,
[](const Message* const p) { [this](Message* const p) {
const auto message = static_cast<const FSKPacketMessage*>(p); auto message = static_cast<FSKPacketMessage*>(p);
(void)message; (void)message;
} }
); );

View File

@ -260,7 +260,7 @@ private:
void handle_baseband_queue() { void handle_baseband_queue() {
std::array<uint8_t, Message::MAX_SIZE> message_buffer; std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(const Message* const message = shared_memory.baseband_queue.pop(message_buffer)) { while(Message* const message = shared_memory.baseband_queue.pop(message_buffer)) {
message_map.send(message); message_map.send(message);
} }
} }

View File

@ -245,7 +245,7 @@ public:
class MessageHandlerMap { class MessageHandlerMap {
public: public:
using MessageHandler = std::function<void(const Message* const p)>; using MessageHandler = std::function<void(Message* const p)>;
void register_handler(const Message::ID id, MessageHandler&& handler) { void register_handler(const Message::ID id, MessageHandler&& handler) {
map_[toUType(id)] = std::move(handler); map_[toUType(id)] = std::move(handler);
@ -255,7 +255,7 @@ public:
map_[toUType(id)] = nullptr; map_[toUType(id)] = nullptr;
} }
void send(const Message* const message) { void send(Message* const message) {
if( message->id < Message::ID::MAX ) { if( message->id < Message::ID::MAX ) {
auto& fn = map_[toUType(message->id)]; auto& fn = map_[toUType(message->id)];
if( fn ) { if( fn ) {

View File

@ -47,8 +47,8 @@ public:
return push(&message, sizeof(message)); return push(&message, sizeof(message));
} }
const Message* pop(std::array<uint8_t, Message::MAX_SIZE>& buf) { Message* pop(std::array<uint8_t, Message::MAX_SIZE>& buf) {
const Message* const p = reinterpret_cast<Message*>(buf.data()); Message* const p = reinterpret_cast<Message*>(buf.data());
return fifo.out_r(buf.data(), buf.size()) ? p : nullptr; return fifo.out_r(buf.data(), buf.size()) ? p : nullptr;
} }