PacketQueue.h 827 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <memory>
  3. #include <CircularBuffer.h>
  4. #include <MiLightRadioConfig.h>
  5. #include <MiLightRemoteConfig.h>
  6. #ifndef MILIGHT_MAX_QUEUED_PACKETS
  7. #define MILIGHT_MAX_QUEUED_PACKETS 20
  8. #endif
  9. struct QueuedPacket {
  10. uint8_t packet[MILIGHT_MAX_PACKET_LENGTH];
  11. const MiLightRemoteConfig* remoteConfig;
  12. size_t repeatsOverride;
  13. };
  14. class PacketQueue {
  15. public:
  16. PacketQueue();
  17. void push(const uint8_t* packet, const MiLightRemoteConfig* remoteConfig, const size_t repeatsOverride);
  18. std::shared_ptr<QueuedPacket> pop();
  19. bool isEmpty() const;
  20. size_t size() const;
  21. size_t getDroppedPacketCount() const;
  22. private:
  23. size_t droppedPackets;
  24. std::shared_ptr<QueuedPacket> checkoutPacket();
  25. void checkinPacket(std::shared_ptr<QueuedPacket> packet);
  26. LinkedList<std::shared_ptr<QueuedPacket>> queue;
  27. };