Skip to content

Commit 08d8872

Browse files
authored
refactor: various client SDK lints (#298)
Removes a bunch of redundant namespace qualifiers + formatting changes in the client SDK.
1 parent 1ee08e6 commit 08d8872

File tree

8 files changed

+81
-65
lines changed

8 files changed

+81
-65
lines changed

contract-tests/client-contract-tests/src/entity_manager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include "entity_manager.hpp"
2-
#include <boost/json/parse.hpp>
32

43
#include <launchdarkly/config/client.hpp>
54
#include <launchdarkly/context_builder.hpp>
65
#include <launchdarkly/serialization/json_context.hpp>
76

7+
#include <boost/json.hpp>
8+
89
using launchdarkly::LogLevel;
910
using namespace launchdarkly::client_side;
1011

libs/client-sdk/src/client_impl.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <launchdarkly/events/asio_event_processor.hpp>
77
#include <launchdarkly/events/null_event_processor.hpp>
88

9+
#include <launchdarkly/detail/c_binding_helpers.hpp>
910
#include <launchdarkly/encoding/sha_256.hpp>
1011
#include <launchdarkly/logging/console_backend.hpp>
1112
#include <launchdarkly/logging/null_logger.hpp>
@@ -30,14 +31,14 @@ using launchdarkly::client_side::data_sources::DataSourceStatus;
3031
using launchdarkly::config::shared::built::DataSourceConfig;
3132
using launchdarkly::config::shared::built::HttpProperties;
3233

33-
static std::shared_ptr<::launchdarkly::data_sources::IDataSource>
34-
MakeDataSource(HttpProperties const& http_properties,
35-
Config const& config,
36-
Context const& context,
37-
boost::asio::any_io_executor const& executor,
38-
IDataSourceUpdateSink& flag_updater,
39-
data_sources::DataSourceStatusManager& status_manager,
40-
Logger& logger) {
34+
static std::shared_ptr<data_sources::IDataSource> MakeDataSource(
35+
HttpProperties const& http_properties,
36+
Config const& config,
37+
Context const& context,
38+
boost::asio::any_io_executor const& executor,
39+
IDataSourceUpdateSink& flag_updater,
40+
data_sources::DataSourceStatusManager& status_manager,
41+
Logger& logger) {
4142
if (config.Offline()) {
4243
return std::make_shared<data_sources::NullDataSource>(executor,
4344
status_manager);
@@ -80,39 +81,39 @@ static std::shared_ptr<IPersistence> MakePersistence(Config const& config) {
8081
return persistence.implementation;
8182
}
8283

83-
ClientImpl::ClientImpl(Config config,
84+
ClientImpl::ClientImpl(Config in_cfg,
8485
Context context,
8586
std::string const& version)
86-
: config_(config),
87+
: config_(std::move(in_cfg)), /* caution: do not use in_cfg (moved from!) */
8788
http_properties_(
88-
HttpPropertiesBuilder(config.HttpProperties())
89+
HttpPropertiesBuilder(config_.HttpProperties())
8990
.Header("user-agent", "CPPClient/" + version)
90-
.Header("authorization", config.SdkKey())
91-
.Header("x-launchdarkly-tags", config.ApplicationTag())
91+
.Header("authorization", config_.SdkKey())
92+
.Header("x-launchdarkly-tags", config_.ApplicationTag())
9293
.Build()),
93-
logger_(MakeLogger(config.Logging())),
94+
logger_(MakeLogger(config_.Logging())),
9495
ioc_(kAsioConcurrencyHint),
9596
work_(boost::asio::make_work_guard(ioc_)),
9697
context_(std::move(context)),
97-
flag_manager_(config.SdkKey(),
98+
flag_manager_(config_.SdkKey(),
9899
logger_,
99-
config.Persistence().max_contexts_,
100-
MakePersistence(config)),
100+
config_.Persistence().max_contexts_,
101+
MakePersistence(config_)),
101102
data_source_factory_([this]() {
102103
return MakeDataSource(http_properties_, config_, context_,
103104
ioc_.get_executor(), flag_manager_.Updater(),
104105
status_manager_, logger_);
105106
}),
106107
data_source_(nullptr),
107108
event_processor_(nullptr),
108-
eval_reasons_available_(config.DataSourceConfig().with_reasons) {
109+
eval_reasons_available_(config_.DataSourceConfig().with_reasons) {
109110
flag_manager_.LoadCache(context_);
110111

111-
if (config.Events().Enabled() && !config.Offline()) {
112+
if (config_.Events().Enabled() && !config_.Offline()) {
112113
event_processor_ =
113114
std::make_unique<events::AsioEventProcessor<ClientSDK>>(
114-
ioc_.get_executor(), config.ServiceEndpoints(), config.Events(),
115-
http_properties_, logger_);
115+
ioc_.get_executor(), config_.ServiceEndpoints(),
116+
config_.Events(), http_properties_, logger_);
116117
} else {
117118
event_processor_ = std::make_unique<events::NullEventProcessor>();
118119
}
@@ -160,14 +161,14 @@ void ClientImpl::RestartDataSource() {
160161

161162
std::future<bool> ClientImpl::StartAsyncInternal(
162163
std::function<bool(DataSourceStatus::DataSourceState)> result_predicate) {
163-
auto pr = std::make_shared<std::promise<bool>>();
164-
auto fut = pr->get_future();
164+
auto init_promise = std::make_shared<std::promise<bool>>();
165+
auto init_future = init_promise->get_future();
165166

166167
status_manager_.OnDataSourceStatusChangeEx(
167-
[result_predicate, pr](data_sources::DataSourceStatus status) {
168-
auto state = status.State();
169-
if (IsInitialized(state)) {
170-
pr->set_value(result_predicate(status.State()));
168+
[result = std::move(result_predicate),
169+
init_promise](data_sources::DataSourceStatus const& status) {
170+
if (auto const state = status.State(); IsInitialized(state)) {
171+
init_promise->set_value(result(status.State()));
171172
return true; /* delete this change listener since the desired
172173
state was reached */
173174
}
@@ -176,7 +177,7 @@ std::future<bool> ClientImpl::StartAsyncInternal(
176177

177178
RestartDataSource();
178179

179-
return fut;
180+
return init_future;
180181
}
181182

182183
std::future<bool> ClientImpl::StartAsync() {
@@ -272,14 +273,15 @@ EvaluationDetail<T> ClientImpl::VariationInternal(FlagKey const& key,
272273
event_processor_->SendAsync(std::move(event));
273274
return EvaluationDetail<T>(default_value, std::nullopt,
274275
std::move(error_reason));
276+
}
275277

276-
} else if (!Initialized()) {
278+
if (!Initialized()) {
277279
LD_LOG(logger_, LogLevel::kInfo)
278280
<< "LaunchDarkly client has not yet been initialized. "
279281
"Returning cached value";
280282
}
281283

282-
assert(desc->item);
284+
LD_ASSERT(desc->item);
283285

284286
auto const& flag = *(desc->item);
285287
auto const& detail = flag.Detail();

libs/client-sdk/src/client_impl.hpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,29 @@
11
#pragma once
22

3-
#include <boost/asio/executor_work_guard.hpp>
4-
#include <boost/asio/io_context.hpp>
5-
6-
#include <condition_variable>
7-
#include <cstdint>
8-
#include <memory>
9-
#include <optional>
10-
#include <shared_mutex>
11-
#include <thread>
12-
#include <tuple>
13-
14-
#include <tl/expected.hpp>
3+
#include "data_sources/data_source.hpp"
4+
#include "data_sources/data_source_status_manager.hpp"
5+
#include "flag_manager/flag_manager.hpp"
156

167
#include <launchdarkly/client_side/client.hpp>
178
#include <launchdarkly/client_side/data_source_status.hpp>
189
#include <launchdarkly/client_side/flag_notifier.hpp>
1910
#include <launchdarkly/config/client.hpp>
2011
#include <launchdarkly/context.hpp>
2112
#include <launchdarkly/data/evaluation_detail.hpp>
22-
#include <launchdarkly/data_sources/data_source.hpp>
2313
#include <launchdarkly/error.hpp>
14+
#include <launchdarkly/events/event_processor_interface.hpp>
2415
#include <launchdarkly/logging/logger.hpp>
2516
#include <launchdarkly/value.hpp>
2617

27-
#include <launchdarkly/events/event_processor_interface.hpp>
18+
#include <boost/asio/executor_work_guard.hpp>
19+
#include <boost/asio/io_context.hpp>
2820

29-
#include "data_sources/data_source_status_manager.hpp"
30-
#include "flag_manager/flag_manager.hpp"
21+
#include <condition_variable>
22+
#include <cstdint>
23+
#include <memory>
24+
#include <optional>
25+
#include <shared_mutex>
26+
#include <thread>
3127

3228
namespace launchdarkly::client_side {
3329
class ClientImpl : public IClient {
@@ -130,10 +126,10 @@ class ClientImpl : public IClient {
130126
mutable std::shared_mutex context_mutex_;
131127

132128
flag_manager::FlagManager flag_manager_;
133-
std::function<std::shared_ptr<::launchdarkly::data_sources::IDataSource>()>
129+
std::function<std::shared_ptr<data_sources::IDataSource>()>
134130
data_source_factory_;
135131

136-
std::shared_ptr<::launchdarkly::data_sources::IDataSource> data_source_;
132+
std::shared_ptr<data_sources::IDataSource> data_source_;
137133

138134
std::unique_ptr<events::IEventProcessor> event_processor_;
139135

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
#include <future>
3+
4+
namespace launchdarkly::client_side::data_sources {
5+
6+
class IDataSource {
7+
public:
8+
virtual void Start() = 0;
9+
virtual void ShutdownAsync(std::function<void()>) = 0;
10+
virtual ~IDataSource() = default;
11+
IDataSource(IDataSource const& item) = delete;
12+
IDataSource(IDataSource&& item) = delete;
13+
IDataSource& operator=(IDataSource const&) = delete;
14+
IDataSource& operator=(IDataSource&&) = delete;
15+
16+
protected:
17+
IDataSource() = default;
18+
};
19+
20+
} // namespace launchdarkly::client_side::data_sources

libs/client-sdk/src/data_sources/data_source_event_handler.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <launchdarkly/config/shared/built/service_endpoints.hpp>
99
#include <launchdarkly/context.hpp>
1010
#include <launchdarkly/data/evaluation_result.hpp>
11-
#include <launchdarkly/data_sources/data_source.hpp>
1211
#include <launchdarkly/logging/logger.hpp>
1312

1413
namespace launchdarkly::client_side::data_sources {

libs/client-sdk/src/data_sources/null_data_source.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#pragma once
22

3-
#include <boost/asio/any_io_executor.hpp>
4-
3+
#include "data_source.hpp"
54
#include "data_source_status_manager.hpp"
65

7-
#include <launchdarkly/data_sources/data_source.hpp>
6+
#include <boost/asio/any_io_executor.hpp>
87

98
namespace launchdarkly::client_side::data_sources {
109

11-
class NullDataSource : public ::launchdarkly::data_sources::IDataSource {
10+
class NullDataSource : public IDataSource {
1211
public:
1312
explicit NullDataSource(boost::asio::any_io_executor exec,
1413
DataSourceStatusManager& status_manager);

libs/client-sdk/src/data_sources/polling_data_source.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
#pragma once
22

3-
#include <chrono>
4-
5-
#include <boost/asio/any_io_executor.hpp>
6-
3+
#include "data_source.hpp"
74
#include "data_source_event_handler.hpp"
85
#include "data_source_status_manager.hpp"
96
#include "data_source_update_sink.hpp"
107

118
#include <launchdarkly/config/shared/built/data_source_config.hpp>
129
#include <launchdarkly/config/shared/built/http_properties.hpp>
1310
#include <launchdarkly/config/shared/built/service_endpoints.hpp>
14-
#include <launchdarkly/data_sources/data_source.hpp>
1511
#include <launchdarkly/logging/logger.hpp>
1612
#include <launchdarkly/network/asio_requester.hpp>
1713

14+
#include <chrono>
15+
16+
#include <boost/asio/any_io_executor.hpp>
17+
1818
namespace launchdarkly::client_side::data_sources {
1919

2020
class PollingDataSource
21-
: public ::launchdarkly::data_sources::IDataSource,
21+
: public IDataSource,
2222
public std::enable_shared_from_this<PollingDataSource> {
2323
public:
2424
PollingDataSource(

libs/client-sdk/src/data_sources/streaming_data_source.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#pragma once
22

3-
#include <chrono>
4-
using namespace std::chrono_literals;
5-
63
#include <boost/asio/any_io_executor.hpp>
74

5+
#include "data_source.hpp"
86
#include "data_source_event_handler.hpp"
97
#include "data_source_status_manager.hpp"
108
#include "data_source_update_sink.hpp"
@@ -15,14 +13,15 @@ using namespace std::chrono_literals;
1513
#include <launchdarkly/config/shared/built/service_endpoints.hpp>
1614
#include <launchdarkly/context.hpp>
1715
#include <launchdarkly/data/evaluation_result.hpp>
18-
#include <launchdarkly/data_sources/data_source.hpp>
1916
#include <launchdarkly/logging/logger.hpp>
2017
#include <launchdarkly/sse/client.hpp>
2118

19+
#include <chrono>
20+
2221
namespace launchdarkly::client_side::data_sources {
2322

2423
class StreamingDataSource final
25-
: public ::launchdarkly::data_sources::IDataSource,
24+
: public IDataSource,
2625
public std::enable_shared_from_this<StreamingDataSource> {
2726
public:
2827
StreamingDataSource(

0 commit comments

Comments
 (0)