diff options
-rw-r--r-- | platform/default/local_file_source.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/storage/local_file_source.hpp | 5 |
2 files changed, 15 insertions, 7 deletions
diff --git a/platform/default/local_file_source.cpp b/platform/default/local_file_source.cpp index 93b42f5fa0..9d84764433 100644 --- a/platform/default/local_file_source.cpp +++ b/platform/default/local_file_source.cpp @@ -1,7 +1,8 @@ #include <mbgl/storage/local_file_source.hpp> +#include <mbgl/storage/file_source_request.hpp> #include <mbgl/storage/response.hpp> #include <mbgl/util/string.hpp> -#include <mbgl/util/thread.hpp> +#include <mbgl/util/threaded_object.hpp> #include <mbgl/util/url.hpp> #include <mbgl/util/util.hpp> #include <mbgl/util/io.hpp> @@ -21,7 +22,9 @@ namespace mbgl { class LocalFileSource::Impl { public: - void request(const std::string& url, FileSource::Callback callback) { + Impl(ActorRef<Impl>) {} + + void request(const std::string& url, ActorRef<FileSourceRequest> req) { // Cut off the protocol std::string path = mbgl::util::percentDecode(url.substr(protocolLength)); @@ -44,19 +47,23 @@ public: } } - callback(response); + req.invoke(&FileSourceRequest::setResponse, response); } }; LocalFileSource::LocalFileSource() - : thread(std::make_unique<util::Thread<Impl>>(util::ThreadContext{"LocalFileSource", util::ThreadPriority::Low})) { + : impl(std::make_unique<util::ThreadedObject<Impl>>("LocalFileSource")) { } LocalFileSource::~LocalFileSource() = default; std::unique_ptr<AsyncRequest> LocalFileSource::request(const Resource& resource, Callback callback) { - return thread->invokeWithCallback(&Impl::request, resource.url, callback); + auto req = std::make_unique<FileSourceRequest>(std::move(callback)); + + impl->actor().invoke(&Impl::request, resource.url, req->actor()); + + return std::move(req); } bool LocalFileSource::acceptsURL(const std::string& url) { diff --git a/src/mbgl/storage/local_file_source.hpp b/src/mbgl/storage/local_file_source.hpp index 43319bc06e..1e785379c0 100644 --- a/src/mbgl/storage/local_file_source.hpp +++ b/src/mbgl/storage/local_file_source.hpp @@ -5,7 +5,7 @@ namespace mbgl { namespace util { -template <typename T> class Thread; +template <typename T> class ThreadedObject; } // namespace util class LocalFileSource : public FileSource { @@ -19,7 +19,8 @@ public: private: class Impl; - std::unique_ptr<util::Thread<Impl>> thread; + + std::unique_ptr<util::ThreadedObject<Impl>> impl; }; } // namespace mbgl |