181 Commits

Author SHA1 Message Date
Alexander Tkachev
a66322408f CLOUD: Implement Storage's isWorking()
It now keeps track of how many Requests are running.

To achieve that, we had to pass a callback to ConnectionManager, so each
Request has a callback paired with it. If that's one of Storage's
Requests, it has a callback, which would decrease a counter. When
Storage adds a Request, it also increases a counter and passes that
callback. Callback is called by ConnMan when Request is deleted.

isWorking() returns true if there is at least one Request running.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
b39f46788a CLOUD: Add OneDriveUploadRequest
Doesn't support server's requested ranges yet.

Commit also adds some PUT-related code in NetworkReadStream and
CurlRequest.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
eb63b50b7f CLOUD: Refactor Request
Added ErrorResponse and ErrorCallback. Each Request now has an
ErrorCallback, which should be called instead of usual callback in case
of failure.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
d917592099 CLOUD: Add DropboxUploadRequest 2016-08-24 16:07:55 +06:00
Peter Bozsó
81c34adaef Fix comment formatting 2016-08-24 16:07:55 +06:00
Alexander Tkachev
b74d7a6861 CLOUD: Fix Requests destructors
I forgot to delete callbacks!
2016-08-24 16:07:55 +06:00
Alexander Tkachev
1dfa73b8f8 CLOUD: Fix ConnectionManager singleton warning 2016-08-24 16:07:55 +06:00
Alexander Tkachev
6c01edc57a CLOUD: Simplify OneDriveTokenRefresher
It now just extends CurlJsonRequest, not wraps one.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
1348befe29 CLOUD: Add access to CurlRequest's Stream
One can access CurlRequest's NetworkReadStream in order to find out HTTP
response code or some other Stream-related data.

OneDriveTokenRefresher uses it to print some info on that 404 error I'm
trying to troubleshoot.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
98150beb38 CLOUD: Refactor ConnectionManager/Requests system
ConnectionManager now storages Request * (not generates ids for it),
Requests have control on their RequestState, RequestIdPair is now called
Response and storages Request * with some response together.

All related classes are changed to use it in more clean and
understandable way.

Request, RequestState and Response are carefully commented/documented.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
83b349a033 CLOUD: Make OneDriveStorage::download() work fine
Well, it takes two API calls instead of one now, but there are no
problems with expired token because of it.

