Hide most of MessageQueue functions.

This commit is contained in:
Jared Boone 2016-02-27 21:19:51 -08:00
parent bf348cf30a
commit 0fae1488c4

View File

@ -60,6 +60,19 @@ public:
return result;
}
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;
Message* peek(std::array<uint8_t, Message::MAX_SIZE>& buf) {
Message* const p = reinterpret_cast<Message*>(buf.data());
return fifo.peek_r(buf.data(), buf.size()) ? p : nullptr;
@ -82,19 +95,6 @@ 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;
bool push(const void* const buf, const size_t len) {
chMtxLock(&mutex_write);
const auto result = fifo.in_r(buf, len);