Skip to content

Commit 0601a42

Browse files
Align CancellationToken to google style
Allow compiler to generate copy/move constructors and assignment operators. Resolves: OLPEDGE-1130 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent c099ef3 commit 0601a42

30 files changed

+92
-92
lines changed

olp-cpp-sdk-core/include/olp/core/client/CancellationContext.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ inline void CancellationContext::CancelOperation() {
5858
return;
5959
}
6060

61-
impl_->sub_operation_cancel_token_.cancel();
61+
impl_->sub_operation_cancel_token_.Cancel();
6262
impl_->sub_operation_cancel_token_ = CancellationToken();
6363
impl_->is_cancelled_ = true;
6464
}

olp-cpp-sdk-core/include/olp/core/client/CancellationToken.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <functional>
2323

2424
#include <olp/core/CoreApi.h>
25+
#include <olp/core/porting/deprecated.h>
2526

2627
namespace olp {
2728
namespace client {
@@ -40,18 +41,18 @@ class CORE_API CancellationToken {
4041
* @param func an operation that should be used to cancel an authentication
4142
* request.
4243
*/
43-
CancellationToken(const std::function<void()> func);
44+
CancellationToken(std::function<void()> func);
4445

4546
/**
46-
* @brief Copy Constructor
47-
* @param other object to copy from
47+
* @brief Cancels the current operation, calls the func_ instance variable.
4848
*/
49-
CancellationToken(const CancellationToken& other);
49+
OLP_SDK_DEPRECATED("Deprecated, use Cancel instead.")
50+
void cancel() const;
5051

5152
/**
5253
* @brief Cancels the current operation, calls the func_ instance variable.
5354
*/
54-
void cancel() const;
55+
void Cancel() const;
5556

5657
private:
5758
std::function<void()> func_{};

olp-cpp-sdk-core/src/client/CancellationToken.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121

2222
namespace olp {
2323
namespace client {
24-
CancellationToken::CancellationToken(const std::function<void()> func)
25-
: func_(func) {}
24+
CancellationToken::CancellationToken(std::function<void()> func)
25+
: func_(std::move(func)) {}
2626

27-
CancellationToken::CancellationToken(const CancellationToken& other)
28-
: func_(other.func_) {}
27+
void CancellationToken::cancel() const { Cancel(); }
2928

30-
void CancellationToken::cancel() const {
29+
void CancellationToken::Cancel() const {
3130
if (func_) {
3231
func_();
3332
}

olp-cpp-sdk-core/src/client/PendingRequests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ bool PendingRequests::CancelAll() {
4242
}
4343

4444
for (auto& pair : requests_map) {
45-
pair.second.cancel();
45+
pair.second.Cancel();
4646
}
4747

4848
for (auto context : contexts) {
49-
context.CancelToken().cancel();
49+
context.CancelToken().Cancel();
5050
}
5151

5252
return true;

olp-cpp-sdk-core/tests/client/TaskContextTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ TEST(TaskContextTest, CancelToken) {
206206

207207
EXPECT_TRUE(execution_started.Wait());
208208

209-
context.CancelToken().cancel();
209+
context.CancelToken().Cancel();
210210

211211
continue_execution.Notify();
212212

olp-cpp-sdk-core/tests/olpclient/OlpClientTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ TEST_F(OlpClientTest, CancelBeforeResponse) {
934934
std::multimap<std::string, std::string>(),
935935
nullptr, std::string(), callback);
936936

937-
cancel_token.cancel();
937+
cancel_token.Cancel();
938938
wait_for_cancel->set_value(true);
939939
ASSERT_TRUE(was_cancelled->load());
940940
ASSERT_EQ(std::future_status::ready,
@@ -976,7 +976,7 @@ TEST_F(OlpClientTest, CancelAfterCompletion) {
976976
nullptr, std::string(), callback);
977977

978978
auto response = promise.get_future().get();
979-
cancel_token.cancel();
979+
cancel_token.Cancel();
980980

981981
ASSERT_TRUE(was_cancelled->load());
982982
}
@@ -1021,11 +1021,11 @@ TEST_F(OlpClientTest, CancelDuplicate) {
10211021
std::multimap<std::string, std::string>(),
10221022
nullptr, std::string(), callback);
10231023

1024-
cancel_token.cancel();
1025-
cancel_token.cancel();
1026-
cancel_token.cancel();
1024+
cancel_token.Cancel();
1025+
cancel_token.Cancel();
1026+
cancel_token.Cancel();
10271027
wait_for_cancel->set_value(true);
1028-
cancel_token.cancel();
1028+
cancel_token.Cancel();
10291029

10301030
ASSERT_TRUE(was_cancelled->load());
10311031
ASSERT_EQ(std::future_status::ready,
@@ -1083,7 +1083,7 @@ TEST_F(OlpClientTest, CancelRetry) {
10831083
nullptr, std::string(), callback);
10841084

10851085
wait_for_cancel->get_future().get();
1086-
cancel_token.cancel();
1086+
cancel_token.Cancel();
10871087

10881088
EXPECT_EQ(std::future_status::ready,
10891089
promise.get_future().wait_for(std::chrono::seconds(2)));

olp-cpp-sdk-dataservice-read/src/ApiClientLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ApiClientLookup::ApiClientResponse ApiClientLookup::LookupApi(
186186

187187
return client::CancellationToken([&, token, flag]() {
188188
if (flag->exchange(false)) {
189-
token.cancel();
189+
token.Cancel();
190190
condition.Notify();
191191
}
192192
});

olp-cpp-sdk-dataservice-read/src/Common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ inline client::CancellationToken ScheduleFetch(TaskScheduler&& schedule_task,
5252
std::move(request.WithFetchOption(FetchOptions::OnlineOnly)), nullptr);
5353

5454
return client::CancellationToken([=]() {
55-
cache_token.cancel();
56-
online_token.cancel();
55+
cache_token.Cancel();
56+
online_token.Cancel();
5757
});
5858
}
5959

olp-cpp-sdk-dataservice-read/src/MultiRequestContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class MultiRequestContext final {
6565
OLP_SDK_LOG_INFO_F(kMultiRequestContextLogTag,
6666
"~MultiRequestContext() -> cancelling id %s",
6767
itr->first.c_str());
68-
itr->second->cancellation_token_.cancel();
68+
itr->second->cancellation_token_.Cancel();
6969
}
7070
}
7171

@@ -199,7 +199,7 @@ class MultiRequestContext final {
199199
// this is the last callback.
200200
// cancel the underlying request, allowing the provider to invoke the
201201
// callback(s)
202-
context->cancellation_token_.cancel();
202+
context->cancellation_token_.Cancel();
203203
}
204204

205205
auto req = *requestItr;

olp-cpp-sdk-dataservice-read/src/repositories/CatalogRepository.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ read::CatalogResponse CatalogRepository::GetCatalog(
208208

209209
return CancellationToken([&, interest_flag, token]() {
210210
if (interest_flag->exchange(false)) {
211-
token.cancel();
211+
token.Cancel();
212212
condition.Notify();
213213
}
214214
});
@@ -384,7 +384,7 @@ MetadataApi::CatalogVersionResponse CatalogRepository::GetLatestVersion(
384384

385385
return client::CancellationToken([&, interest_flag, token]() {
386386
if (interest_flag->exchange(false)) {
387-
token.cancel();
387+
token.Cancel();
388388
condition.Notify();
389389
}
390390
});

0 commit comments

Comments
 (0)