ScummVM API documentation
storage.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_CLOUD_STORAGE_H
23 #define BACKENDS_CLOUD_STORAGE_H
24 
25 #include "backends/cloud/storagefile.h"
26 #include "backends/cloud/storageinfo.h"
27 #include "backends/networking/curl/request.h"
28 #include "backends/networking/curl/curlrequest.h"
29 #include "common/array.h"
30 #include "common/callback.h"
31 #include "common/mutex.h"
32 #include "common/path.h"
33 #include "common/stream.h"
34 #include "common/str.h"
35 
36 namespace GUI {
37 
38 class CommandReceiver;
39 
40 }
41 
42 namespace Cloud {
43 
44 class SavesSyncRequest;
45 class FolderDownloadRequest;
46 
47 class Storage {
48 public:
54 
60 
61 protected:
64  Common::Mutex _runningRequestsMutex;
65 
68  bool _syncRestartRequestsed;
69 
72 
74  bool _isEnabled;
75 
77  virtual Networking::ErrorCallback getErrorPrintingCallback();
78 
80  virtual void printErrorResponse(const Networking::ErrorResponse &error);
81 
89  virtual Networking::Request *addRequest(Networking::Request *request);
90 
96  virtual void requestFinishedCallback(Networking::Request *invalidRequestPointer);
97 
98 public:
99  Storage();
100  virtual ~Storage();
101 
113  virtual void saveConfig(const Common::String &keyPrefix) = 0;
114 
119  virtual Common::String name() const = 0;
120 
124  bool isEnabled() const;
125 
129  void enable();
130 
140  virtual Networking::Request *listDirectory(const Common::String &path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false) = 0;
141 
143  virtual Networking::Request *upload(const Common::String &path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback) = 0;
144  virtual Networking::Request *upload(const Common::String &remotePath, const Common::Path &localPath, UploadCallback callback, Networking::ErrorCallback errorCallback);
145 
147  virtual bool uploadStreamSupported();
148 
150  virtual Networking::Request *streamFile(const Common::String &path, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback);
151  virtual Networking::Request *streamFileById(const Common::String &id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) = 0;
152 
154  virtual Networking::Request *download(const Common::String &remotePath, const Common::Path &localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
155  virtual Networking::Request *downloadById(const Common::String &remoteId, const Common::Path &localPath, BoolCallback callback, Networking::ErrorCallback errorCallback);
156 
158  virtual Networking::Request *downloadFolder(const Common::String &remotePath, const Common::Path &localPath, FileArrayCallback callback, Networking::ErrorCallback errorCallback, bool recursive = false);
159 
161  virtual SavesSyncRequest *syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback);
162 
164  virtual Networking::Request *createDirectory(const Common::String &path, BoolCallback callback, Networking::ErrorCallback errorCallback) = 0;
165 
173  virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) = 0;
174 
176  virtual Common::String savesDirectoryPath() = 0;
177 
179  virtual bool isWorking();
180 
182 
184  virtual bool isSyncing();
185 
187  virtual double getSyncDownloadingProgress();
188 
190  uint64 bytesDownloaded = 0, bytesToDownload = 0;
191  uint64 filesDownloaded = 0, filesToDownload = 0;
192  bool inProgress = false;
193  };
194 
196  virtual void getSyncDownloadingInfo(SyncDownloadingInfo &info);
197 
199  virtual double getSyncProgress();
200 
202  virtual Common::Array<Common::String> getSyncingFiles();
203 
205  virtual void cancelSync();
206 
207 protected:
209  virtual void savesSyncDefaultCallback(const BoolResponse &response);
210 
212  virtual void savesSyncDefaultErrorCallback(const Networking::ErrorResponse &error);
213 
214 public:
216 
218  virtual bool startDownload(const Common::String &remotePath, const Common::Path &localPath);
219 
221  virtual void cancelDownload();
222 
224  virtual void setDownloadTarget(GUI::CommandReceiver *target);
225 
227  virtual bool isDownloading();
228 
230  virtual double getDownloadingProgress();
231 
233  virtual uint64 getDownloadBytesNumber();
234 
236  virtual uint64 getDownloadTotalBytesNumber();
237 
239  virtual uint64 getDownloadSpeed();
240 
242  virtual Common::String getDownloadRemoteDirectory();
243 
245  virtual Common::Path getDownloadLocalDirectory();
246 
247 protected:
249  virtual void directoryDownloadedCallback(const FileArrayResponse &response);
250 
252  virtual void directoryDownloadedErrorCallback(const Networking::ErrorResponse &error);
253 };
254 
255 } // End of namespace Cloud
256 
257 #endif
Definition: str.h:59
Definition: basestorage.h:28
Definition: storage.h:47
Definition: request.h:73
SavesSyncRequest * _savesSyncRequest
Definition: storage.h:67
Definition: path.h:52
FolderDownloadRequest * _downloadFolderRequest
Definition: storage.h:71
uint32 _runningRequestsCount
Definition: storage.h:63
Definition: request.h:47
Definition: stream.h:745
Definition: system.h:46
bool _isEnabled
Definition: storage.h:74
Definition: mutex.h:67
Definition: folderdownloadrequest.h:31
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: storage.h:189
Definition: object.h:33
Definition: savessyncrequest.h:32
Definition: request.h:119