ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

connectionmanager.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef BACKENDS_NETWORKING_CURL_CONNECTIONMANAGER_H
00024 #define BACKENDS_NETWORKING_CURL_CONNECTIONMANAGER_H
00025 
00026 #include "backends/networking/curl/request.h"
00027 #include "common/str.h"
00028 #include "common/singleton.h"
00029 #include "common/hashmap.h"
00030 #include "common/mutex.h"
00031 
00032 typedef void CURL;
00033 typedef void CURLM;
00034 struct curl_slist;
00035 
00036 namespace Networking {
00037 
00038 class NetworkReadStream;
00039 
00040 class ConnectionManager : public Common::Singleton<ConnectionManager> {
00041     static const uint32 FRAMES_PER_SECOND = 20;
00042     static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
00043     static const uint32 CLOUD_PERIOD = 20; //every 20th frame
00044     static const uint32 CURL_PERIOD = 1; //every frame
00045 
00046     friend void connectionsThread(void *); //calls handle()
00047 
00048     typedef Common::BaseCallback<Request *> *RequestCallback;
00049 
00070     struct RequestWithCallback {
00071         Request *request;
00072         RequestCallback onDeleteCallback;
00073 
00074         RequestWithCallback(Request *rq = nullptr, RequestCallback cb = nullptr): request(rq), onDeleteCallback(cb) {}
00075     };
00076 
00077     CURLM *_multi;
00078     bool _timerStarted;
00079     Common::Array<RequestWithCallback> _requests, _addedRequests;
00080     Common::Mutex _handleMutex, _addedRequestsMutex;
00081     uint32 _frame;
00082 
00083     void startTimer(int interval = TIMER_INTERVAL);
00084     void stopTimer();
00085     void handle();
00086     void interateRequests();
00087     void processTransfers();
00088     bool hasAddedRequests();
00089 
00090 public:
00091     ConnectionManager();
00092     virtual ~ConnectionManager();
00093 
00099     void registerEasyHandle(CURL *easy) const;
00100 
00114     Request *addRequest(Request *request, RequestCallback callback = nullptr);
00115 
00117     Common::String urlEncode(Common::String s) const;
00118 
00119     static uint32 getCloudRequestsPeriodInMicroseconds();
00120 };
00121 
00123 #define ConnMan     Networking::ConnectionManager::instance()
00124 
00125 } // End of namespace Networking
00126 
00127 #endif


Generated on Sat Feb 16 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge