Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ option(BUILD_TESTING "Enable C++ unit tests." ON)
option(TESTING_SANITIZERS "Enable sanitizers for unit tests." ON)

if (BUILD_TESTING)
add_compile_definitions(LAUNCHDARKLY_USE_ASSERT)
if (TESTING_SANITIZERS)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined -fsanitize=leak")
Expand Down Expand Up @@ -62,7 +63,7 @@ else ()
else ()
set(Boost_USE_STATIC_LIBS ON)
endif ()
endif()
endif ()

set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
Expand Down
42 changes: 23 additions & 19 deletions apps/hello-cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ int main() {
return 1;
}

Client client(
ConfigBuilder(key)
.ServiceEndpoints(
launchdarkly::client_side::EndpointsBuilder()
// Set to http to demonstrate redirect to https.
.PollingBaseUrl("http://sdk.launchdarkly.com")
.StreamingBaseUrl("https://stream.launchdarkly.com")
.EventsBaseUrl("https://events.launchdarkly.com"))
.DataSource(DataSourceBuilder()
.Method(DataSourceBuilder::Polling().PollInterval(
std::chrono::seconds{30}))
.WithReasons(true)
.UseReport(true))
.Logging(LoggingBuilder::BasicLogging().Level(LogLevel::kDebug))
.Events(launchdarkly::client_side::EventsBuilder().FlushInterval(
std::chrono::seconds(5)))
.Build()
.value(),
ContextBuilder().kind("user", "ryan").build());
auto config_builder = ConfigBuilder(key);

config_builder.ServiceEndpoints()
.PollingBaseUrl("http://sdk.launchdarkly.com")
.StreamingBaseUrl("https://stream.launchdarkly.com")
.EventsBaseUrl("https://events.launchdarkly.com");
config_builder.DataSource()
.Method(
DataSourceBuilder::Polling().PollInterval(std::chrono::seconds{30}))
.WithReasons(true)
.UseReport(true);
config_builder.Logging().Logging(
LoggingBuilder::BasicLogging().Level(LogLevel::kDebug));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably slightly improve this by adding Basic()/Custom() members to the logging builder, so it's not Logging().Logging. Hmm

config_builder.Events().FlushInterval(std::chrono::seconds(5));

auto config = config_builder.Build();
if (!config) {
std::cout << config.error();
return 1;
}

Client client(std::move(*config),
ContextBuilder().kind("user", "ryan").build());

std::cout << "Initial Status: " << client.DataSourceStatus().Status()
<< std::endl;
Expand Down
16 changes: 5 additions & 11 deletions apps/sdk-contract-tests/src/entity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
auto default_endpoints =
launchdarkly::client_side::Defaults::ServiceEndpoints();

auto endpoints =
EndpointsBuilder()
auto& endpoints =
config_builder.ServiceEndpoints()
.EventsBaseUrl(default_endpoints.EventsBaseUrl())
.PollingBaseUrl(default_endpoints.PollingBaseUrl())
.StreamingBaseUrl(default_endpoints.StreamingBaseUrl());

auto datasource = DataSourceBuilder();

if (in.serviceEndpoints) {
if (in.serviceEndpoints->streaming) {
endpoints.StreamingBaseUrl(*in.serviceEndpoints->streaming);
Expand All @@ -57,6 +55,8 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
}
}

auto& datasource = config_builder.DataSource();

if (in.polling) {
if (in.polling->baseUri) {
endpoints.PollingBaseUrl(*in.polling->baseUri);
Expand All @@ -73,7 +73,7 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
}
}

auto event_config = EventsBuilder();
auto& event_config = config_builder.Events();

if (in.events) {
ConfigEventParams const& events = *in.events;
Expand Down Expand Up @@ -106,10 +106,6 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
event_config.Disable();
}

config_builder.Events(std::move(event_config));

config_builder.ServiceEndpoints(std::move(endpoints));

if (in.clientSide->evaluationReasons) {
datasource.WithReasons(*in.clientSide->evaluationReasons);
}
Expand All @@ -118,8 +114,6 @@ std::optional<std::string> EntityManager::create(ConfigParams const& in) {
datasource.UseReport(*in.clientSide->useReport);
}

config_builder.DataSource(std::move(datasource));

auto config = config_builder.Build();
if (!config) {
LD_LOG(logger_, LogLevel::kWarn)
Expand Down
Loading