Commit 86c03fa5 authored by Paweł Wegner's avatar Paweł Wegner

IRequest: introduced IGenericCallback.

parent ccdf9f62
......@@ -27,6 +27,7 @@
#include <chrono>
#include <memory>
#include <string>
#include <vector>
namespace cloudstorage {
......@@ -34,6 +35,7 @@ class IItem {
public:
using Pointer = std::shared_ptr<IItem>;
using TimeStamp = std::chrono::system_clock::time_point;
using List = std::vector<IItem::Pointer>;
static constexpr size_t UnknownSize = -1;
static const TimeStamp UnknownTimeStamp;
......
......@@ -48,7 +48,7 @@ struct GeneralData {
};
struct PageData {
std::vector<IItem::Pointer> items_;
IItem::List items_;
std::string next_token_; // empty if no next page
};
......@@ -99,11 +99,20 @@ class IRequest : public IGenericRequest {
virtual ReturnValue result() = 0;
};
class IListDirectoryCallback {
template <class... Arguments>
class IGenericCallback {
public:
using Pointer = std::shared_ptr<IListDirectoryCallback>;
using Pointer = std::shared_ptr<IGenericCallback>;
virtual ~IGenericCallback() = default;
virtual ~IListDirectoryCallback() = default;
virtual void done(Arguments... args) = 0;
};
class IListDirectoryCallback
: public IGenericCallback<EitherError<IItem::List>> {
public:
using Pointer = std::shared_ptr<IListDirectoryCallback>;
/**
* Called when directory's child was fetched.
......@@ -111,21 +120,12 @@ class IListDirectoryCallback {
* @param item fetched item
*/
virtual void receivedItem(IItem::Pointer item) = 0;
/**
* Called when the request was successfully finished.
*
* @param result contains all retrieved children
*/
virtual void done(EitherError<std::vector<IItem::Pointer>>) = 0;
};
class IDownloadFileCallback {
class IDownloadFileCallback : public IGenericCallback<EitherError<void>> {
public:
using Pointer = std::shared_ptr<IDownloadFileCallback>;
virtual ~IDownloadFileCallback() = default;
/**
* Called when received a part of file.
*
......@@ -134,11 +134,6 @@ class IDownloadFileCallback {
*/
virtual void receivedData(const char* data, uint32_t length) = 0;
/**
* Called when the download has finished.
*/
virtual void done(EitherError<void>) = 0;
/**
* Called when progress has changed.
*
......@@ -148,12 +143,10 @@ class IDownloadFileCallback {
virtual void progress(uint64_t total, uint64_t now) = 0;
};
class IUploadFileCallback {
class IUploadFileCallback : public IGenericCallback<EitherError<IItem>> {
public:
using Pointer = std::shared_ptr<IUploadFileCallback>;
virtual ~IUploadFileCallback() = default;
/**
* Called when upload starts, can be also called when retransmission is
* required due to network issues.
......@@ -174,11 +167,6 @@ class IUploadFileCallback {
*/
virtual uint64_t size() = 0;
/**
* Called when the upload is finished sucessfully.
*/
virtual void done(EitherError<IItem>) = 0;
/**
* Called when upload progress changed.
*
......@@ -233,8 +221,7 @@ using CreateDirectoryCallback = std::function<void(EitherError<IItem>)>;
using MoveItemCallback = std::function<void(EitherError<IItem>)>;
using RenameItemCallback = std::function<void(EitherError<IItem>)>;
using ListDirectoryPageCallback = std::function<void(EitherError<PageData>)>;
using ListDirectoryCallback =
std::function<void(EitherError<std::vector<IItem::Pointer>>)>;
using ListDirectoryCallback = std::function<void(EitherError<IItem::List>)>;
using DownloadFileCallback = std::function<void(EitherError<void>)>;
using UploadFileCallback = std::function<void(EitherError<IItem>)>;
using GetThumbnailCallback = std::function<void(EitherError<void>)>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment