summaryrefslogtreecommitdiff
path: root/include/mbgl/storage/base_request.hpp
diff options
context:
space:
mode:
authorMike Morris <michael.patrick.morris@gmail.com>2014-10-10 12:24:45 -0400
committerMike Morris <michael.patrick.morris@gmail.com>2014-10-10 12:24:45 -0400
commit2d1219fa5154c489cd856bedd04b84573d45ac04 (patch)
treea8e42e6acd79f73aac228e0fe6876917067db8c4 /include/mbgl/storage/base_request.hpp
parent8f6e8eead12c6b2c2de0ce76fa7df39ca2445006 (diff)
parentf390dab0ea7d449bdd89855c84e47f4a07606fe4 (diff)
downloadqtlocation-mapboxgl-2d1219fa5154c489cd856bedd04b84573d45ac04.tar.gz
Merge branch 'master' into libuv-0.10-headless-display
Conflicts: common/curl_request.cpp common/glfw_view.cpp common/glfw_view.hpp include/mbgl/platform/request.hpp ios/mapbox-gl-cocoa setup-libraries.sh src/map/map.cpp src/platform/request.cpp test/fixtures/fixture_request.cpp
Diffstat (limited to 'include/mbgl/storage/base_request.hpp')
-rw-r--r--include/mbgl/storage/base_request.hpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp
new file mode 100644
index 0000000000..16ff24faa3
--- /dev/null
+++ b/include/mbgl/storage/base_request.hpp
@@ -0,0 +1,62 @@
+#ifndef MBGL_STORAGE_BASE_REQUEST
+#define MBGL_STORAGE_BASE_REQUEST
+
+#include <mbgl/storage/request_callback.hpp>
+#include <mbgl/util/ptr.hpp>
+
+#include <string>
+#include <forward_list>
+#include <functional>
+
+
+typedef struct uv_loop_s uv_loop_t;
+typedef struct uv_async_s uv_async_t;
+
+namespace mbgl {
+
+class Response;
+class Request;
+
+class BaseRequest {
+private:
+ // Make noncopyable and immovable
+ BaseRequest(const BaseRequest &) = delete;
+ BaseRequest(BaseRequest &&) = delete;
+ BaseRequest& operator=(const BaseRequest &) = delete;
+ BaseRequest& operator=(BaseRequest &&) = delete;
+
+public:
+ BaseRequest(const std::string &path);
+ virtual ~BaseRequest();
+
+ Callback *add(Callback &&callback, const util::ptr<BaseRequest> &request);
+ void remove(Callback *callback);
+
+ // Must be called by subclasses when a valid Response object is available. It will notify
+ // all listeners.
+ void notify();
+
+ // This function is called when the request ought to be stopped. Any subclass must make sure this
+ // is also called in its destructor. Calling this function repeatedly must be safe.
+ // This function must call notify().
+ virtual void cancel() = 0;
+
+ // This function is called when the request should be reattempted immediately. This is typically
+ // reaction to a network status change.
+ virtual void retryImmediately();
+
+public:
+ const unsigned long thread_id;
+ const std::string path;
+ std::unique_ptr<Response> response;
+
+protected:
+ // This object may hold a shared_ptr to itself. It does this to prevent destruction of this object
+ // while a request is in progress.
+ util::ptr<BaseRequest> self;
+ std::forward_list<std::unique_ptr<Callback>> callbacks;
+};
+
+}
+
+#endif