aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-15 00:31:02 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit8b585d631b21441dfa3de69d2c7c848d172c73be (patch)
tree36302c2945116c0229d0d897ae515bb4ac61c1f8
parent6ad983bb7220eed2f635163a7fcfdac811b80ca0 (diff)
downloadscummvm-rg350-8b585d631b21441dfa3de69d2c7c848d172c73be.tar.gz
scummvm-rg350-8b585d631b21441dfa3de69d2c7c848d172c73be.tar.bz2
scummvm-rg350-8b585d631b21441dfa3de69d2c7c848d172c73be.zip
CLOUD: Add CurlRequest
CurlRequest uses own multi_handle, in which it creates an easy_handle to make a request. Every time `handle()` is called it checks whether request is complete and, if it is, stops.
-rw-r--r--backends/cloud/dropbox/curlrequest.cpp82
-rw-r--r--backends/cloud/dropbox/curlrequest.h (renamed from backends/cloud/dropbox/finalcountdownrequest.h)32
-rw-r--r--backends/cloud/dropbox/dropboxstorage.cpp21
-rw-r--r--backends/cloud/dropbox/dropboxstorage.h3
-rw-r--r--backends/cloud/storage.cpp5
-rw-r--r--backends/module.mk3
6 files changed, 119 insertions, 27 deletions
diff --git a/backends/cloud/dropbox/curlrequest.cpp b/backends/cloud/dropbox/curlrequest.cpp
new file mode 100644
index 0000000000..216b56c19e
--- /dev/null
+++ b/backends/cloud/dropbox/curlrequest.cpp
@@ -0,0 +1,82 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU 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 General Public License for more details.
+*
+* You should have received a copy of the GNU 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.
+*
+*/
+
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/cloud/dropbox/curlrequest.h"
+#include "common/debug.h"
+#include <curl/curl.h>
+
+namespace Cloud {
+namespace Dropbox {
+
+static size_t curlDataCallback(char *d, size_t n, size_t l, void *p) {
+ debug("%p got %d more bytes", p, n * l);
+ return n * l;
+}
+
+CurlRequest::CurlRequest(Callback cb, char *url) : Request(cb), _firstTime(true) {
+ _curlm = curl_multi_init();
+ _url = url;
+}
+
+CurlRequest::~CurlRequest() {
+ curl_multi_cleanup(_curlm);
+}
+
+bool CurlRequest::handle() {
+ if (_firstTime) {
+ CURL *eh = curl_easy_init();
+ curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, curlDataCallback);
+ curl_easy_setopt(eh, CURLOPT_WRITEDATA, this);
+ curl_easy_setopt(eh, CURLOPT_HEADER, 0L);
+ curl_easy_setopt(eh, CURLOPT_URL, _url);
+ curl_easy_setopt(eh, CURLOPT_VERBOSE, 0L);
+ curl_multi_add_handle(_curlm, eh);
+
+ _firstTime = false;
+ }
+
+ int U;
+ curl_multi_perform(_curlm, &U);
+
+ int Q;
+ CURLMsg *_curlMsg;
+ while ((_curlMsg = curl_multi_info_read(_curlm, &Q))) {
+ if (_curlMsg->msg == CURLMSG_DONE) {
+ CURL *e = _curlMsg->easy_handle;
+ debug("R: %d - %s\n", _curlMsg->data.result, curl_easy_strerror(_curlMsg->data.result));
+ curl_multi_remove_handle(_curlm, e);
+ curl_easy_cleanup(e);
+
+ _callback(0);
+ return true;
+ } else {
+ debug("E: CURLMsg (%d)\n", _curlMsg->msg);
+ }
+ }
+
+ return false;
+}
+
+} //end of namespace Dropbox
+} //end of namespace Cloud
diff --git a/backends/cloud/dropbox/finalcountdownrequest.h b/backends/cloud/dropbox/curlrequest.h
index 5ef942180c..8453fbb90a 100644
--- a/backends/cloud/dropbox/finalcountdownrequest.h
+++ b/backends/cloud/dropbox/curlrequest.h
@@ -20,33 +20,29 @@
*
*/
-#ifndef BACKENDS_CLOUD_DROPBOX_FINALCOUNTDOWNREQUEST_H
-#define BACKENDS_CLOUD_DROPBOX_FINALCOUNTDOWNREQUEST_H
+#ifndef BACKENDS_CLOUD_DROPBOX_CURLREQUEST_H
+#define BACKENDS_CLOUD_DROPBOX_CURLREQUEST_H
#include "backends/cloud/request.h"
+typedef void CURLM;
+
namespace Cloud {
namespace Dropbox {
-class FinalCountdownRequest : public Cloud::Request {
- int _times;
+class CurlRequest : public Cloud::Request {
+ bool _firstTime;
+ CURLM *_curlm;
+ char *_url;
public:
- FinalCountdownRequest(Callback cb) : Request(cb), _times(5) {};
-
- virtual bool handle() {
- if (--_times == 0) {
- warning("It's the final countdown!");
- _callback(0); //meh, don't have anything for you, my caller
- return true;
- }
-
- warning("%d...", _times);
- return false;
- }
+ CurlRequest(Callback cb, char *url);
+ virtual ~CurlRequest();
+
+ virtual bool handle();
};
-}
-} //end of namespace Cloud::Dropbox
+} //end of namespace Dropbox
+} //end of namespace Cloud
#endif
diff --git a/backends/cloud/dropbox/dropboxstorage.cpp b/backends/cloud/dropbox/dropboxstorage.cpp
index 8a0772dc3f..142a059457 100644
--- a/backends/cloud/dropbox/dropboxstorage.cpp
+++ b/backends/cloud/dropbox/dropboxstorage.cpp
@@ -19,18 +19,26 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "backends/cloud/dropbox/dropboxstorage.h"
-#include "backends/cloud/dropbox/finalcountdownrequest.h"
+#include "backends/cloud/dropbox/curlrequest.h"
#include "common/debug.h"
+#include <curl/curl.h>
namespace Cloud {
namespace Dropbox {
-static void finalCountdownCallback(void *ptr) {
- warning("ladies and gentlemen, this is your callback speaking");
- warning("the returned pointer is %d", ptr);
- warning("thank you for your attention");
+static void curlCallback(void *ptr) {
+ debug("--- curl request is complete ---");
+}
+
+DropboxStorage::DropboxStorage() {
+ curl_global_init(CURL_GLOBAL_ALL);
+}
+
+DropboxStorage::~DropboxStorage() {
+ curl_global_cleanup();
}
void DropboxStorage::listDirectory(Common::String path) {
@@ -38,7 +46,8 @@ void DropboxStorage::listDirectory(Common::String path) {
}
void DropboxStorage::syncSaves() {
- addRequest(new FinalCountdownRequest(finalCountdownCallback));
+ addRequest(new CurlRequest(curlCallback, "tkachov.ru"));
+ addRequest(new CurlRequest(curlCallback, "bash.im"));
}
} //end of namespace Dropbox
diff --git a/backends/cloud/dropbox/dropboxstorage.h b/backends/cloud/dropbox/dropboxstorage.h
index f80854b987..a0229438be 100644
--- a/backends/cloud/dropbox/dropboxstorage.h
+++ b/backends/cloud/dropbox/dropboxstorage.h
@@ -29,7 +29,8 @@ namespace Cloud { namespace Dropbox {
class DropboxStorage: public Cloud::Storage {
public:
- DropboxStorage() {};
+ DropboxStorage();
+ virtual ~DropboxStorage();
virtual void listDirectory(Common::String path);
virtual void syncSaves();
diff --git a/backends/cloud/storage.cpp b/backends/cloud/storage.cpp
index 23dcd8c379..0c5f6a39e7 100644
--- a/backends/cloud/storage.cpp
+++ b/backends/cloud/storage.cpp
@@ -42,7 +42,10 @@ void Storage::handler() {
//TODO: lock mutex here (in case another handler() would be called before this one ends)
warning("handler's here");
for (Common::Array<Request *>::iterator i = _requests.begin(); i != _requests.end();) {
- if ((*i)->handle()) _requests.erase(i);
+ if ((*i)->handle()) {
+ delete (*i);
+ _requests.erase(i);
+ }
else ++i;
}
if (_requests.empty()) stopTimer();
diff --git a/backends/module.mk b/backends/module.mk
index aa9e976fc2..ccf5151b2c 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -23,7 +23,8 @@ ifdef USE_CLOUD
MODULE_OBJS += \
cloud/manager.o \
cloud/storage.o \
- cloud/dropbox/dropboxstorage.o
+ cloud/dropbox/dropboxstorage.o \
+ cloud/dropbox/curlrequest.o
endif
ifdef USE_ELF_LOADER