Polyphase Game Engine
Loading...
Searching...
No Matches
HttpBackend.h
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <memory>
5
8
9// Abstract HTTP backend interface — one concrete implementation per platform
10// (WinHTTP on Windows, libcurl on Linux, httpc on 3DS, libogc TCP + mbedTLS on
11// Wii/GCN, stub elsewhere). Backends are blocking: the worker thread inside
12// HttpClient is what makes the public API async.
14{
15public:
16 virtual ~HttpBackend() = default;
17
18 // Backend-wide initialization. Called once during Http::Initialize.
19 // Return false to disable the backend (the stub backend will be used
20 // instead, and IsAvailable() will return false).
21 virtual bool Initialize() = 0;
22
23 // Symmetric teardown.
24 virtual void Shutdown() = 0;
25
26 // True when this backend is functional in the current environment.
27 // libcurl-on-Linux returns false here when libcurl isn't installed.
28 virtual bool IsAvailable() const = 0;
29
30 // Diagnostic string when IsAvailable() is false.
31 virtual const char* GetMissingDependencyMessage() const { return ""; }
32
33 // Synchronous request execution. The cancel flag is checked periodically
34 // by the backend during the request loop. Backends MUST populate
35 // outResponse with a status, headers, body, and on failure an HttpError.
36 virtual void PerformRequest(const HttpRequest& request,
37 std::atomic<bool>& cancelFlag,
38 HttpResponse& outResponse) = 0;
39};
40
41// Factory — returns the appropriate backend for the current platform.
42// Implemented per-platform: only one of the HttpBackend_*.cpp files is
43// compiled into a given build.
44std::unique_ptr<HttpBackend> CreatePlatformHttpBackend();
std::unique_ptr< HttpBackend > CreatePlatformHttpBackend()
Definition HttpBackend_Stub.cpp:35
Definition HttpBackend.h:14
virtual ~HttpBackend()=default
virtual bool IsAvailable() const =0
virtual void Shutdown()=0
virtual const char * GetMissingDependencyMessage() const
Definition HttpBackend.h:31
virtual void PerformRequest(const HttpRequest &request, std::atomic< bool > &cancelFlag, HttpResponse &outResponse)=0
virtual bool Initialize()=0
Definition HttpRequest.h:20
Definition HttpResponse.h:16