diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2019-01-22 11:34:50 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2019-01-22 15:01:32 +0300 |
commit | 58182fc7a6ef5cd6d9c451263f7b03f71f418a32 (patch) | |
tree | d25a62a694c8dca833959fe40ffdf7d00e09ce19 /platform | |
parent | 1eece0bef3428cd1394d74841e98b823ef6ef490 (diff) |
[core][power_manager] review fixes
Diffstat (limited to 'platform')
-rw-r--r-- | platform/battery_tracker.cpp | 17 | ||||
-rw-r--r-- | platform/battery_tracker.hpp | 1 |
2 files changed, 10 insertions, 8 deletions
diff --git a/platform/battery_tracker.cpp b/platform/battery_tracker.cpp index a80ce09eed..c77139f532 100644 --- a/platform/battery_tracker.cpp +++ b/platform/battery_tracker.cpp @@ -18,15 +18,13 @@ void BatteryLevelTracker::Subscribe(Subscriber * subscriber) { m_subscribers.push_back(subscriber); - if (IsLevelExpired(m_lastRequestTime)) - { - // Run periodic requests when the first subscriber is added. - if (m_subscribers.size() == 1) - RequestBatteryLevel(); - } - else - { + if (!IsLevelExpired(m_lastRequestTime)) subscriber->OnBatteryLevelReceived(m_lastReceivedLevel); + + if (!m_isTrackingInProgress) + { + m_isTrackingInProgress = true; + RequestBatteryLevel(); } } @@ -44,7 +42,10 @@ void BatteryLevelTracker::UnsubscribeAll() void BatteryLevelTracker::RequestBatteryLevel() { if (m_subscribers.empty()) + { + m_isTrackingInProgress = false; return; + } if (IsLevelExpired(m_lastRequestTime)) { diff --git a/platform/battery_tracker.hpp b/platform/battery_tracker.hpp index 65a6b35f3b..320b8372f1 100644 --- a/platform/battery_tracker.hpp +++ b/platform/battery_tracker.hpp @@ -26,5 +26,6 @@ private: std::vector<Subscriber *> m_subscribers; std::chrono::system_clock::time_point m_lastRequestTime; uint8_t m_lastReceivedLevel = 0; + bool m_isTrackingInProgress = false; }; } // platform |