GroupStateStore.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /*
  15. * Sets the state for the given BulbId. State will be marked as dirty and
  16. * flushed to persistent storage.
  17. */
  18. GroupState& set(const BulbId& id, const GroupState& state);
  19. /*
  20. * Flushes all states to persistent storage. Returns true iff anything was
  21. * flushed.
  22. */
  23. bool flush();
  24. /*
  25. * Flushes at most one dirty state to persistent storage. Rate limit
  26. * specified by Settings.
  27. */
  28. void limitedFlush();
  29. private:
  30. GroupStateCache cache;
  31. GroupStatePersistence persistence;
  32. LinkedList<BulbId> evictedIds;
  33. const size_t flushRate;
  34. unsigned long lastFlush;
  35. void trackEviction();
  36. };
  37. #endif