olp-cpp-sdk  1.19.0
OlpClientSettings.h
1 /*
2  * Copyright (C) 2019-2023 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <chrono>
23 #include <functional>
24 #include <memory>
25 #include <string>
26 
27 #include <boost/optional.hpp>
28 
29 #include <olp/core/client/CancellationContext.h>
30 #include <olp/core/client/CancellationToken.h>
31 #include <olp/core/client/DefaultLookupEndpointProvider.h>
32 #include <olp/core/client/HRN.h>
33 #include <olp/core/client/HttpResponse.h>
34 #include <olp/core/client/OauthToken.h>
35 #include <olp/core/client/RetrySettings.h>
36 #include <olp/core/http/Network.h>
37 
38 namespace olp {
39 namespace cache {
40 class KeyValueCache;
41 } // namespace cache
42 
43 namespace thread {
44 class TaskScheduler;
45 } // namespace thread
46 
47 namespace http {
48 class Network;
49 } // namespace http
50 
51 namespace client {
57 using NetworkAsyncCallback = std::function<void(HttpResponse)>;
58 
64 using NetworkAsyncCancel = std::function<void()>;
65 
75 struct CORE_API AuthenticationSettings {
77  using ApiKeyProviderType = std::function<std::string()>;
78 
97  std::function<OauthTokenResponse(CancellationContext&)>;
98 
105  TokenProviderCancellableCallback token_provider = nullptr;
106 
117  ApiKeyProviderType api_key_provider = nullptr;
118 };
119 
123 struct CORE_API ApiLookupSettings {
135  using LookupEndpointProvider = std::function<std::string(const std::string&)>;
136 
150  using CatalogEndpointProvider = std::function<std::string(const HRN&)>;
151 
161  LookupEndpointProvider lookup_endpoint_provider =
163 
174  CatalogEndpointProvider catalog_endpoint_provider = nullptr;
175 };
176 
180 struct CORE_API OlpClientSettings {
185 
190 
196  boost::optional<http::NetworkProxySettings> proxy_settings = boost::none;
197 
203  boost::optional<AuthenticationSettings> authentication_settings = boost::none;
204 
210  std::shared_ptr<thread::TaskScheduler> task_scheduler = nullptr;
211 
217  std::shared_ptr<http::Network> network_request_handler = nullptr;
218 
226  std::shared_ptr<cache::KeyValueCache> cache = nullptr;
227 
240  std::chrono::seconds default_cache_expiration = std::chrono::seconds::max();
241 };
242 
243 } // namespace client
244 } // namespace olp
A wrapper that manages the cancellation state of an asynchronous operation in a thread-safe way.
Definition: CancellationContext.h:40
Allows a Here Resource Name (HRN) to be passed to the operations that require it.
Definition: HRN.h:34
This class represents the HTTP response created from the NetworkResponse and the request body.
Definition: HttpResponse.h:89
std::function< void()> NetworkAsyncCancel
An alias for the cancel function.
Definition: OlpClientSettings.h:64
ApiResponse< OauthToken, ApiError > OauthTokenResponse
An alias for the OAuth token response.
Definition: OauthToken.h:90
std::function< void(HttpResponse)> NetworkAsyncCallback
An alias for the asynchronous network callback.
Definition: OlpClientSettings.h:57
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24
Settings to provide URLs for API lookup requests.
Definition: OlpClientSettings.h:123
std::function< std::string(const std::string &)> LookupEndpointProvider
An alias for the lookup provider function.
Definition: OlpClientSettings.h:135
std::function< std::string(const HRN &)> CatalogEndpointProvider
An alias for the catalog endpoint provider function.
Definition: OlpClientSettings.h:150
A set of settings that manages the TokenProviderCallback and TokenProviderCancelCallback functions.
Definition: OlpClientSettings.h:75
std::function< std::string()> ApiKeyProviderType
An alias for the ApiKey provider.
Definition: OlpClientSettings.h:77
std::function< OauthTokenResponse(CancellationContext &)> TokenProviderCancellableCallback
Implemented by the client that should return the OAuth2 bearer access token if the operation is succe...
Definition: OlpClientSettings.h:97
The default implementation of the lookup API endpoint provider.
Definition: DefaultLookupEndpointProvider.h:35
Configures the behavior of the OlpClient class.
Definition: OlpClientSettings.h:180
RetrySettings retry_settings
The retry settings.
Definition: OlpClientSettings.h:184
ApiLookupSettings api_lookup_settings
API Lookup settings.
Definition: OlpClientSettings.h:189
A collection of settings that controls how failed requests should be treated by the Data SDK.
Definition: RetrySettings.h:47