aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-31 19:18:06 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit0d0033fb6ad00e3081bc2854ce5972746b603105 (patch)
tree001f3f481609731d19dd5818e1789fa0d3a05faf
parent13351a730d79cc2f0d5b964226c69bb04e2c93c1 (diff)
downloadscummvm-rg350-0d0033fb6ad00e3081bc2854ce5972746b603105.tar.gz
scummvm-rg350-0d0033fb6ad00e3081bc2854ce5972746b603105.tar.bz2
scummvm-rg350-0d0033fb6ad00e3081bc2854ce5972746b603105.zip
CLOUD: Make syncSaves() common for all Storages
As it uses SavesSyncRequest and this request is using Storage's upload(), download() and listDirectory(), there is no need to make storage-dependent version of that request and so method could be implemented in base Storage.
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp14
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h6
-rw-r--r--backends/cloud/onedrive/onedrivestorage.cpp14
-rw-r--r--backends/cloud/onedrive/onedrivestorage.h6
-rw-r--r--backends/cloud/storage.cpp21
-rw-r--r--backends/cloud/storage.h11
6 files changed, 31 insertions, 41 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index beb510882a..1aae73e524 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -114,15 +114,6 @@ void DropboxStorage::printStorageFile(UploadResponse response) {
debug("\ttimestamp: %u", response.value.timestamp());
}
-void DropboxStorage::printErrorResponse(Networking::ErrorResponse error) {
- debug("error response (%s, %ld):", (error.failed ? "failed" : "interrupted"), error.httpResponseCode);
- debug("%s", error.response.c_str());
-}
-
-Networking::ErrorCallback DropboxStorage::getErrorPrintingCallback() {
- return new Common::Callback<DropboxStorage, Networking::ErrorResponse>(this, &DropboxStorage::printErrorResponse);
-}
-
Networking::Request *DropboxStorage::listDirectory(Common::String path, ListDirectoryCallback outerCallback, Networking::ErrorCallback errorCallback, bool recursive) {
return ConnMan.addRequest(new DropboxListDirectoryRequest(_token, path, outerCallback, errorCallback, recursive));
}
@@ -162,11 +153,6 @@ Networking::Request *DropboxStorage::downloadFolder(Common::String remotePath, C
return ConnMan.addRequest(new FolderDownloadRequest(this, callback, errorCallback, remotePath, localPath, recursive));
}
-Networking::Request *DropboxStorage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
- //this might be the real syncSaves() implementation
- return ConnMan.addRequest(new SavesSyncRequest(this, new Common::Callback<DropboxStorage, BoolResponse>(this, &DropboxStorage::printBool), getErrorPrintingCallback())); //TODO
-}
-
Networking::Request *DropboxStorage::info(StorageInfoCallback outerCallback, Networking::ErrorCallback errorCallback) {
Networking::JsonCallback innerCallback = new Common::CallbackBridge<DropboxStorage, StorageInfoResponse, Networking::JsonResponse>(this, &DropboxStorage::infoInnerCallback, outerCallback);
Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, errorCallback, "https://api.dropboxapi.com/1/account/info");
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index 90a1d270e8..7752dddf9b 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -48,9 +48,6 @@ class DropboxStorage: public Cloud::Storage {
void printFiles(FileArrayResponse response);
void printBool(BoolResponse response);
void printStorageFile(UploadResponse response);
- void printErrorResponse(Networking::ErrorResponse error);
-
- Networking::ErrorCallback getErrorPrintingCallback();
public:
virtual ~DropboxStorage();
@@ -89,9 +86,6 @@ public:
virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Calls the callback when finished. */
- virtual Networking::Request *syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback);
-
- /** Calls the callback when finished. */
virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Calls the callback when finished. */
diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp
index a16a351690..fb2ead3364 100644
--- a/backends/cloud/onedrive/onedrivestorage.cpp
+++ b/backends/cloud/onedrive/onedrivestorage.cpp
@@ -255,20 +255,6 @@ void OneDriveStorage::printFile(UploadResponse response) {
debug("\ttimestamp: %u", response.value.timestamp());
}
-void OneDriveStorage::printErrorResponse(Networking::ErrorResponse error) {
- debug("error response (%s, %ld):", (error.failed ? "failed" : "interrupted"), error.httpResponseCode);
- debug("%s", error.response.c_str());
-}
-
-Networking::ErrorCallback OneDriveStorage::getErrorPrintingCallback() {
- return new Common::Callback<OneDriveStorage, Networking::ErrorResponse>(this, &OneDriveStorage::printErrorResponse);
-}
-
-Networking::Request *OneDriveStorage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
- //this is not the real syncSaves() implementation
- return ConnMan.addRequest(new SavesSyncRequest(this, new Common::Callback<OneDriveStorage, BoolResponse>(this, &OneDriveStorage::printBool), getErrorPrintingCallback())); //TODO
-}
-
Networking::Request *OneDriveStorage::info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) {
Networking::JsonCallback innerCallback = new Common::CallbackBridge<OneDriveStorage, StorageInfoResponse, Networking::JsonResponse>(this, &OneDriveStorage::infoInnerCallback, callback);
Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, errorCallback, "https://api.onedrive.com/v1.0/drive/special/approot");
diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h
index 5741f8e20e..241b6a8742 100644
--- a/backends/cloud/onedrive/onedrivestorage.h
+++ b/backends/cloud/onedrive/onedrivestorage.h
@@ -57,9 +57,6 @@ class OneDriveStorage: public Cloud::Storage {
void printFiles(FileArrayResponse response);
void printBool(BoolResponse response);
void printFile(UploadResponse response);
- void printErrorResponse(Networking::ErrorResponse error);
-
- Networking::ErrorCallback getErrorPrintingCallback();
void fileInfoCallback(Networking::NetworkReadStreamCallback outerCallback, Networking::JsonResponse response);
public:
@@ -99,9 +96,6 @@ public:
virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Calls the callback when finished. */
- virtual Networking::Request *syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback);
-
- /** Calls the callback when finished. */
virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Calls the callback when finished. */
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 6588b05193..2e13376fa8 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -21,11 +21,25 @@
*/
#include "backends/cloud/storage.h"
+#include "backends/cloud/savessyncrequest.h"
+#include "backends/networking/curl/connectionmanager.h"
+#include "common/debug.h"
#include "common/file.h"
namespace Cloud {
+Networking::ErrorCallback Storage::getErrorPrintingCallback() {
+ return new Common::Callback<Storage, Networking::ErrorResponse>(this, &Storage::printErrorResponse);
+}
+
+void Storage::printErrorResponse(Networking::ErrorResponse error) {
+ debug("error response (%s, %ld):", (error.failed ? "failed" : "interrupted"), error.httpResponseCode);
+ debug("%s", error.response.c_str());
+}
+
Networking::Request *Storage::upload(Common::String remotePath, Common::String localPath, UploadCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+
Common::File *f = new Common::File();
if (!f->open(localPath)) {
warning("Storage: unable to open file to upload from");
@@ -35,8 +49,15 @@ Networking::Request *Storage::upload(Common::String remotePath, Common::String l
delete f;
return nullptr;
}
+
return upload(remotePath, f, callback, errorCallback);
}
+Networking::Request *Storage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ return ConnMan.addRequest(new SavesSyncRequest(this, callback, errorCallback));
+}
+
+
} // End of namespace Cloud
diff --git a/backends/cloud/storage.h b/backends/cloud/storage.h
index 4bd2aa3fb1..b4d2680e31 100644
--- a/backends/cloud/storage.h
+++ b/backends/cloud/storage.h
@@ -48,6 +48,15 @@ public:
typedef Common::BaseCallback<UploadResponse> *UploadCallback;
typedef Common::BaseCallback<ListDirectoryResponse> *ListDirectoryCallback;
+protected:
+
+ /** Returns default error callback (printErrorResponse). */
+ virtual Networking::ErrorCallback getErrorPrintingCallback();
+
+ /** Prints ErrorResponse contents with debug(). */
+ virtual void printErrorResponse(Networking::ErrorResponse error);
+
+public:
Storage() {}
virtual ~Storage() {}
@@ -92,7 +101,7 @@ public:
virtual Networking::Request *remove(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;
/** Calls the callback when finished. */
- virtual Networking::Request *syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;
+ virtual Networking::Request *syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback);
/** Calls the callback when finished. */
virtual Networking::Request *createDirectory(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;