summaryrefslogtreecommitdiff
path: root/platform/default/src/mbgl/storage/file_source_request.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-12-13 18:45:29 +0100
committerKonstantin Käfer <mail@kkaefer.com>2018-12-14 11:03:03 +0100
commit1d8235f5b899a2cd8414522b2d72b96fab91577b (patch)
tree2ab56dce064de872525db7f24ba150a9065c4757 /platform/default/src/mbgl/storage/file_source_request.cpp
parentc2a4a8822ce9577c972975da61034a30fb0fe3e9 (diff)
downloadqtlocation-mapboxgl-1d8235f5b899a2cd8414522b2d72b96fab91577b.tar.gz
[build] rework platform/default directory and add -files.txt for vendored libs
Diffstat (limited to 'platform/default/src/mbgl/storage/file_source_request.cpp')
-rw-r--r--platform/default/src/mbgl/storage/file_source_request.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/platform/default/src/mbgl/storage/file_source_request.cpp b/platform/default/src/mbgl/storage/file_source_request.cpp
new file mode 100644
index 0000000000..09ea8cc32a
--- /dev/null
+++ b/platform/default/src/mbgl/storage/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