cesium-native 0.50.0
Loading...
Searching...
No Matches
CesiumIonAssetAccessor.h
1#pragma once
2
3#include <CesiumAsync/AsyncSystem.h>
4#include <CesiumAsync/IAssetAccessor.h>
5#include <CesiumAsync/IAssetRequest.h>
6#include <CesiumAsync/IAssetResponse.h>
7
8#include <functional>
9#include <memory>
10#include <optional>
11#include <string>
12
13namespace CesiumAsync {
14
24 : public std::enable_shared_from_this<CesiumIonAssetAccessor>,
25 public IAssetAccessor {
26public:
30 struct UpdatedToken {
34 std::string token;
35
40 };
41
46 const std::shared_ptr<spdlog::logger>& pLogger,
47 const std::shared_ptr<IAssetAccessor>& pAggregatedAccessor,
48 const std::string& assetEndpointUrl,
49 const std::vector<IAssetAccessor::THeader>& assetEndpointHeaders,
50 std::function<Future<void>(const UpdatedToken&)> updatedTokenCallback);
51
56 get(const AsyncSystem& asyncSystem,
57 const std::string& url,
58 const std::vector<THeader>& headers = {}) override;
59
64 const AsyncSystem& asyncSystem,
65 const std::string& verb,
66 const std::string& url,
67 const std::vector<THeader>& headers = std::vector<THeader>(),
68 const std::span<const std::byte>& contentPayload = {}) override;
69
73 void tick() noexcept override;
74
80
81private:
82 SharedFuture<UpdatedToken> refreshTokenInMainThread(
83 const AsyncSystem& asyncSystem,
84 const std::string& currentAuthorizationHeader,
85 const std::string& currentAccessTokenQueryParameterValue);
86
87 std::shared_ptr<spdlog::logger> _pLogger;
88 std::shared_ptr<IAssetAccessor> _pAggregatedAccessor;
89 std::string _assetEndpointUrl;
90 std::vector<IAssetAccessor::THeader> _assetEndpointHeaders;
91 std::optional<std::function<Future<void>(const UpdatedToken&)>>
92 _maybeUpdatedTokenCallback;
93 std::optional<SharedFuture<UpdatedToken>> _tokenRefreshInProgress;
94};
95
96} // namespace CesiumAsync
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
CesiumIonAssetAccessor(const std::shared_ptr< spdlog::logger > &pLogger, const std::shared_ptr< IAssetAccessor > &pAggregatedAccessor, const std::string &assetEndpointUrl, const std::vector< IAssetAccessor::THeader > &assetEndpointHeaders, std::function< Future< void >(const UpdatedToken &)> updatedTokenCallback)
Creates a new instance.
Future< std::shared_ptr< IAssetRequest > > get(const AsyncSystem &asyncSystem, const std::string &url, const std::vector< THeader > &headers={}) override
void notifyOwnerIsBeingDestroyed()
Notifies this accessor that it's owner has been destroyed. When the owner is destroyed,...
void tick() noexcept override
Future< std::shared_ptr< IAssetRequest > > request(const AsyncSystem &asyncSystem, const std::string &verb, const std::string &url, const std::vector< THeader > &headers=std::vector< THeader >(), const std::span< const std::byte > &contentPayload={}) override
A value that will be available in the future, as produced by AsyncSystem.
Definition Future.h:29
Provides asynchronous access to assets, usually files downloaded via HTTP.
std::pair< std::string, std::string > THeader
An HTTP header represented as a key/value pair.
A value that will be available in the future, as produced by AsyncSystem. Unlike Future,...
Classes that support asynchronous operations.
STL namespace.
std::string authorizationHeader
The new Authorization header containing the new token.