diff options
author | Alexander Tkachev | 2016-05-26 17:12:40 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | eda575a660543884b1a4addd21b676a67d2c2a31 (patch) | |
tree | 0964f46167ff44daefba64cf429ea69da5512aeb /backends/networking | |
parent | 17fc40a94436f970af75d6717c7a63c70eafcb12 (diff) | |
download | scummvm-rg350-eda575a660543884b1a4addd21b676a67d2c2a31.tar.gz scummvm-rg350-eda575a660543884b1a4addd21b676a67d2c2a31.tar.bz2 scummvm-rg350-eda575a660543884b1a4addd21b676a67d2c2a31.zip |
CLOUD: Add Requests id
(Upgrading ConnectionManager step by step.)
Diffstat (limited to 'backends/networking')
-rw-r--r-- | backends/networking/curl/connectionmanager.cpp | 18 | ||||
-rw-r--r-- | backends/networking/curl/connectionmanager.h | 9 | ||||
-rw-r--r-- | backends/networking/curl/request.h | 9 |
3 files changed, 25 insertions, 11 deletions
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp index 97ae31a446..8428bd25f0 100644 --- a/backends/networking/curl/connectionmanager.cpp +++ b/backends/networking/curl/connectionmanager.cpp @@ -48,9 +48,12 @@ void ConnectionManager::registerEasyHandle(CURL *easy) { curl_multi_add_handle(_multi, easy); } -void ConnectionManager::addRequest(Request *request) { - _requests.push_back(request); +int32 ConnectionManager::addRequest(Request *request) { + int32 newId = _nextId++; + _requests[newId] = request; + request->setId(newId); if (!_timerStarted) startTimer(); + return newId; } //private goes here: @@ -84,10 +87,13 @@ void ConnectionManager::handle() { void ConnectionManager::interateRequests() { //call handle() of all running requests (so they can do their work) debug("handling %d request(s)", _requests.size()); - for (Common::Array<Request *>::iterator i = _requests.begin(); i != _requests.end();) { - if ((*i)->handle()) { - delete (*i); - _requests.erase(i); + for (Common::HashMap<int32, Request *>::iterator i = _requests.begin(); i != _requests.end();) { + Request *request = i->_value; + if (request && request->handle()) { + delete request; + //_requests.erase(i); + _requests[i->_key] = 0; + ++i; //that's temporary } else ++i; } if (_requests.empty()) stopTimer(); diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h index ed726441c4..9651a0166a 100644 --- a/backends/networking/curl/connectionmanager.h +++ b/backends/networking/curl/connectionmanager.h @@ -26,7 +26,7 @@ #include "backends/networking/curl/request.h" #include "common/str.h" #include "common/singleton.h" -#include "common/array.h" +#include "common/hashmap.h" typedef void CURL; typedef void CURLM; @@ -41,7 +41,8 @@ class ConnectionManager : public Common::Singleton<ConnectionManager> { CURLM *_multi; bool _timerStarted; - Common::Array<Request *> _requests; + Common::HashMap<int32, Request *> _requests; + int32 _nextId; void startTimer(int interval = 1000000); //1 second is the default interval void stopTimer(); @@ -66,8 +67,10 @@ public: * Requests until they return true. * * @note This method starts the timer if it's not started yet. + * + * @return generated Request's id, which might be used to get its status */ - void addRequest(Request *request); + int32 addRequest(Request *request); }; /** Shortcut for accessing the connection manager. */ diff --git a/backends/networking/curl/request.h b/backends/networking/curl/request.h index 37cb3884ca..0265d3e2f3 100644 --- a/backends/networking/curl/request.h +++ b/backends/networking/curl/request.h @@ -24,6 +24,7 @@ #define BACKENDS_NETWORKING_CURL_REQUEST_H #include "common/callback.h" +#include "common/scummsys.h" namespace Networking { @@ -36,9 +37,11 @@ protected: Common::BaseCallback<> *_callback; + int32 _id; + public: - Request(Common::BaseCallback<> *cb): _callback(cb) {}; - virtual ~Request() { delete _callback; }; + Request(Common::BaseCallback<> *cb): _callback(cb), _id(-1) {} + virtual ~Request() { delete _callback; } /** * Method, which does actual work. Depends on what this Request is doing. @@ -47,6 +50,8 @@ public: */ virtual bool handle() = 0; + + void setId(int32 id) { _id = id; } }; } //end of namespace Cloud |