summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-03-07 21:50:24 -0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-03-08 10:31:01 -0300
commitfa7c40c37fc2078b181f77afc808fdc4cd1baae9 (patch)
tree8b56eb1f406ca87153204aae6919f05ee188dd90 /src
parent20c3706536ac9e927f80a50e9ec8906dfd0d2baf (diff)
downloadqtlocation-mapboxgl-fa7c40c37fc2078b181f77afc808fdc4cd1baae9.tar.gz
[core] Add client defined network status
This API will let the client force a network status. If set to Offline, we won't make network requests. When set make to Online, it will trigger the pending requests and try to fetch tiles from the network.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/storage/network_status.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mbgl/storage/network_status.cpp b/src/mbgl/storage/network_status.cpp
index 796cc5d27f..1ef5619bd6 100644
--- a/src/mbgl/storage/network_status.cpp
+++ b/src/mbgl/storage/network_status.cpp
@@ -9,9 +9,27 @@
namespace mbgl {
+std::atomic<bool> NetworkStatus::online(true);
std::mutex NetworkStatus::mtx;
std::set<util::AsyncTask *> NetworkStatus::observers;
+NetworkStatus::Status NetworkStatus::Get() {
+ if (online) {
+ return Status::Online;
+ } else {
+ return Status::Offline;
+ }
+}
+
+void NetworkStatus::Set(Status status) {
+ if (status == Status::Online) {
+ online = true;
+ Reachable();
+ } else {
+ online = false;
+ }
+}
+
void NetworkStatus::Subscribe(util::AsyncTask *async) {
std::lock_guard<std::mutex> lock(NetworkStatus::mtx);
observers.insert(async);
@@ -23,6 +41,10 @@ void NetworkStatus::Unsubscribe(util::AsyncTask *async) {
}
void NetworkStatus::Reachable() {
+ if (!online) {
+ return;
+ }
+
std::lock_guard<std::mutex> lock(NetworkStatus::mtx);
for (auto async : observers) {
async->send();