ScummVM API documentation
networkreadstream-emscripten.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_EMSCRIPTEN_NETWORKREADSTREAMEMSCRIPTEN_H
23 #define BACKENDS_NETWORKING_HTTP_EMSCRIPTEN_NETWORKREADSTREAMEMSCRIPTEN_H
24 
25 #ifdef EMSCRIPTEN
26 
27 #include "backends/networking/http/networkreadstream.h"
28 #include <emscripten/fetch.h>
29 
30 namespace Networking {
31 
32 class NetworkReadStream; // Forward declaration
33 
34 class NetworkReadStreamEmscripten : public NetworkReadStream {
35 private:
36  emscripten_fetch_attr_t *_emscripten_fetch_attr;
37  emscripten_fetch_t *_emscripten_fetch;
38  const char *_emscripten_fetch_url = nullptr;
39  char **_emscripten_request_headers;
40  bool _success;
41  char *_errorBuffer;
42 
43 public:
44  NetworkReadStreamEmscripten(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading, bool usingPatch, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
45 
46  NetworkReadStreamEmscripten(const char *url, RequestHeaders *headersList, const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
47 
48  NetworkReadStreamEmscripten(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
49 
50  ~NetworkReadStreamEmscripten() override;
51  void initEmscripten(const char *url, RequestHeaders *headersList);
52 
53  // NetworkReadStream interface
54  bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading = false, bool usingPatch = false) override { return false; } // no reuse for Emscripten
55  bool reuse(const char *url, RequestHeaders *headersList, const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles) override { return false; } // no reuse for Emscripten
56  bool reuse(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = false) override { return false; } // no reuse for Emscripten
57  void setupBufferContents(const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) override;
58  void setupFormMultipart(const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles) override;
59 
60  bool hasError() const override;
61  const char *getError() const override;
62 
63  long httpResponseCode() const override;
64  Common::String currentLocation() const override;
65  Common::HashMap<Common::String, Common::String> responseHeadersMap() const override;
66  void resetStream() override;
67 
68  uint32 read(void *dataPtr, uint32 dataSize) override;
69 
70  // Static callback functions
71  static void emscriptenOnSuccess(emscripten_fetch_t *fetch);
72  static void emscriptenOnError(emscripten_fetch_t *fetch);
73  static void emscriptenOnProgress(emscripten_fetch_t *fetch);
74  static void emscriptenOnReadyStateChange(emscripten_fetch_t *fetch);
75  void emscriptenDownloadFinished(bool success);
76 };
77 
78 } // End of namespace Networking
79 
80 #endif // EMSCRIPTEN
81 
82 #endif
Definition: str.h:59
Definition: scummvmcloud.h:32