This commit changes Storage::streamFile() to pass NetworkReadStream *
through callback.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
24007c029b CLOUD: Add OneDriveStorage::download()
Doesn't work when token is invalid, though.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
8f6bcdf55d CLOUD: Add OneDriveTokenRefresher
OneDriveTokenRefresher is a CurlJsonRequest replacement for
OneDriveStorage methods. It behaves very similarly, but checks received
JSON before passing it to user. If it contains "error" key, it attempts
to refresh the token through OneDriveStorage, and then restarts the
original request, so user won't notice that there ever was an error.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
b246c17850 CLOUD: Fix CurlJsonRequest to use JsonCallback
Type safety first.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
a7b28605a0 CLOUD: Change Request::handle()
With new ConnectionManager upgrade Requests indicate that they are
finished with RequestInfo.state. No need to use handle() return value
anymore.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
f4547f44df CLOUD: Add RequestIdPair struct
Can be used with Callback<T> (means it's still type safe). It's used to
pass not only Request id to user's callback, but also a value user
wanted.

void *data field is removed from RequestInfo.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
62ccf1f902 CLOUD: Add RequestInfo struct
ConnectionManager upgrade: it now contains a special struct for each
request, so you can access request status and data by request id.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
eda575a660 CLOUD: Add Requests id
(Upgrading ConnectionManager step by step.)
2016-08-24 16:07:55 +06:00
Alexander Tkachev
5e346ea6fb CLOUD: Add OneDrive refresh_token support
It might be not that easy to restart the request after new token
received, though.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
826a2a921c CLOUD: Add DownloadRequest stub
It reads the passed NetworkReadStream and prints its contents onto
console (for now). It would be writing contents into file.

To simplify work with raw NetworkReadStream there is a new CurlRequest.
It basically does nothing, but as ConnMan handles transfers only if
there is an active Request, you need some Request to get
NetworkReadStream working. Thus, there is a CurlRequest, which is active
until NetworkReadStream is completely read. CurlRequest also has useful
addHeader() and addPostField() methods in order to customize the request
easily. Use execute() method to get its NetworkReadStream.

DropboxStorage implements streamFile() and download() API methods. As
DownloadRequest is incomplete, it is not actually downloading a file,
though.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
735db74b90 CLOUD: Add DropboxStorage::listDirectory sketch
It doesn't support any "has_more", doesn't call user's callback and just
prints JSON instead of parsing in into an array of files.

I believe it would become DropboxListDirectoryRequest in the next
commit.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
c4b1fdc727 CLOUD: Fix Request destructor
It now contains not a pointer to a function, but an actual pointer,
which must be freed.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
9e531e3ce7 CLOUD: Polish Callbacks
Cleaned up all example code and old callbacks.

New Callback classes are introduced in "common/callback.h" and
documented.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
e1109c0c32 CLOUD: Add CallbackBridge
This commit also adds GlobalFunctionCallback, because it was needed in
order to replace plain C pointers to functions (which were used in
Request) into our object-oriented BaseCallback pointers.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
ca456a7241 CLOUD: Add object-oriented Callbacks
These callbacks can call object's methods, not some global C functions.

DropboxStorage::info2() and DropboxStorage::infoMethodCallback()
demonstrate the idea.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
17eb5f9143 CLOUD: Add complex callbacks
Originally, I intended to add Storage API, StorageFile and StorageInfo
stubs. When I tried to implement a simple info() call, I ended up fixing
Request to contain some pointer field and all callbacks to have Request*
parameter. And, now I have to place callback pointer into Request. which
calls another callback.

And, eventually, these "simple" callbacks would again require another
pointer (to some caller class).
2016-08-24 16:07:55 +06:00
Alexander Tkachev
0a947618fb CLOUD: Make ConnectionManager singleton
With ConnectionManager singleton one can start their Requests without
creating Storage instance. Moreover, Storage instance should contain
cloud API, not Requests-related handling and timer starting methods.
Thus, these methods were moved into ConnectionManager itself.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
e743a65636 CLOUD: Add Dropbox into CloudManager's configs
This commit adds:
* ConfMan's new "cloud" domain;
* CloudManager's init() method, where it loads keys from "cloud" configs
domain;
* CurlJsonRequest's addHeader() and addPostField() methods;
* temporary Storage's printInfo() method;
* DropboxStorage's implementation of printInfo(), which is using access
token and user id;
* DropboxStorage's loadFromConfig() static method to load access token
and user id from configs and create a Storage instance with those;
* temporary DropboxStorage's authThroughConsole() static method, which
guides user through auth process from the console.

So, in CloudManager's init() implementation ScummVM checks that there is
"current_storage_type" key in "cloud" domain of configs, and loads
corresponding storage if there is such key.

If there is no such key, ScummVM offers user to auth with Dropbox.
That's done through console, and thus it's temporary (it also requires
restarting ScummVM twice and manually editing config.ini file).
2016-08-24 16:07:55 +06:00
Alexander Tkachev
5df8c51402 CLOUD: Fix CurlJsonRequest
It's using MemoryWriteStreamDynamic instead of String and it prepares
raw byte contents of this stream for JSON::parse().
2016-08-24 16:07:55 +06:00
Alexander Tkachev
03217cd5c3 CLOUD: Add CurlJsonRequest
Now we can do REST API request by creating CurlJsonRequest and waiting
for it to call our callback. Passed pointer is Common::JSONValue.

This commit also does some minor variable renaming fixes.
2016-08-24 16:07:55 +06:00
Alexander Tkachev
9c22b7cc64 CLOUD: Rewrite NetworkReadStream
Now it is based on MemoryReadWriteStream, which is introduced by this
commit. This stream is using ring buffer and is dynamically increasing
its size when necessary.
2016-08-24 16:07:55 +06:00