Woman, Life, Freedom


OBD-II Emulator
Linux ODB-II Emulator public and protected interfaces documentation
packet_buffer.h
1#ifndef PACKET_BUFFER_H
2#define PACKET_BUFFER_H
3
4#include <atomic>
5#include <mutex>
6#include <queue>
7#include <vector>
8
9namespace ObdEmulator
10{
13 {
14 private:
15 std::mutex mMutex;
16 std::queue<std::vector<uint8_t>> mQueue;
17 std::atomic_size_t mSize;
18
19 public:
21
22 ~PacketBuffer() = default;
23
26 inline bool Empty() const noexcept
27 {
28 return mSize == 0;
29 }
30
34 bool TryEnqueue(std::vector<uint8_t> &&packet);
35
39 bool TryDequeue(std::vector<uint8_t> &packet);
40
43 bool TryClear();
44 };
45}
46
47#endif
Thread-safe queue for buffering packet data bytes.
Definition: packet_buffer.h:13
bool TryDequeue(std::vector< uint8_t > &packet)
Try to peek a packet from the buffer by removing it.
bool TryClear()
Try to make the buffer empty.
bool Empty() const noexcept
Indicate whether the buffer is empty or not.
Definition: packet_buffer.h:26
bool TryEnqueue(std::vector< uint8_t > &&packet)
Try to insert a packet to the buffer via moving.