summaryrefslogtreecommitdiff
path: root/platform/glfw/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/glfw/main.cpp')
-rw-r--r--platform/glfw/main.cpp44
1 files changed, 31 insertions, 13 deletions
diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp
index 8f134804f0..ded8ee3e1f 100644
--- a/platform/glfw/main.cpp
+++ b/platform/glfw/main.cpp
@@ -3,13 +3,14 @@
#include "settings_json.hpp"
#include <mbgl/gfx/backend.hpp>
+#include <mbgl/renderer/renderer.hpp>
+#include <mbgl/storage/database_file_source.hpp>
+#include <mbgl/storage/file_source_manager.hpp>
+#include <mbgl/style/style.hpp>
#include <mbgl/util/default_styles.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/platform.hpp>
#include <mbgl/util/string.hpp>
-#include <mbgl/storage/default_file_source.hpp>
-#include <mbgl/style/style.hpp>
-#include <mbgl/renderer/renderer.hpp>
#include <args.hxx>
@@ -106,10 +107,16 @@ int main(int argc, char *argv[]) {
mbgl::ResourceOptions resourceOptions;
resourceOptions.withCachePath(cacheDB).withAccessToken(token);
- auto fileSource = std::static_pointer_cast<mbgl::DefaultFileSource>(mbgl::FileSource::getSharedFileSource(resourceOptions));
+ auto onlineFileSource =
+ mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Network, resourceOptions);
if (!settings.online) {
- fileSource->setOnlineStatus(false);
- mbgl::Log::Warning(mbgl::Event::Setup, "Application is offline. Press `O` to toggle online status.");
+ if (onlineFileSource) {
+ onlineFileSource->setProperty("online-status", false);
+ mbgl::Log::Warning(mbgl::Event::Setup, "Application is offline. Press `O` to toggle online status.");
+ } else {
+ mbgl::Log::Warning(mbgl::Event::Setup,
+ "Network resource provider is not available, only local requests are supported.");
+ }
}
GLFWRendererFrontend rendererFrontend { std::make_unique<mbgl::Renderer>(view->getRendererBackend(), view->getPixelRatio()), *view };
@@ -132,9 +139,14 @@ int main(int argc, char *argv[]) {
if (testDirValue) view->setTestDirectory(args::get(testDirValue));
- view->setOnlineStatusCallback([&settings, fileSource]() {
+ view->setOnlineStatusCallback([&settings, onlineFileSource]() {
+ if (!onlineFileSource) {
+ mbgl::Log::Warning(mbgl::Event::Setup,
+ "Cannot change online status. Network resource provider is not available.");
+ return;
+ }
settings.online = !settings.online;
- fileSource->setOnlineStatus(settings.online);
+ onlineFileSource->setProperty("online-status", settings.online);
mbgl::Log::Info(mbgl::Event::Setup, "Application is %s. Press `O` to toggle online status.", settings.online ? "online" : "offline");
});
@@ -152,20 +164,26 @@ int main(int argc, char *argv[]) {
mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.name);
});
- view->setPauseResumeCallback([fileSource] () {
+ // Resource loader controls top-level request processing and can resume / pause all managed sources simultaneously.
+ auto resourceLoader =
+ mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::ResourceLoader, resourceOptions);
+ view->setPauseResumeCallback([resourceLoader]() {
static bool isPaused = false;
if (isPaused) {
- fileSource->resume();
+ resourceLoader->resume();
} else {
- fileSource->pause();
+ resourceLoader->pause();
}
isPaused = !isPaused;
});
- view->setResetCacheCallback([fileSource] () {
- fileSource->resetDatabase([](std::exception_ptr ex) {
+ // Database file source.
+ auto databaseFileSource = std::static_pointer_cast<mbgl::DatabaseFileSource>(
+ mbgl::FileSourceManager::get()->getFileSource(mbgl::FileSourceType::Database, resourceOptions));
+ view->setResetCacheCallback([databaseFileSource]() {
+ databaseFileSource->resetDatabase([](std::exception_ptr ex) {
if (ex) {
mbgl::Log::Error(mbgl::Event::Database, "Failed to reset cache:: %s", mbgl::util::toString(ex).c_str());
}