diff options
author | Mike Morris <michael.patrick.morris@gmail.com> | 2015-09-02 15:46:43 -0400 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2015-09-02 15:46:43 -0400 |
commit | 322e1aa2c3c2570554a2fe2bbfa733ab7bbd4e81 (patch) | |
tree | c6d665f13f1342b8a5adaff14a7a676a6b0c4a85 /platform/node/src/node_file_source.hpp | |
parent | 6929dcec966c5c9eb2f2409fb4568f55253116f9 (diff) | |
parent | 6634adee398c7e84c0892042751fa299546a9965 (diff) | |
download | qtlocation-mapboxgl-322e1aa2c3c2570554a2fe2bbfa733ab7bbd4e81.tar.gz |
Merge pull request #2179 from mapbox/node
Node bindings
Diffstat (limited to 'platform/node/src/node_file_source.hpp')
-rw-r--r-- | platform/node/src/node_file_source.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/platform/node/src/node_file_source.hpp b/platform/node/src/node_file_source.hpp new file mode 100644 index 0000000000..f412bdee16 --- /dev/null +++ b/platform/node/src/node_file_source.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include <mbgl/storage/file_source.hpp> + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic ignored "-Wshadow" +#include <node.h> +#include <node_version.h> +#include <nan.h> +#pragma GCC diagnostic pop + +#include <memory> +#include <mutex> +#include <unordered_map> + +namespace node_mbgl { + +namespace util { template <typename T> class AsyncQueue; } + +class NodeFileSource : public mbgl::FileSource { +public: + NodeFileSource(v8::Handle<v8::Object>); + ~NodeFileSource(); + + mbgl::Request* request(const mbgl::Resource&, uv_loop_t*, Callback); + void cancel(mbgl::Request*); + + // visiblity? + void notify(const mbgl::Resource&, const std::shared_ptr<const mbgl::Response>&); + +private: + struct Action; + using Queue = util::AsyncQueue<Action>; + + void processAdd(const mbgl::Resource&); + void processCancel(const mbgl::Resource&); + + v8::Persistent<v8::Object> options; + +private: +#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) + std::unordered_map<mbgl::Resource, v8::Persistent<v8::Object, v8::CopyablePersistentTraits<v8::Object>>, mbgl::Resource::Hash> pending; +#else + std::unordered_map<mbgl::Resource, v8::Persistent<v8::Object>, mbgl::Resource::Hash> pending; +#endif + + // The observers list will hold pointers to all the requests waiting + // for a particular resource. The access must be guarded by a mutex + // because the list is also accessed by a thread from the mbgl::Map + // object and from the main thread when notifying requests of + // completion. Concurrent access is specially needed when + // canceling a request to avoid a deadlock (see #129). + std::unordered_map<mbgl::Resource, mbgl::Request*, mbgl::Resource::Hash> observers; + std::mutex observersMutex; + + Queue *queue = nullptr; +}; + +} |