Move message handling loops to MessageQueue.

This commit is contained in:
Jared Boone 2016-02-27 21:07:11 -08:00
parent eb294c8e1c
commit bf348cf30a
3 changed files with 14 additions and 8 deletions

View file

@ -82,6 +82,15 @@ public:
return fifo.is_empty();
}
template<typename HandlerFn>
void handle(HandlerFn handler) {
std::array<uint8_t, Message::MAX_SIZE> message_buffer;
while(Message* const message = peek(message_buffer)) {
handler(message);
skip();
}
}
private:
FIFO<uint8_t> fifo;
Mutex mutex_write;