diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-09-25 21:35:04 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2017-09-28 13:48:36 -0400 |
commit | 64c75b442c4d387e4867757abf49462c561e5955 (patch) | |
tree | 63f572961f6309a851d2e85ebe191e6a3cb7e5ab /platform/default/file_source_request.cpp | |
parent | d73e33eb62858b91212314d97bfe9cf49e857141 (diff) | |
download | qtlocation-mapboxgl-64c75b442c4d387e4867757abf49462c561e5955.tar.gz |
[build] split out DefaultFileSource and dependents to a separate target
We don't want to link it into the node bindings, so keep it in a separate target
Diffstat (limited to 'platform/default/file_source_request.cpp')
-rw-r--r-- | platform/default/file_source_request.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/platform/default/file_source_request.cpp b/platform/default/file_source_request.cpp new file mode 100644 index 0000000000..09ea8cc32a --- /dev/null +++ b/platform/default/file_source_request.cpp @@ -0,0 +1,37 @@ +#include <mbgl/storage/file_source_request.hpp> + +#include <mbgl/actor/mailbox.hpp> +#include <mbgl/actor/scheduler.hpp> + +namespace mbgl { + +FileSourceRequest::FileSourceRequest(FileSource::Callback&& callback) + : responseCallback(callback) + , mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())) { +} + +FileSourceRequest::~FileSourceRequest() { + if (cancelCallback) { + cancelCallback(); + } + + mailbox->close(); +} + +void FileSourceRequest::onCancel(std::function<void()>&& callback) { + cancelCallback = std::move(callback); +} + +void FileSourceRequest::setResponse(const Response& response) { + // Copy, because calling the callback will sometimes self + // destroy this object. We cannot move because this method + // can be called more than one. + auto callback = responseCallback; + callback(response); +} + +ActorRef<FileSourceRequest> FileSourceRequest::actor() { + return ActorRef<FileSourceRequest>(*this, mailbox); +} + +} // namespace mbgl |