#pragma once #include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wshadow" #include #include #include #pragma GCC diagnostic pop #include #include #include #include namespace node_mbgl { namespace util { template class AsyncQueue; } class NodeFileSource : public mbgl::FileSource { public: NodeFileSource(v8::Handle); ~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&); private: struct Action; using Queue = util::AsyncQueue; void processAdd(const mbgl::Resource&); void processCancel(const mbgl::Resource&); v8::Persistent options; private: #if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION) std::unordered_map>, mbgl::Resource::Hash> pending; #else std::unordered_map, mbgl::Resource::Hash> pending; #endif // The observers list will hold pointers to all the requests waiting // for a particular resource. It is also used for coalescing requests, // so we don't ask for the same resources twice. 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::Hash> observers; std::mutex observersMutex; Queue *queue = nullptr; }; }