olp-cpp-sdk 1.24.0
Loading...
Searching...
No Matches
Network.h
1/*
2 * Copyright (C) 2019-2024 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 <cstdint>
23#include <functional>
24#include <memory>
25#include <string>
26
27#include "olp/core/CoreApi.h"
28#include "olp/core/http/NetworkInitializationSettings.h"
29#include "olp/core/http/NetworkRequest.h"
30#include "olp/core/http/NetworkResponse.h"
31#include "olp/core/http/NetworkTypes.h"
32
33namespace olp {
35namespace http {
36
38class CORE_API Network {
39 public:
41 using Callback = std::function<void(NetworkResponse response)>;
42
45 std::function<void(std::string key, std::string value)>;
46
48 using DataCallback = std::function<void(
49 const std::uint8_t* data, std::uint64_t offset, std::size_t length)>;
50
52 using Payload = std::shared_ptr<std::ostream>;
53
55 struct Statistics {
57 uint64_t bytes_downloaded{0ull};
58
60 uint64_t bytes_uploaded{0ull};
61
63 uint32_t total_requests{0u};
64
66 uint32_t total_failed{0u};
67 };
68
69 virtual ~Network() = default;
70
89 virtual SendOutcome Send(NetworkRequest request, Payload payload,
90 Callback callback,
91 HeaderCallback header_callback = nullptr,
92 DataCallback data_callback = nullptr) = 0;
93
118 virtual void Cancel(RequestId id) = 0;
119
128 virtual void SetDefaultHeaders(Headers headers);
129
135 virtual void SetCurrentBucket(uint8_t bucket_id);
136
147 virtual Statistics GetStatistics(uint8_t bucket_id = 0);
148};
149
151CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
153
154} // namespace http
155} // namespace olp
A network request abstraction for an HTTP request.
Definition NetworkRequest.h:34
A network response abstraction for the HTTP request.
Definition NetworkResponse.h:62
An HTTP client abstraction.
Definition Network.h:38
std::function< void(const std::uint8_t *data, std::uint64_t offset, std::size_t length)> DataCallback
The callback that is called when a chunk of data is received.
Definition Network.h:49
virtual Statistics GetStatistics(uint8_t bucket_id=0)
Gets the statistics for a bucket.
virtual void Cancel(RequestId id)=0
Cancels the request associated with the given RequestId.
std::shared_ptr< std::ostream > Payload
The request and response payload type.
Definition Network.h:52
virtual void SetDefaultHeaders(Headers headers)
Sets the default network headers.
std::function< void(std::string key, std::string value)> HeaderCallback
The callback that is called when a header is received.
Definition Network.h:45
virtual void SetCurrentBucket(uint8_t bucket_id)
Sets the current bucket statistics.
std::function< void(NetworkResponse response)> Callback
The callback that is called when the request is processed or canceled.
Definition Network.h:41
virtual SendOutcome Send(NetworkRequest request, Payload payload, Callback callback, HeaderCallback header_callback=nullptr, DataCallback data_callback=nullptr)=0
Sends the network request.
Rrepresents the outcome of a network request.
Definition NetworkTypes.h:76
CORE_API std::shared_ptr< Network > CreateDefaultNetwork(NetworkInitializationSettings settings)
Creates a default Network implementation.
std::uint64_t RequestId
A unique request ID.
Definition NetworkTypes.h:41
std::vector< Header > Headers
An alias for a vector of the HTTP headers.
Definition NetworkTypes.h:140
Rules all the other namespaces.
Definition AppleSignInProperties.h:24
Settings for network initialization.
Definition NetworkInitializationSettings.h:32
Network statistics for a specific bucket.
Definition Network.h:55