From 169755e89a72b103fab100ccd101013e8eef1481 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 23 Mar 2016 17:31:14 -0700 Subject: [core] Unify FileRequest and WorkRequest --- include/mbgl/storage/default_file_source.hpp | 2 +- include/mbgl/storage/file_source.hpp | 10 +++------- include/mbgl/storage/online_file_source.hpp | 2 +- include/mbgl/util/async_request.hpp | 12 ++++++++++++ include/mbgl/util/run_loop.hpp | 4 ++-- include/mbgl/util/work_request.hpp | 6 +++--- 6 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 include/mbgl/util/async_request.hpp (limited to 'include/mbgl') diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp index dd67cff9b8..76d60fce70 100644 --- a/include/mbgl/storage/default_file_source.hpp +++ b/include/mbgl/storage/default_file_source.hpp @@ -30,7 +30,7 @@ public: void setAccessToken(const std::string&); std::string getAccessToken() const; - std::unique_ptr request(const Resource&, Callback) override; + std::unique_ptr request(const Resource&, Callback) override; /* * Retrieve all regions in the offline database. diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp index 8d08315cd9..e572776af2 100644 --- a/include/mbgl/storage/file_source.hpp +++ b/include/mbgl/storage/file_source.hpp @@ -5,17 +5,13 @@ #include #include +#include #include #include namespace mbgl { -class FileRequest : private util::noncopyable { -public: - virtual ~FileRequest() = default; -}; - class FileSource : private util::noncopyable { public: virtual ~FileSource() = default; @@ -24,10 +20,10 @@ public: // Request a resource. The callback will be called asynchronously, in the same // thread as the request was made. This thread must have an active RunLoop. The - // request may be cancelled before completion by releasing the returned FileRequest. + // request may be cancelled before completion by releasing the returned AsyncRequest. // If the request is cancelled before the callback is executed, the callback will // not be executed. - virtual std::unique_ptr request(const Resource&, Callback) = 0; + virtual std::unique_ptr request(const Resource&, Callback) = 0; }; } // namespace mbgl diff --git a/include/mbgl/storage/online_file_source.hpp b/include/mbgl/storage/online_file_source.hpp index aceb141fb4..b52dce35f0 100644 --- a/include/mbgl/storage/online_file_source.hpp +++ b/include/mbgl/storage/online_file_source.hpp @@ -17,7 +17,7 @@ public: void setAccessToken(const std::string& t) { accessToken = t; } std::string getAccessToken() const { return accessToken; } - std::unique_ptr request(const Resource&, Callback) override; + std::unique_ptr request(const Resource&, Callback) override; private: friend class OnlineFileRequestImpl; diff --git a/include/mbgl/util/async_request.hpp b/include/mbgl/util/async_request.hpp new file mode 100644 index 0000000000..9e85094966 --- /dev/null +++ b/include/mbgl/util/async_request.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace mbgl { + +class AsyncRequest : private util::noncopyable { +public: + virtual ~AsyncRequest() = default; +}; + +} // namespace mbgl diff --git a/include/mbgl/util/run_loop.hpp b/include/mbgl/util/run_loop.hpp index fbc4794940..4e25caf554 100644 --- a/include/mbgl/util/run_loop.hpp +++ b/include/mbgl/util/run_loop.hpp @@ -58,7 +58,7 @@ public: // Post the cancellable work fn(args...) to this RunLoop. template - std::unique_ptr + std::unique_ptr invokeCancellable(Fn&& fn, Args&&... args) { auto flag = std::make_shared>(); *flag = false; @@ -76,7 +76,7 @@ public: // Invoke fn(args...) on this RunLoop, then invoke callback(results...) on the current RunLoop. template - std::unique_ptr + std::unique_ptr invokeWithCallback(Fn&& fn, Cb&& callback, Args&&... args) { auto flag = std::make_shared>(); *flag = false; diff --git a/include/mbgl/util/work_request.hpp b/include/mbgl/util/work_request.hpp index bd1d97ee70..f24e4b2e9f 100644 --- a/include/mbgl/util/work_request.hpp +++ b/include/mbgl/util/work_request.hpp @@ -1,7 +1,7 @@ #ifndef MBGL_UTIL_WORK_REQUEST #define MBGL_UTIL_WORK_REQUEST -#include +#include #include @@ -9,11 +9,11 @@ namespace mbgl { class WorkTask; -class WorkRequest : public util::noncopyable { +class WorkRequest : public AsyncRequest { public: using Task = std::shared_ptr; WorkRequest(Task); - ~WorkRequest(); + ~WorkRequest() override; private: std::shared_ptr task; -- cgit v1.2.1