Files
firmware/src/mesh/MeshPacketQueue.h
Audun Foyen 8a79663fa0 Drop lower priority packets when tx queue is full.
Track packet pointers in vector. Priority maintained using: push_heap, pop_heap, make_heap, and sort_heap.
2021-07-31 21:42:48 +02:00

33 lines
778 B
C++

#pragma once
#include "MeshTypes.h"
#include <assert.h>
#include <queue>
/**
* A priority queue of packets
*/
class MeshPacketQueue
{
size_t maxLen;
std::vector<MeshPacket *> queue;
/** Replace a lower priority package in the queue with 'mp' (provided there are lower pri packages). Return true if replaced. */
bool replaceLowerPriorityPacket(MeshPacket *mp);
public:
MeshPacketQueue(size_t _maxLen);
/** enqueue a packet, return false if full */
bool enqueue(MeshPacket *p);
/** return true if the queue is empty */
bool empty();
MeshPacket *dequeue();
/** Attempt to find and remove a packet from this queue. Returns the packet which was removed from the queue */
MeshPacket *remove(NodeNum from, PacketId id);
};