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_CURL_SESSIONREQUEST_H
23 #define BACKENDS_NETWORKING_CURL_SESSIONREQUEST_H
24 
25 #include "backends/networking/curl/curlrequest.h"
26 #include "common/memstream.h"
27 
28 namespace Common {
29 class DumpFile;
30 class JSONValue;
31 class Path;
32 }
33 
34 namespace Networking {
35 
36 #define CURL_SESSION_REQUEST_BUFFER_SIZE 512 * 1024
37 
39  byte *buffer;
40  uint32 len;
41  bool eos;
42 };
43 
50 class SessionRequest: public CurlRequest {
51 protected:
52  Common::MemoryWriteStreamDynamic _contentsStream;
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 
63  char *getPreparedContents();
64 
65  void finishError(const ErrorResponse &error, RequestState state = PAUSED) override;
66  void finishSuccess() override;
67  void openLocalFile(const Common::Path &localFile);
68 
69 public:
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 
88  void abortRequest();
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: str.h:59
Definition: scummvmcloud.h:31
Definition: request.h:73
int64 size() const override
Definition: memstream.h:250
Definition: memstream.h:194
Definition: path.h:52
Definition: file.h:145
Definition: json.h:90
Path
Definition: game.h:75
Definition: algorithm.h:29
Definition: callback.h:49
Class for reading file and storing locally.
Definition: sessionrequest.h:50
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: sessionrequest.h:38
Definition: curlrequest.h:41