LoRaMesher Library  0.0.5
A LoRa Mesh library for the IoT
PacketQueueService.h
1#ifndef _LORAMESHER_PACKET_QUEUE_SERVICE_H
2#define _LORAMESHER_PACKET_QUEUE_SERVICE_H
3
4#include <Arduino.h>
5
6#include "ArduinoLog.h"
7
8#include "entities/packets/QueuePacket.h"
9
10#include "services/PacketService.h"
11
12#include "utilities/LinkedQueue.hpp"
13
14class PacketQueueService {
15public:
16
26 template<class T>
27 static QueuePacket<T>* createQueuePacket(T* p, uint8_t priority, uint16_t number = 0) {
28 QueuePacket<T>* qp = new QueuePacket<T>();
29 qp->priority = priority;
30 qp->number = number;
31 qp->packet = p;
32 return qp;
33 }
34
43 template<class T>
44 static QueuePacket<T>* findPacketQueue(LM_LinkedList<QueuePacket<T>>* queue, uint8_t num) {
45 queue->setInUse();
46
47 if (queue->moveToStart()) {
48 do {
49 QueuePacket<T>* current = queue->getCurrent();
50
51 if (current->number == num) {
52 queue->releaseInUse();
53 return current;
54 }
55
56 } while (queue->next());
57 }
58
59 queue->releaseInUse();
60
61 return nullptr;
62 }
63
70 static void addOrdered(LM_LinkedList<QueuePacket<Packet<uint8_t>>>* list, QueuePacket<Packet<uint8_t>>* qp);
71
77 static void deleteQueuePacketAndPacket(QueuePacket<Packet<uint8_t>>* pq) {
78 Log.traceln(F("Deleting packet"));
79 free(pq->packet);
80
81 Log.traceln(F("Deleting packet queue"));
82 delete pq;
83 }
84
91 template <typename T>
92 static void deleteQueuePacketAndPacket(QueuePacket<T>* pq) {
93 deleteQueuePacketAndPacket(reinterpret_cast<QueuePacket<Packet<uint8_t>>*>(pq));
94 }
95
96};
97
98#endif