Commit a6bc51af authored by Paweł Wegner's avatar Paweł Wegner

Added MoveItemRequest.

parent fd17b173
......@@ -35,6 +35,7 @@
#include "Request/GetItemDataRequest.h"
#include "Request/GetItemRequest.h"
#include "Request/ListDirectoryRequest.h"
#include "Request/MoveItemRequest.h"
#include "Request/UploadFileRequest.h"
using namespace std::placeholders;
......@@ -192,6 +193,13 @@ CloudProvider::createDirectoryAsync(IItem::Pointer parent,
shared_from_this(), parent, name, callback);
}
ICloudProvider::MoveItemRequest::Pointer CloudProvider::moveItemAsync(
IItem::Pointer source, IItem::Pointer destination,
MoveItemCallback callback) {
return make_unique<cloudstorage::MoveItemRequest>(shared_from_this(), source,
destination, callback);
}
HttpRequest::Pointer CloudProvider::getItemDataRequest(const std::string&,
std::ostream&) const {
return nullptr;
......@@ -232,6 +240,11 @@ HttpRequest::Pointer CloudProvider::createDirectoryRequest(
return nullptr;
}
HttpRequest::Pointer CloudProvider::moveItemRequest(const IItem&, const IItem&,
std::ostream&) const {
return nullptr;
}
IItem::Pointer CloudProvider::getItemDataResponse(std::istream&) const {
return nullptr;
}
......
......@@ -75,6 +75,9 @@ class CloudProvider : public ICloudProvider,
CreateDirectoryRequest::Pointer createDirectoryAsync(IItem::Pointer parent,
const std::string& name,
CreateDirectoryCallback);
MoveItemRequest::Pointer moveItemAsync(IItem::Pointer source,
IItem::Pointer destination,
MoveItemCallback);
virtual HttpRequest::Pointer getItemDataRequest(
const std::string& id, std::ostream& input_stream) const;
......@@ -93,6 +96,9 @@ class CloudProvider : public ICloudProvider,
virtual HttpRequest::Pointer createDirectoryRequest(const IItem&,
const std::string&,
std::ostream&) const;
virtual HttpRequest::Pointer moveItemRequest(const IItem& source,
const IItem& destination,
std::ostream&) const;
virtual IItem::Pointer getItemDataResponse(std::istream& response) const;
virtual std::vector<IItem::Pointer> listDirectoryResponse(
......
......@@ -46,6 +46,7 @@ class ICloudProvider {
using GetItemDataRequest = IRequest<IItem::Pointer>;
using DeleteItemRequest = IRequest<bool>;
using CreateDirectoryRequest = IRequest<IItem::Pointer>;
using MoveItemRequest = IRequest<bool>;
class ICallback {
public:
......@@ -89,6 +90,9 @@ class ICloudProvider {
virtual CreateDirectoryRequest::Pointer createDirectoryAsync(
IItem::Pointer parent, const std::string& name,
CreateDirectoryCallback) = 0;
virtual MoveItemRequest::Pointer moveItemAsync(IItem::Pointer source,
IItem::Pointer destination,
MoveItemCallback) = 0;
};
} // namespace cloudstorage
......
......@@ -83,6 +83,7 @@ using GetItemCallback = std::function<void(IItem::Pointer)>;
using GetItemDataCallback = std::function<void(IItem::Pointer)>;
using DeleteItemCallback = std::function<void(bool)>;
using CreateDirectoryCallback = std::function<void(IItem::Pointer)>;
using MoveItemCallback = std::function<void(bool)>;
} // namespace cloudstorage
......
......@@ -33,7 +33,8 @@ libcloudstorage_la_SOURCES = \
Request/UploadFileRequest.cpp \
Request/GetItemDataRequest.cpp \
Request/DeleteItemRequest.cpp \
Request/CreateDirectoryRequest.cpp
Request/CreateDirectoryRequest.cpp \
Request/MoveItemRequest.cpp
noinst_HEADERS = \
IAuth.h \
......@@ -58,7 +59,8 @@ noinst_HEADERS = \
Request/ListDirectoryRequest.h \
Request/UploadFileRequest.h \
Request/DeleteItemRequest.h \
Request/CreateDirectoryRequest.h
Request/CreateDirectoryRequest.h \
Request/MoveItemRequest.h
nobase_include_HEADERS = \
IItem.h \
......
/*****************************************************************************
* MoveItemRequest.cpp : MoveItemRequest implementation
*
*****************************************************************************
* Copyright (C) 2016-2016 VideoLAN
*
* Authors: Paweł Wegner <pawel.wegner95@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "MoveItemRequest.h"
#include "CloudProvider/CloudProvider.h"
namespace cloudstorage {
MoveItemRequest::MoveItemRequest(std::shared_ptr<CloudProvider> p,
IItem::Pointer source,
IItem::Pointer destination,
MoveItemCallback callback)
: Request(p) {
set_resolver([=](Request<bool>* r) {
std::stringstream output;
int code = r->sendRequest(
[=](std::ostream& stream) {
return p->moveItemRequest(*source, *destination, stream);
},
output);
callback(HttpRequest::isSuccess(code));
return HttpRequest::isSuccess(code);
});
}
MoveItemRequest::~MoveItemRequest() { cancel(); }
} // namespace cloudstorage
/*****************************************************************************
* MoveItemRequest.h : MoveItemRequest headers
*
*****************************************************************************
* Copyright (C) 2016-2016 VideoLAN
*
* Authors: Paweł Wegner <pawel.wegner95@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef MOVEITEMREQUEST_H
#define MOVEITEMREQUEST_H
#include "Request.h"
namespace cloudstorage {
class MoveItemRequest : public Request<bool> {
public:
MoveItemRequest(std::shared_ptr<CloudProvider>, IItem::Pointer source,
IItem::Pointer destination, MoveItemCallback);
~MoveItemRequest();
};
} // namespace cloudstorage
#endif // MOVEITEMREQUEST_H
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