1 | #pragma once |
2 | |
3 | #include <atomic> |
4 | #include <mutex> |
5 | #include <unordered_set> |
6 | |
7 | namespace mbgl { |
8 | |
9 | namespace util { |
10 | class AsyncTask; |
11 | } // namespace util |
12 | |
13 | class NetworkStatus { |
14 | public: |
15 | enum class Status : uint8_t { |
16 | Online, |
17 | Offline, |
18 | }; |
19 | |
20 | static Status Get(); |
21 | static void Set(Status); |
22 | |
23 | static void Reachable(); |
24 | |
25 | static void Subscribe(util::AsyncTask* async); |
26 | static void Unsubscribe(util::AsyncTask* async); |
27 | |
28 | private: |
29 | static std::atomic<bool> online; |
30 | static std::mutex mtx; |
31 | static std::unordered_set<util::AsyncTask*> observers; |
32 | }; |
33 | |
34 | } // namespace mbgl |
35 | |