Move setReachability to CachingHTTPFileSource
This commit is contained in:
@@ -122,9 +122,6 @@ public:
|
||||
void toggleDebug();
|
||||
bool getDebug() const;
|
||||
|
||||
// Call this when the network reachability changed.
|
||||
void setReachability(bool status);
|
||||
|
||||
inline const TransformState &getState() const { return state; }
|
||||
inline timestamp getTime() const { return animationTime; }
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ public:
|
||||
|
||||
void prepare(std::function<void()> fn);
|
||||
|
||||
void retryAllPending();
|
||||
// Call this when the network status reachability changed.
|
||||
void setReachability(bool reachable);
|
||||
|
||||
private:
|
||||
std::thread::id thread_id;
|
||||
|
||||
@@ -21,7 +21,6 @@ public:
|
||||
virtual void setBase(const std::string &value) = 0;
|
||||
virtual std::unique_ptr<Request> request(ResourceType type, const std::string &url) = 0;
|
||||
virtual void prepare(std::function<void()> fn) = 0;
|
||||
virtual void retryAllPending() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Submodule ios/mapbox-gl-cocoa updated: 7e16edebf0...cf7436759f
@@ -76,7 +76,7 @@ int main() {
|
||||
GLFWView view;
|
||||
mbgl::CachingHTTPFileSource fileSource(mbgl::platform::defaultCacheDatabase());
|
||||
mbgl::Map map(view, fileSource);
|
||||
mbgl::Map *map_ptr = ↦
|
||||
mbgl::CachingHTTPFileSource *fileSourcePtr = &fileSource;
|
||||
|
||||
URLHandler *handler = [[URLHandler alloc] init];
|
||||
[handler setMap:&map];
|
||||
@@ -86,7 +86,7 @@ int main() {
|
||||
// Notify map object when network reachability status changes.
|
||||
Reachability* reachability = [Reachability reachabilityForInternetConnection];
|
||||
reachability.reachableBlock = ^(Reachability *) {
|
||||
map_ptr->setReachability(true);
|
||||
fileSourcePtr->setReachability(true);
|
||||
};
|
||||
[reachability startNotifier];
|
||||
|
||||
|
||||
@@ -286,15 +286,6 @@ void Map::terminate() {
|
||||
painter->terminate();
|
||||
}
|
||||
|
||||
void Map::setReachability(bool reachable) {
|
||||
// Note: This function may be called from *any* thread.
|
||||
if (reachable) {
|
||||
fileSource.prepare([&]() {
|
||||
fileSource.retryAllPending();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Setup
|
||||
|
||||
void Map::setup() {
|
||||
|
||||
@@ -100,16 +100,17 @@ void CachingHTTPFileSource::prepare(std::function<void()> fn) {
|
||||
}
|
||||
}
|
||||
|
||||
void CachingHTTPFileSource::retryAllPending() {
|
||||
assert(thread_id == std::this_thread::get_id());
|
||||
|
||||
util::ptr<BaseRequest> req;
|
||||
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
|
||||
if ((req = pair.second.lock())) {
|
||||
req->retryImmediately();
|
||||
}
|
||||
void CachingHTTPFileSource::setReachability(bool reachable) {
|
||||
if (reachable && loop) {
|
||||
prepare([this]() {
|
||||
util::ptr<BaseRequest> req;
|
||||
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
|
||||
if ((req = pair.second.lock())) {
|
||||
req->retryImmediately();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user