ScummVM API documentation
sessionrequest.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_SESSIONREQUEST_H
23#define BACKENDS_NETWORKING_HTTP_SESSIONREQUEST_H
24
25#include "backends/networking/http/httprequest.h"
26#include "common/memstream.h"
27
28namespace Common {
29class DumpFile;
30class JSONValue;
31class Path;
32}
33
34namespace Networking {
35
36#define HTTP_SESSION_REQUEST_BUFFER_SIZE 512 * 1024
37
39 byte *buffer;
40 uint32 len;
41 bool eos;
42};
43
51protected:
53 byte *_buffer;
54 char *_text;
55 bool _started, _complete, _success;
56 bool _binary;
57 Common::DumpFile *_localFile;
58 SessionFileResponse _response;
59
60 bool reuseStream();
61
64
65 void finishError(const ErrorResponse &error, RequestState state = PAUSED) override;
66 void finishSuccess() override;
67 void openLocalFile(const Common::Path &localFile);
68
69public:
70 SessionRequest(const Common::String &url, const Common::Path &localFile, DataCallback cb = nullptr, ErrorCallback ecb = nullptr, bool binary = false);
71 ~SessionRequest() override;
72
73 void start();
74 void startAndWait();
75
76 void reuse(const Common::String &url, const Common::Path &localFile, DataCallback cb = nullptr, ErrorCallback ecb = nullptr, bool binary = false);
77
78 void handle() override;
79 void restart() override;
80
82 void close();
83
89
90 bool complete();
91 bool success();
92
93 char *text();
94 Common::JSONValue *json();
95
96 byte *getData() { return _contentsStream.getData(); }
97 uint32 getSize() { return _contentsStream.size(); }
98
99};
100
101} // End of namespace Networking
102
103#endif
Definition: file.h:145
Definition: json.h:90
Definition: memstream.h:194
int64 size() const override
Definition: memstream.h:250
Definition: path.h:52
Definition: str.h:59
Definition: httprequest.h:42
RequestState state() const
Class for reading file and storing locally.
Definition: sessionrequest.h:50
void finishSuccess() override
void finishError(const ErrorResponse &error, RequestState state=PAUSED) override
void abortRequest()
Closes the current request and removes any unfinished files.
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: algorithm.h:29
Path
Definition: game.h:76
Definition: request.h:73
Definition: sessionrequest.h:38