summaryrefslogtreecommitdiff
path: root/platform/node/src/node_request.hpp
blob: 356566132b7803c9f38d16422b983a448b7b232a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#include <nan.h>
#pragma GCC diagnostic pop

#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/async_task.hpp>

#include <memory>

namespace node_mbgl {

class NodeMap;

class NodeRequest : public Nan::ObjectWrap,
                    public Nan::AsyncWorker {
public:
    struct NodeAsyncRequest : public mbgl::AsyncRequest {
        NodeAsyncRequest(NodeRequest*);
        ~NodeAsyncRequest() override;
        NodeRequest* request;
    };

    NodeRequest(NodeMap*, mbgl::FileSource::Callback);
    ~NodeRequest();

    static Nan::Persistent<v8::Function> constructor;

    static void Init();

    static void New(const Nan::FunctionCallbackInfo<v8::Value>&);
    static void HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>&);

    void Execute();

private:
    void doExecute();

    NodeMap* target;
    mbgl::FileSource::Callback callback;
    NodeAsyncRequest* asyncRequest = nullptr;
    std::unique_ptr<mbgl::util::AsyncTask> asyncExecute;
};

}