Skip to content

Commit 9a1f446

Browse files
Added API to retrieve network statistics. (#757)
This API should enable users to query network statistics and aggregate the statistics by buckets (Wifi/Cellular/etc.) when needed. Resolves: OLPEDGE-1761 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 21db284 commit 9a1f446

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

olp-cpp-sdk-core/include/olp/core/http/Network.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ class CORE_API Network {
5151
/// Represents the request and response payload type
5252
using Payload = std::shared_ptr<std::ostream>;
5353

54+
/**
55+
* @brief The Statistics structure represents the network statistics for a
56+
* specific bucket.
57+
*/
58+
struct Statistics {
59+
/// The total bytes downloaded including size of headers and payload.
60+
uint64_t bytes_downloaded{0ull};
61+
/// The total bytes uploaded including size of headers and payload.
62+
uint64_t bytes_uploaded{0ull};
63+
/// The total number of requests made by network.
64+
uint32_t total_requests{0u};
65+
/// The total number of requests failed.
66+
uint32_t total_failed{0u};
67+
};
68+
5469
virtual ~Network() = default;
5570

5671
/**
@@ -90,7 +105,25 @@ class CORE_API Network {
90105
*
91106
* @param headers The default headers.
92107
*/
93-
virtual void SetDefaultHeaders(Headers) {}
108+
virtual void SetDefaultHeaders(Headers headers);
109+
110+
/**
111+
* @brief Set the current statistics bucket.
112+
*
113+
* @param[in] bucked_id The bucket ID.
114+
*/
115+
virtual void SetCurrentBucket(uint8_t bucket_id);
116+
117+
/**
118+
* @brief Get the statistics for a bucket.
119+
*
120+
* By default, this returns the statistics for the default bucket, with the ID 0.
121+
*
122+
* @param[in] bucked_id The bucket ID.
123+
*
124+
* @return Statistics which contains the statistic for the requested bucket.
125+
*/
126+
virtual Statistics GetStatistics(uint8_t bucket_id = 0);
94127
};
95128

96129
/**

olp-cpp-sdk-core/src/http/Network.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ std::shared_ptr<Network> CreateDefaultNetworkImpl(size_t max_requests_count) {
5252
}
5353
} // namespace
5454

55+
void Network::SetDefaultHeaders(Headers /*headers*/) {}
56+
57+
void Network::SetCurrentBucket(uint8_t /*bucket_id*/) {}
58+
59+
Network::Statistics Network::GetStatistics(uint8_t /*bucket_id*/) {
60+
return Network::Statistics{};
61+
}
62+
5563
CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
5664
size_t max_requests_count) {
5765
auto network = CreateDefaultNetworkImpl(max_requests_count);

0 commit comments

Comments
 (0)