diff options
author | Alexander Tkachev | 2016-05-21 21:30:25 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | e1109c0c328aaf671e2b03b3b4e6de1ae9061754 (patch) | |
tree | df4beeb28006b68c6d60953c164f53660f74b376 /backends/cloud/dropbox | |
parent | ca456a7241fb4b46f9c76c86eeecc273ca31d8f6 (diff) | |
download | scummvm-rg350-e1109c0c328aaf671e2b03b3b4e6de1ae9061754.tar.gz scummvm-rg350-e1109c0c328aaf671e2b03b3b4e6de1ae9061754.tar.bz2 scummvm-rg350-e1109c0c328aaf671e2b03b3b4e6de1ae9061754.zip |
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.
Diffstat (limited to 'backends/cloud/dropbox')
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.cpp | 20 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxstorage.h | 3 |
2 files changed, 16 insertions, 7 deletions
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp index 94bdb43450..04e9eeef0b 100644 --- a/backends/cloud/dropbox/dropboxstorage.cpp +++ b/backends/cloud/dropbox/dropboxstorage.cpp @@ -46,7 +46,7 @@ static void printJsonCallback(Networking::Request* rq, void *ptr) { } } -static void saveAccessTokenCallback(Networking::Request* rq, void *ptr) { +static void saveAccessTokenCallback(void *ptr) { Common::JSONValue *json = (Common::JSONValue *)ptr; if (json) { debug("saveAccessTokenCallback:"); @@ -139,19 +139,26 @@ void DropboxStorage::syncSaves(OperationCallback callback) { } void DropboxStorage::info(InfoCallback callback) { + /* Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(infoCallback, "https://api.dropboxapi.com/1/account/info"); request->addHeader("Authorization: Bearer " + _token); ConnMan.addRequest(request); request->setPointer(callback); + */ } -void DropboxStorage::info2(Common::Callback<DropboxStorage> *callback) { - Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(info2Callback, "https://api.dropboxapi.com/1/account/info"); +void DropboxStorage::info2BridgeCallback(Common::BaseCallback *outerCallback, void *ptr) { + //no NULL checks, delete and such yet + Common::JSONValue *json = (Common::JSONValue *)ptr; + (*outerCallback)(new StorageInfo(json->stringify())); +} + +void DropboxStorage::info2(Common::BaseCallback *outerCallback) { + Common::BaseCallback *innerCallback = new Common::CallbackBridge<DropboxStorage>(this, &DropboxStorage::info2BridgeCallback, outerCallback); + Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(innerCallback, "https://api.dropboxapi.com/1/account/info"); request->addHeader("Authorization: Bearer " + _token); ConnMan.addRequest(request); - - request->setPointer(callback); } DropboxStorage *DropboxStorage::loadFromConfig() { @@ -205,7 +212,8 @@ void DropboxStorage::authThroughConsole() { } void DropboxStorage::getAccessToken(Common::String code) { - Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(saveAccessTokenCallback, "https://api.dropboxapi.com/1/oauth2/token"); + Common::BaseCallback *callback = new Common::GlobalFunctionCallback(saveAccessTokenCallback); + Networking::CurlJsonRequest *request = new Networking::CurlJsonRequest(callback, "https://api.dropboxapi.com/1/oauth2/token"); request->addPostField("code=" + code); request->addPostField("grant_type=authorization_code"); request->addPostField("client_id=" + KEY); diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h index 1cf657bc36..efd0eea257 100644 --- a/backends/cloud/dropbox/dropboxstorage.h +++ b/backends/cloud/dropbox/dropboxstorage.h @@ -68,7 +68,8 @@ public: /** Returns pointer to the ServiceInfo struct. */ virtual void info(InfoCallback callback); - void info2(Common::Callback<DropboxStorage> *callback); + void info2(Common::BaseCallback *outerCallback); + void info2BridgeCallback(Common::BaseCallback *outerCallback, void *ptr); /** Returns whether saves sync process is running. */ virtual bool isSyncing() { return false; } //TODO |