[core] Convert AssetFileSource to ThreadedObject
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include <mbgl/storage/asset_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>
|
||||
@@ -14,11 +15,11 @@ namespace mbgl {
|
||||
|
||||
class AssetFileSource::Impl {
|
||||
public:
|
||||
Impl(std::string root_)
|
||||
Impl(ActorRef<Impl>, std::string root_)
|
||||
: root(std::move(root_)) {
|
||||
}
|
||||
|
||||
void request(const std::string& url, FileSource::Callback callback) {
|
||||
void request(const std::string& url, ActorRef<FileSourceRequest> req) {
|
||||
std::string path;
|
||||
|
||||
if (url.size() <= 8 || url[8] == '/') {
|
||||
@@ -48,7 +49,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
callback(response);
|
||||
req.invoke(&FileSourceRequest::setResponse, response);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -56,15 +57,17 @@ private:
|
||||
};
|
||||
|
||||
AssetFileSource::AssetFileSource(const std::string& root)
|
||||
: thread(std::make_unique<util::Thread<Impl>>(
|
||||
util::ThreadContext{"AssetFileSource", util::ThreadPriority::Low},
|
||||
root)) {
|
||||
: impl(std::make_unique<util::ThreadedObject<Impl>>("AssetFileSource", root)) {
|
||||
}
|
||||
|
||||
AssetFileSource::~AssetFileSource() = default;
|
||||
|
||||
std::unique_ptr<AsyncRequest> AssetFileSource::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);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user