diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-04-17 15:23:36 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-04-17 15:23:36 +0200 |
commit | 9072df709d30ed0ed2c913482e1e6bae6a3d5dd5 (patch) | |
tree | 4db146c25b77fb118e732118ca021859752cc076 /include | |
parent | 60a0e8a4be53801bbcb5598000ec7fc32d3a29c6 (diff) | |
download | qtlocation-mapboxgl-9072df709d30ed0ed2c913482e1e6bae6a3d5dd5.tar.gz |
make the request header public as the node module requires it
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/storage/request.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp new file mode 100644 index 0000000000..00157329be --- /dev/null +++ b/include/mbgl/storage/request.hpp @@ -0,0 +1,60 @@ +#ifndef MBGL_STORAGE_DEFAULT_REQUEST +#define MBGL_STORAGE_DEFAULT_REQUEST + +#include <mbgl/storage/resource.hpp> + +#include <mbgl/util/util.hpp> +#include <mbgl/util/noncopyable.hpp> + +#include <mutex> +#include <thread> +#include <functional> +#include <memory> + +typedef struct uv_async_s uv_async_t; +typedef struct uv_loop_s uv_loop_t; + +namespace mbgl { + +class Response; +class Environment; + +class Request : private util::noncopyable { + MBGL_STORE_THREAD(tid) + +public: + using Callback = std::function<void(const Response &)>; + Request(const Resource &resource, uv_loop_t *loop, const Environment &env, Callback callback); + +public: + // May be called from any thread. + void notify(const std::shared_ptr<const Response> &response); + void destruct(); + + // May be called only from the thread the Request was created in. + void cancel(); + +private: + ~Request(); + void invoke(); + void notifyCallback(); + +private: + uv_async_t *async = nullptr; + struct Canceled; + std::unique_ptr<Canceled> canceled; + Callback callback; + std::shared_ptr<const Response> response; + +public: + const Resource resource; + + // The environment ref is used to associate requests with a particular environment. This allows + // us to only terminate requests associated with that environment, e.g. when the map the env + // belongs to is discarded. + const Environment &env; +}; + +} + +#endif |