GroupStateStore.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 accessing state for a valid device
  11. * (i.e., NOT group 0) and no state exists, its state will be initialized with a
  12. * default.
  13. *
  14. * Otherwise, we return NULL.
  15. */
  16. GroupState* get(const BulbId& id);
  17. GroupState* get(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType);
  18. /*
  19. * Sets the state for the given BulbId. State will be marked as dirty and
  20. * flushed to persistent storage.
  21. */
  22. GroupState* set(const BulbId& id, const GroupState& state);
  23. GroupState* set(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType, const GroupState& state);
  24. /*
  25. * Flushes all states to persistent storage. Returns true iff anything was
  26. * flushed.
  27. */
  28. bool flush();
  29. /*
  30. * Flushes at most one dirty state to persistent storage. Rate limit
  31. * specified by Settings.
  32. */
  33. void limitedFlush();
  34. private:
  35. GroupStateCache cache;
  36. GroupStatePersistence persistence;
  37. LinkedList<BulbId> evictedIds;
  38. const size_t flushRate;
  39. unsigned long lastFlush;
  40. void trackEviction();
  41. };
  42. #endif