1 | #include <mbgl/storage/file_source_request.hpp> |
---|---|
2 | |
3 | #include <mbgl/actor/mailbox.hpp> |
4 | #include <mbgl/actor/scheduler.hpp> |
5 | |
6 | namespace mbgl { |
7 | |
8 | FileSourceRequest::FileSourceRequest(FileSource::Callback&& callback) |
9 | : responseCallback(callback) |
10 | , mailbox(std::make_shared<Mailbox>(args&: *Scheduler::GetCurrent())) { |
11 | } |
12 | |
13 | FileSourceRequest::~FileSourceRequest() { |
14 | if (cancelCallback) { |
15 | cancelCallback(); |
16 | } |
17 | |
18 | mailbox->close(); |
19 | } |
20 | |
21 | void FileSourceRequest::onCancel(std::function<void()>&& callback) { |
22 | cancelCallback = std::move(callback); |
23 | } |
24 | |
25 | void 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 | |
33 | ActorRef<FileSourceRequest> FileSourceRequest::actor() { |
34 | return ActorRef<FileSourceRequest>(*this, mailbox); |
35 | } |
36 | |
37 | } // namespace mbgl |
38 |