Welcome to mirror list, hosted at ThFree Co, Russian Federation.

battery_tracker.hpp « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 320b8372f17163e55d1da50d25bbffe82328db96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include <chrono>
#include <cstdint>
#include <vector>

namespace platform
{
// Note: this class is NOT thread-safe.
class BatteryLevelTracker
{
public:
  class Subscriber
  {
  public:
    virtual void OnBatteryLevelReceived(uint8_t level) = 0;
  };

  void Subscribe(Subscriber * subscriber);
  void Unsubscribe(Subscriber * subscriber);
  void UnsubscribeAll();

private:
  void RequestBatteryLevel();

  std::vector<Subscriber *> m_subscribers;
  std::chrono::system_clock::time_point m_lastRequestTime;
  uint8_t m_lastReceivedLevel = 0;
  bool m_isTrackingInProgress = false;
};
}  // platform