notifications on request cancellation

This commit is contained in:
Konstantin Käfer
2014-09-17 12:10:08 +02:00
parent fd2b2e2082
commit 89cd310cf6
6 changed files with 68 additions and 21 deletions

View File

@@ -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;
};

View File

@@ -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:

View File

@@ -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