diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-09-17 12:10:08 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-09-24 16:14:10 +0200 |
commit | 89cd310cf6117586701b1e72fe7c2bf0fbd760db (patch) | |
tree | dbcab2bfec7d3b446c57f6811810feae16118850 /include | |
parent | fd2b2e208229259630f92bd7615f9197c163d27f (diff) | |
download | qtlocation-mapboxgl-89cd310cf6117586701b1e72fe7c2bf0fbd760db.tar.gz |
notifications on request cancellation
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/storage/base_request.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/storage/request.hpp | 6 | ||||
-rw-r--r-- | include/mbgl/storage/request_callback.hpp | 22 |
3 files changed, 26 insertions, 6 deletions
diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp index c903742f4b..832ecbc23d 100644 --- a/include/mbgl/storage/base_request.hpp +++ b/include/mbgl/storage/base_request.hpp @@ -1,6 +1,7 @@ #ifndef MBGL_STORAGE_BASE_REQUEST #define MBGL_STORAGE_BASE_REQUEST +#include <mbgl/storage/request_callback.hpp> #include <mbgl/util/ptr.hpp> #include <string> @@ -15,8 +16,6 @@ namespace mbgl { class Response; class Request; -using Callback = std::function<void(const Response &)>; - class BaseRequest { private: @@ -43,7 +42,6 @@ private: // 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; }; diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp index 10c938ed15..e603ee527a 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -1,10 +1,10 @@ #ifndef MBGL_STORAGE_REQUEST #define MBGL_STORAGE_REQUEST +#include <mbgl/storage/request_callback.hpp> #include <mbgl/storage/response.hpp> #include <mbgl/util/ptr.hpp> -#include <functional> #include <forward_list> typedef struct uv_loop_s uv_loop_t; @@ -12,7 +12,6 @@ typedef struct uv_loop_s uv_loop_t; namespace mbgl { class BaseRequest; -using Callback = std::function<void(const Response &)>; class Request { private: @@ -25,7 +24,8 @@ public: Request(const util::ptr<BaseRequest> &base); ~Request(); - void onload(Callback cb); + void onload(CompletedCallback cb); + void oncancel(AbortedCallback cb); void cancel(); private: diff --git a/include/mbgl/storage/request_callback.hpp b/include/mbgl/storage/request_callback.hpp new file mode 100644 index 0000000000..01427bd96d --- /dev/null +++ b/include/mbgl/storage/request_callback.hpp @@ -0,0 +1,22 @@ +#ifndef MBGL_STORAGE_REQUEST_CALLBACK +#define MBGL_STORAGE_REQUEST_CALLBACK + +#include <mbgl/util/variant.hpp> + +#include <functional> + +namespace mbgl { + +class Response; + +using CompletedCallback = std::function<void(const Response &)>; +using AbortedCallback = std::function<void()>; + +using Callback = mapbox::util::variant< + CompletedCallback, + AbortedCallback +>; + +} + +#endif |