Don't update battery list on every update

Speedup battery state update by only updating the battery list when we
get a CREATE/DELETE event in the directory or whenever we do a full
refresh on the interval.
This commit is contained in:
Pedro Côrte-Real
2020-12-03 09:52:33 +00:00
parent cc365a8175
commit 09c89bcd20
2 changed files with 41 additions and 19 deletions

View File

@ -34,16 +34,19 @@ class Battery : public ALabel {
void refreshBatteries();
void worker();
const std::string getAdapterStatus(uint8_t capacity) const;
const std::tuple<uint8_t, float, std::string> getInfos() const;
const std::tuple<uint8_t, float, std::string> getInfos();
const std::string formatTimeRemaining(float hoursRemaining);
int global_watch;
std::map<fs::path,int> batteries_;
fs::path adapter_;
int fd_;
int battery_watch_fd_;
int global_watch_fd_;
std::mutex battery_list_mutex_;
std::string old_status_;
util::SleeperThread thread_;
util::SleeperThread thread_battery_update_;
util::SleeperThread thread_timer_;
};