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_HTTP_CONNECTIONMANAGER_H
23#define BACKENDS_NETWORKING_HTTP_CONNECTIONMANAGER_H
24
25#include "backends/networking/http/request.h"
26#include "common/hashmap.h"
27#include "common/mutex.h"
28#include "common/singleton.h"
29#include "common/str.h"
30
31namespace Networking {
32
33class ConnectionManager : public Common::Singleton<Networking::ConnectionManager> {
34 static const uint32 FRAMES_PER_SECOND = 100;
35 static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
36 static const uint32 ITERATION_PERIOD = 1; // every frame
37 static const uint32 PROCESSING_PERIOD = 1; // every frame
38 static const uint32 DEBUG_PRINT_PERIOD = FRAMES_PER_SECOND; // once per second
39
40 friend void connectionsThread(void *); // calls handle()
41
43
64 struct RequestWithCallback {
65 Request *request;
66 RequestCallback onDeleteCallback;
67
68 RequestWithCallback(Request *rq = nullptr, RequestCallback cb = nullptr) : request(rq), onDeleteCallback(cb) {}
69 };
70
71 bool _timerStarted;
72 Common::Array<RequestWithCallback> _requests, _addedRequests;
73 Common::Mutex _handleMutex, _addedRequestsMutex;
74 uint32 _frame;
75
76 void startTimer(int interval = TIMER_INTERVAL);
77 void stopTimer();
78 void handle();
79 void iterateRequests();
80 virtual void processTransfers() = 0;
81 bool hasAddedRequests();
82
83public:
86
100 Request *addRequest(Request *request, RequestCallback callback = nullptr);
101
102 static uint32 getCloudRequestsPeriodInMicroseconds();
103};
104
106#define ConnMan Networking::ConnectionManager::instance()
107
108} // End of namespace Networking
109
110namespace Common {
111template<>
112Networking::ConnectionManager *Singleton<Networking::ConnectionManager>::makeInstance();
113} // End of namespace Common
114
115#endif
Definition: mutex.h:67
Definition: singleton.h:42
Definition: connectionmanager.h:33
Request * addRequest(Request *request, RequestCallback callback=nullptr)
Definition: request.h:119
Definition: algorithm.h:29