GroupStateStore.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <GroupState.h>
  2. #include <GroupStateCache.h>
  3. #include <GroupStatePersistence.h>
  4. #ifndef _GROUP_STATE_STORE_H
  5. #define _GROUP_STATE_STORE_H
  6. class GroupStateStore {
  7. public:
  8. GroupStateStore(const size_t maxSize, const size_t flushRate);
  9. /*
  10. * Returns the state for the given BulbId. If no state exists, a suitable
  11. * default state will be returned.
  12. */
  13. GroupState& get(const BulbId& id);
  14. GroupState& get(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType);
  15. /*
  16. * Sets the state for the given BulbId. State will be marked as dirty and
  17. * flushed to persistent storage.
  18. */
  19. GroupState& set(const BulbId& id, const GroupState& state);
  20. GroupState& set(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType, const GroupState& state);
  21. /*
  22. * Flushes all states to persistent storage. Returns true iff anything was
  23. * flushed.
  24. */
  25. bool flush();
  26. /*
  27. * Flushes at most one dirty state to persistent storage. Rate limit
  28. * specified by Settings.
  29. */
  30. void limitedFlush();
  31. private:
  32. GroupStateCache cache;
  33. GroupStatePersistence persistence;
  34. LinkedList<BulbId> evictedIds;
  35. const size_t flushRate;
  36. unsigned long lastFlush;
  37. void trackEviction();
  38. };
  39. #endif