#include #include #include #ifndef _GROUP_STATE_STORE_H #define _GROUP_STATE_STORE_H class GroupStateStore { public: GroupStateStore(const size_t maxSize, const size_t flushRate); /* * Returns the state for the given BulbId. If no state exists, a suitable * default state will be returned. */ GroupState& get(const BulbId& id); GroupState& get(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType); /* * Sets the state for the given BulbId. State will be marked as dirty and * flushed to persistent storage. */ GroupState& set(const BulbId& id, const GroupState& state); GroupState& set(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType, const GroupState& state); /* * Flushes all states to persistent storage. Returns true iff anything was * flushed. */ bool flush(); /* * Flushes at most one dirty state to persistent storage. Rate limit * specified by Settings. */ void limitedFlush(); private: GroupStateCache cache; GroupStatePersistence persistence; LinkedList evictedIds; const size_t flushRate; unsigned long lastFlush; void trackEviction(); }; #endif