1#include <mbgl/storage/file_source_request.hpp>
2
3#include <mbgl/actor/mailbox.hpp>
4#include <mbgl/actor/scheduler.hpp>
5
6namespace mbgl {
7
8FileSourceRequest::FileSourceRequest(FileSource::Callback&& callback)
9 : responseCallback(callback)
10 , mailbox(std::make_shared<Mailbox>(args&: *Scheduler::GetCurrent())) {
11}
12
13FileSourceRequest::~FileSourceRequest() {
14 if (cancelCallback) {
15 cancelCallback();
16 }
17
18 mailbox->close();
19}
20
21void FileSourceRequest::onCancel(std::function<void()>&& callback) {
22 cancelCallback = std::move(callback);
23}
24
25void FileSourceRequest::setResponse(const Response& response) {
26 // Copy, because calling the callback will sometimes self
27 // destroy this object. We cannot move because this method
28 // can be called more than one.
29 auto callback = responseCallback;
30 callback(response);
31}
32
33ActorRef<FileSourceRequest> FileSourceRequest::actor() {
34 return ActorRef<FileSourceRequest>(*this, mailbox);
35}
36
37} // namespace mbgl
38

source code of qtlocation/src/3rdparty/mapbox-gl-native/platform/default/file_source_request.cpp