Skip to content

Commit

Permalink
Remove deprecated OlpClient functions (#1559)
Browse files Browse the repository at this point in the history
Constructor should be used instead

Relates-To: OCMAM-212

Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
  • Loading branch information
andrey-kashcheev authored Oct 17, 2024
1 parent 4f07bae commit 60f7ef8
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 218 deletions.
4 changes: 1 addition & 3 deletions olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ client::OlpClient CreateOlpClient(
settings.retry_settings.max_attempts = 0;
}

client::OlpClient client;
client.SetBaseUrl(auth_settings.token_endpoint_url);
client.SetSettings(std::move(settings));
client::OlpClient client(settings, auth_settings.token_endpoint_url);
return client;
}

Expand Down
17 changes: 1 addition & 16 deletions olp-cpp-sdk-core/include/olp/core/client/OlpClient.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2023 HERE Europe B.V.
* Copyright (C) 2019-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -92,21 +92,6 @@ class CORE_API OlpClient {
*/
ParametersType& GetMutableDefaultHeaders();

/**
* @brief Sets the client settings.
*
* @note Handle with care and do not change while requests are ongoing.
* Ideally the settings would not change during the lifecycle of this
* instance.
*
* @param settings The client settings.
*
* @deprecated This method will be removed by 05.2021. Please use the
* constructor instead. The settings should not change during the lifetime of
* the instance.
*/
void SetSettings(const OlpClientSettings& settings);

/**
* @brief Getter function to retrieve client settings.
*
Expand Down
28 changes: 17 additions & 11 deletions olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 HERE Europe B.V.
* Copyright (C) 2020-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,9 +47,7 @@ std::string FindApi(const Apis& apis, const std::string& service,

OlpClient CreateClient(const std::string& base_url,
const OlpClientSettings& settings) {
OlpClient client;
client.SetBaseUrl(base_url);
client.SetSettings(settings);
OlpClient client(settings, base_url);
return client;
}

Expand Down Expand Up @@ -227,20 +225,28 @@ CancellationToken ApiLookupClientImpl::LookupApi(
OlpClient ApiLookupClientImpl::CreateAndCacheClient(
const std::string& base_url, const std::string& cache_key,
boost::optional<time_t> expiration) {
const auto new_expiration =
std::chrono::steady_clock::now() +
std::chrono::seconds(expiration.value_or(kLookupApiDefaultExpiryTime));

std::lock_guard<std::mutex> lock(cached_clients_mutex_);
ClientWithExpiration& client_with_expiration = cached_clients_[cache_key];

const auto current_base_url = client_with_expiration.client.GetBaseUrl();
if (current_base_url.empty()) {
client_with_expiration.client.SetSettings(settings_);
auto findIt = cached_clients_.find(cache_key);
if (findIt == cached_clients_.end()) {
auto emplace_result = cached_clients_.emplace(
cache_key,
ClientWithExpiration{OlpClient(settings_, base_url), new_expiration});
return emplace_result.first->second.client;
}

ClientWithExpiration& client_with_expiration = findIt->second;
const auto current_base_url = client_with_expiration.client.GetBaseUrl();
if (current_base_url != base_url) {
client_with_expiration.client.SetBaseUrl(base_url);
}

client_with_expiration.expire_at =
std::chrono::steady_clock::now() +
std::chrono::seconds(expiration.value_or(kLookupApiDefaultExpiryTime));
client_with_expiration.expire_at = new_expiration;

return client_with_expiration.client;
}

Expand Down
10 changes: 0 additions & 10 deletions olp-cpp-sdk-core/src/client/OlpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ class OlpClient::OlpClientImpl {
std::string GetBaseUrl() const;

ParametersType& GetMutableDefaultHeaders();
void SetSettings(const OlpClientSettings& settings);
const OlpClientSettings& GetSettings() const { return settings_; }

CancellationToken CallApi(const std::string& path, const std::string& method,
Expand Down Expand Up @@ -527,11 +526,6 @@ OlpClient::OlpClientImpl::GetMutableDefaultHeaders() {
return default_headers_;
}

void OlpClient::OlpClientImpl::SetSettings(const OlpClientSettings& settings) {
// I would not expect that settings change during lifetime of the instance.
settings_ = settings;
}

boost::optional<client::ApiError> OlpClient::OlpClientImpl::AddBearer(
bool query_empty, http::NetworkRequest& request,
CancellationContext& context) const {
Expand Down Expand Up @@ -853,10 +847,6 @@ OlpClient::ParametersType& OlpClient::GetMutableDefaultHeaders() {
return impl_->GetMutableDefaultHeaders();
}

void OlpClient::SetSettings(const OlpClientSettings& settings) {
impl_->SetSettings(settings);
}

const OlpClientSettings& OlpClient::GetSettings() const {
return impl_->GetSettings();
}
Expand Down
6 changes: 3 additions & 3 deletions olp-cpp-sdk-core/src/client/OlpClientFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2021 HERE Europe B.V.
* Copyright (C) 2019-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,8 +27,8 @@ namespace client {

std::shared_ptr<OlpClient> OlpClientFactory::Create(
const OlpClientSettings& settings) {
auto olp_client = std::make_shared<OlpClient>();
olp_client->SetSettings(settings);
const auto kEmptyBaseUrl = std::string();
auto olp_client = std::make_shared<OlpClient>(settings, kEmptyBaseUrl);
return olp_client;
}

Expand Down
Loading

0 comments on commit 60f7ef8

Please sign in to comment.