1#include "HTTPRasterSource.h"
3#include "../Bridge/TerrainProviderFunctions.h"
5#include "Desktop/HTTP/BasicAuth.h"
6#include "Desktop/HTTP/HTTPDataFetcher.h"
9#include "Services/Services.h"
11#include "Foundation/Logging/Logger.h"
19Cogs::Core::TerrainProvider::HTTPRasterSource::HTTPRasterSource(
Context* context)
20 : BaseRasterSource(context)
21 , httpDataFetcher(context)
25bool Cogs::Core::TerrainProvider::HTTPRasterSource::init(
const HTTPConfig& conf, std::unique_ptr<ICache>&& icache)
27 baseUrl = conf.baseUrl;
28 if (baseUrl == NoString) {
29 LOG_ERROR(logger,
"No Base URL set");
32 username = conf.username;
33 password = conf.password;
35 if (password != NoString && password != NoString) {
36 Cogs::Desktop::BasicAuth::Configuration authConfig = {
37 Strings::get(baseUrl).to_string(),
38 Strings::get(username).to_string(),
39 Strings::get(password).to_string()
41 httpDataFetcher.addAuthProvider(std::make_shared<Cogs::Desktop::BasicAuth>(std::move(authConfig)));
44 return BaseRasterSource::init(conf, std::move(icache));
47void Cogs::Core::TerrainProvider::HTTPRasterSource::getConfig(HTTPConfig& conf)
const
49 BaseRasterSource::getConfig(conf);
50 conf.baseUrl = baseUrl;
51 conf.username = username;
52 conf.password = password;
55void Cogs::Core::TerrainProvider::HTTPRasterSource::requestTile(Request* req)
58 if (createFetchTileUrl(url, req->id)) {
60 auto fetchCb = [
this, req, url](Cogs::FileContents::Ptr&& contents) {
62 std::string debugLog =
"URL: " + url;
63 debugLog.append(
"\n\nSuccess: false" \
65 addTileFailure(req, debugLog);
69 MimeType kind = parseMimeType(contents->mimeTypeHash);
73 if (kind == MimeType::XML || kind == MimeType::None) {
74 std::string debugLog =
"URL: " + url;
75 debugLog.append(
"\n\nSuccess: false");
77 if (kind == MimeType::XML) {
78 debugLog.append(
"\n\nContent Type: ");
79 debugLog.append(Strings::getC(mimeTypeString(kind)));
80 debugLog.append(
"\n\nContent:\n");
81 debugLog.append(
static_cast<const char*
>(contentsBuff.data()), contentsBuff.size());
84 addTileFailure(req, debugLog);
90 debugLog.append(
"URL: ");
92 debugLog.append(
"\n\nSuccess: true");
93 debugLog.append(
"\n\nContent Type: ");
94 debugLog.append(Strings::getC(mimeTypeString(kind)));
95 debugLog.append(
"\n\nContent:\n");
96 debugLog.append(
static_cast<const char*
>(contentsBuff.data()), contentsBuff.size());
99 addTile(contentsBuff, kind, req, debugLog);
102 httpDataFetcher.fetchAsync(url, fetchCb, 0, 0, 0, Cogs::FileContentsHints::None);
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Log implementation class.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
constexpr Log getLogger(const char(&name)[LEN]) noexcept