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 = 25;
00042     static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
00043     static const uint32 CLOUD_PERIOD = 1; //every frame
00044     static const uint32 CURL_PERIOD = 1; //every frame
00045     static const uint32 DEBUG_PRINT_PERIOD = FRAMES_PER_SECOND; // once per second
00046 
00047     friend void connectionsThread(void *); //calls handle()
00048 
00049     typedef Common::BaseCallback<Request *> *RequestCallback;
00050 
00071     struct RequestWithCallback {
00072         Request *request;
00073         RequestCallback onDeleteCallback;
00074 
00075         RequestWithCallback(Request *rq = nullptr, RequestCallback cb = nullptr): request(rq), onDeleteCallback(cb) {}
00076     };
00077 
00078     CURLM *_multi;
00079     bool _timerStarted;
00080     Common::Array<RequestWithCallback> _requests, _addedRequests;
00081     Common::Mutex _handleMutex, _addedRequestsMutex;
00082     uint32 _frame;
00083 
00084     void startTimer(int interval = TIMER_INTERVAL);
00085     void stopTimer();
00086     void handle();
00087     void interateRequests();
00088     void processTransfers();
00089     bool hasAddedRequests();
00090 
00091 public:
00092     ConnectionManager();
00093     virtual ~ConnectionManager();
00094 
00100     void registerEasyHandle(CURL *easy) const;
00101 
00115     Request *addRequest(Request *request, RequestCallback callback = nullptr);
00116 
00118     Common::String urlEncode(Common::String s) const;
00119 
00120     static uint32 getCloudRequestsPeriodInMicroseconds();
00121 
00123     static const char *getCaCertPath();
00124 };
00125 
00127 #define ConnMan     Networking::ConnectionManager::instance()
00128 
00129 } // End of namespace Networking
00130 
00131 #endif


Generated on Sat May 23 2020 05:00:28 for ResidualVM by doxygen 1.7.1
curved edge   curved edge