PacketQueue.h 731 B

12345678910111213141516171819202122232425262728293031
  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. void push(const uint8_t* packet, const MiLightRemoteConfig* remoteConfig, const size_t repeatsOverride);
  17. std::shared_ptr<QueuedPacket> pop();
  18. bool isEmpty();
  19. size_t size();
  20. private:
  21. std::shared_ptr<QueuedPacket> checkoutPacket();
  22. void checkinPacket(std::shared_ptr<QueuedPacket> packet);
  23. LinkedList<std::shared_ptr<QueuedPacket>> queue;
  24. };