ScummVM API documentation
connectionmanager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_NETWORKING_CURL_CONNECTIONMANAGER_H
23 #define BACKENDS_NETWORKING_CURL_CONNECTIONMANAGER_H
24 
25 #include "backends/networking/curl/request.h"
26 #include "common/str.h"
27 #include "common/singleton.h"
28 #include "common/hashmap.h"
29 #include "common/mutex.h"
30 
31 typedef void CURL;
32 typedef void CURLM;
33 struct curl_slist;
34 
35 namespace Networking {
36 
37 class NetworkReadStream;
38 
39 class ConnectionManager : public Common::Singleton<ConnectionManager> {
40  static const uint32 FRAMES_PER_SECOND = 100;
41  static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
42  static const uint32 CLOUD_PERIOD = 1; //every frame
43  static const uint32 CURL_PERIOD = 1; //every frame
44  static const uint32 DEBUG_PRINT_PERIOD = FRAMES_PER_SECOND; // once per second
45 
46  friend void connectionsThread(void *); //calls handle()
47 
49 
70  struct RequestWithCallback {
71  Request *request;
72  RequestCallback onDeleteCallback;
73 
74  RequestWithCallback(Request *rq = nullptr, RequestCallback cb = nullptr): request(rq), onDeleteCallback(cb) {}
75  };
76 
77  CURLM *_multi;
78  bool _timerStarted;
79  Common::Array<RequestWithCallback> _requests, _addedRequests;
80  Common::Mutex _handleMutex, _addedRequestsMutex;
81  uint32 _frame;
82 
83  void startTimer(int interval = TIMER_INTERVAL);
84  void stopTimer();
85  void handle();
86  void interateRequests();
87  void processTransfers();
88  bool hasAddedRequests();
89 
90 public:
92  ~ConnectionManager() override;
93 
99  void registerEasyHandle(CURL *easy) const;
100 
114  Request *addRequest(Request *request, RequestCallback callback = nullptr);
115 
117  Common::String urlEncode(const Common::String &s) const;
118 
119  static uint32 getCloudRequestsPeriodInMicroseconds();
120 
122  static Common::String getCaCertPath();
123 };
124 
126 #define ConnMan Networking::ConnectionManager::instance()
127 
128 } // End of namespace Networking
129 
130 #endif
Definition: str.h:59
Definition: scummvmcloud.h:31
Definition: connectionmanager.h:39
Common::String urlEncode(const Common::String &s) const
Request * addRequest(Request *request, RequestCallback callback=nullptr)
void registerEasyHandle(CURL *easy) const
Definition: mutex.h:67
static Common::String getCaCertPath()
Definition: singleton.h:42
Definition: request.h:119