Skip to content

Commit 94f94ae

Browse files
authored
feat: Reorganize code to better facilitate encapsulation. (#87)
* feat: Reorganize code to better facilitate encapsulation. * Start scaffoling logging config. * Building common/internal/sse * Client builds. * Hello app runs * All runs. * Everything builds. * Attempt to appease GCC. * Reformat code. * Feedback, and make boost private. * Run regex better. * Lowercase w. * Add missing newline to end of file. * More Write casing. * Fix header groupings for polling data source. * Add missing headers. * Remove code from bad merge. * Update dependencies for release-please. * Cleanup install deps. * Format again. * Format libs.
1 parent f377fb7 commit 94f94ae

File tree

190 files changed

+1064
-818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+1064
-818
lines changed

.release-please-manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"libs/client-sdk": "0.0.0",
33
"libs/server-sent-events": "0.0.0",
4-
"libs/common": "0.0.0"
4+
"libs/common": "0.0.0",
5+
"libs/internal": "0.0.0"
56
}

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ if (BUILD_TESTING)
4949
enable_testing()
5050
endif ()
5151

52-
add_subdirectory(libs/client-sdk)
53-
5452
set(OPENSSL_USE_STATIC_LIBS ON)
5553
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/[email protected]")
5654
find_package(OpenSSL REQUIRED)
@@ -71,11 +69,14 @@ set(Boost_USE_STATIC_RUNTIME OFF)
7169
find_package(Boost 1.80 REQUIRED COMPONENTS json url coroutine)
7270
message(STATUS "LaunchDarkly: using Boost v${Boost_VERSION}")
7371

72+
add_subdirectory(libs/client-sdk)
73+
7474
set(ORIGINAL_BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS}")
7575
set(BUILD_SHARED_LIBS OFF)
7676

7777
# Always build the common libraries as shared libs.
7878
add_subdirectory(libs/common)
79+
add_subdirectory(libs/internal)
7980
add_subdirectory(libs/server-sent-events)
8081
add_subdirectory(bindings/c)
8182

apps/hello-cpp/main.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,24 @@
22

33
#include <boost/asio/io_context.hpp>
44

5-
#include <launchdarkly/console_backend.hpp>
65
#include <launchdarkly/context_builder.hpp>
76

87
#include <iostream>
98

109
namespace net = boost::asio; // from <boost/asio.hpp>
1110

12-
using launchdarkly::ConsoleBackend;
1311
using launchdarkly::ContextBuilder;
14-
using launchdarkly::Logger;
15-
using launchdarkly::LogLevel;
1612
using launchdarkly::client_side::Client;
1713
using launchdarkly::client_side::ConfigBuilder;
1814
using launchdarkly::client_side::DataSourceBuilder;
1915

2016
int main() {
21-
Logger logger(std::make_unique<ConsoleBackend>("Hello"));
22-
2317
net::io_context ioc;
2418

2519
char const* key = std::getenv("STG_SDK_KEY");
2620
if (!key) {
27-
std::cout << "Set environment variable STG_SDK_KEY to the sdk key";
21+
std::cout << "Set environment variable STG_SDK_KEY to the sdk key"
22+
<< std::endl;
2823
return 1;
2924
}
3025

@@ -47,27 +42,26 @@ int main() {
4742
.value(),
4843
ContextBuilder().kind("user", "ryan").build());
4944

50-
LD_LOG(logger, LogLevel::kInfo)
51-
<< "Initial Status: " << client.DataSourceStatus().Status();
45+
std::cout << "Initial Status: " << client.DataSourceStatus().Status()
46+
<< std::endl;
5247

53-
client.DataSourceStatus().OnDataSourceStatusChange([&logger](auto status) {
54-
LD_LOG(logger, LogLevel::kInfo) << "Got status: " << status;
48+
client.DataSourceStatus().OnDataSourceStatusChange([](auto status) {
49+
std::cout << "Got status: " << status << std::endl;
5550
});
5651

57-
client.FlagNotifier().OnFlagChange(
58-
"my-boolean-flag", [&logger](auto event) {
59-
LD_LOG(logger, LogLevel::kInfo) << "Got flag change: " << *event;
60-
});
52+
client.FlagNotifier().OnFlagChange("my-boolean-flag", [](auto event) {
53+
std::cout << "Got flag change: " << *event << std::endl;
54+
});
6155

6256
client.WaitForReadySync(std::chrono::seconds(30));
6357

6458
auto value = client.BoolVariationDetail("my-boolean-flag", false);
65-
LD_LOG(logger, LogLevel::kInfo) << "Value was: " << *value;
59+
std::cout << "Value was: " << *value << std::endl;
6660
if (auto reason = value.Reason()) {
67-
LD_LOG(logger, LogLevel::kInfo) << "Reason was: " << *reason;
61+
std::cout << "Reason was: " << *reason << std::endl;
6862
}
6963

7064
// Sit around.
71-
std::cout << "Press enter to exit" << std::endl;
65+
std::cout << "Press enter to exit" << std::endl << std::endl;
7266
std::cin.get();
7367
}

apps/sdk-contract-tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_executable(sdk-tests
2222

2323
target_link_libraries(sdk-tests PRIVATE
2424
launchdarkly::client
25+
launchdarkly::internal
2526
foxy
2627
nlohmann_json::nlohmann_json
2728
Boost::coroutine

apps/sdk-contract-tests/include/entity_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <boost/asio/any_io_executor.hpp>
44

55
#include <launchdarkly/client_side/client.hpp>
6-
#include <launchdarkly/logger.hpp>
6+
#include <launchdarkly/logging/logger.hpp>
77

88
#include "client_entity.hpp"
99
#include "definitions.hpp"

apps/sdk-contract-tests/include/server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "entity_manager.hpp"
99

10-
#include <launchdarkly/logger.hpp>
10+
#include <launchdarkly/logging/logger.hpp>
1111

1212
#include <foxy/listener.hpp>
1313

apps/sdk-contract-tests/include/session.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3+
#include <launchdarkly/logging/logger.hpp>
4+
35
#include "entity_manager.hpp"
4-
#include <launchdarkly/logger.hpp>
56

67
#include <boost/beast.hpp>
78
#include <boost/beast/http.hpp>

apps/sdk-contract-tests/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "server.hpp"
22

3-
#include <launchdarkly/console_backend.hpp>
3+
#include <launchdarkly/logging/console_backend.hpp>
44

55
#include <boost/asio/io_context.hpp>
66
#include <boost/asio/signal_set.hpp>
@@ -13,7 +13,7 @@
1313
namespace net = boost::asio;
1414
namespace beast = boost::beast;
1515

16-
using launchdarkly::ConsoleBackend;
16+
using launchdarkly::logging::ConsoleBackend;
1717

1818
using launchdarkly::LogLevel;
1919

apps/sse-contract-tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_executable(sse-tests
2222
target_link_libraries(sse-tests PRIVATE
2323
launchdarkly::sse
2424
launchdarkly::common
25+
launchdarkly::internal
2526
foxy
2627
nlohmann_json::nlohmann_json
2728
Boost::coroutine

apps/sse-contract-tests/include/entity_manager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3+
#include <launchdarkly/logging/logger.hpp>
34
#include "definitions.hpp"
4-
#include <launchdarkly/logger.hpp>
55

66
#include <launchdarkly/sse/client.hpp>
77

apps/sse-contract-tests/include/server.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <boost/asio/ip/tcp.hpp>
55
#include <boost/asio/signal_set.hpp>
66
#include <boost/beast.hpp>
7+
#include <launchdarkly/logging/logger.hpp>
78
#include "entity_manager.hpp"
8-
#include <launchdarkly/logger.hpp>
99

1010
#include <foxy/listener.hpp>
1111

apps/sse-contract-tests/include/session.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3+
#include <launchdarkly/logging/logger.hpp>
34
#include "entity_manager.hpp"
4-
#include <launchdarkly/logger.hpp>
55

66
#include <boost/beast.hpp>
77
#include <boost/beast/http.hpp>

apps/sse-contract-tests/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "server.hpp"
22

3-
#include <launchdarkly/console_backend.hpp>
3+
#include <launchdarkly/logging/console_backend.hpp>
44

55
#include <boost/asio/io_context.hpp>
66
#include <boost/asio/signal_set.hpp>
@@ -12,7 +12,7 @@
1212
namespace net = boost::asio;
1313
namespace beast = boost::beast;
1414

15-
using launchdarkly::ConsoleBackend;
15+
using launchdarkly::logging::ConsoleBackend;
1616

1717
using launchdarkly::LogLevel;
1818

libs/client-sdk/docs/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
The following pages document the core of the API, every application will use these portions of the SDK:
66

77
- [Client](@ref launchdarkly::client_side::Client)
8-
- [Config Builder](@ref launchdarkly::config::detail::builders::ConfigBuilder)
8+
- [Config Builder](@ref launchdarkly::config::shared::builders::ConfigBuilder)
99
- [Context Builder](@ref launchdarkly::ContextBuilder)

libs/client-sdk/include/launchdarkly/client_side/client.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#include <launchdarkly/context.hpp>
99
#include <launchdarkly/value.hpp>
1010

11-
#include <launchdarkly/client_side/data_sources/data_source_status.hpp>
12-
#include <launchdarkly/client_side/flag_manager/flag_notifier.hpp>
11+
#include <launchdarkly/client_side/data_source_status.hpp>
12+
#include <launchdarkly/client_side/flag_notifier.hpp>
1313
#include <launchdarkly/config/client.hpp>
1414
#include <launchdarkly/data/evaluation_detail.hpp>
1515

@@ -220,7 +220,7 @@ class IClient {
220220
* flag changes.
221221
* @return A flag notifier.
222222
*/
223-
virtual flag_manager::detail::IFlagNotifier& FlagNotifier() = 0;
223+
virtual flag_manager::IFlagNotifier& FlagNotifier() = 0;
224224

225225
/**
226226
* Wait for the client to be ready. A client will be ready when it either
@@ -299,7 +299,7 @@ class Client : public IClient {
299299

300300
data_sources::IDataSourceStatusProvider& DataSourceStatus() override;
301301

302-
flag_manager::detail::IFlagNotifier& FlagNotifier() override;
302+
flag_manager::IFlagNotifier& FlagNotifier() override;
303303

304304
void WaitForReadySync(std::chrono::milliseconds timeout) override;
305305

libs/client-sdk/include/launchdarkly/client_side/data_sources/data_source_status.hpp renamed to libs/client-sdk/include/launchdarkly/client_side/data_source_status.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
#include <chrono>
44
#include <cstddef>
5+
#include <functional>
6+
#include <memory>
57
#include <optional>
68
#include <ostream>
79
#include <string>
810

9-
#include <launchdarkly/client_side/connection.hpp>
10-
#include <launchdarkly/network/detail/http_requester.hpp>
11+
#include <launchdarkly/connection.hpp>
1112

1213
namespace launchdarkly::client_side::data_sources {
1314

@@ -77,7 +78,7 @@ class DataSourceStatus {
7778
*/
7879
class ErrorInfo {
7980
public:
80-
using StatusCodeType = network::detail::HttpResult::StatusCode;
81+
using StatusCodeType = uint64_t;
8182

8283
/**
8384
* An enumeration describing the general type of an error.

libs/client-sdk/include/launchdarkly/client_side/export.hpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

libs/client-sdk/include/launchdarkly/client_side/flag_manager/flag_change_event.hpp renamed to libs/client-sdk/include/launchdarkly/client_side/flag_change_event.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <launchdarkly/value.hpp>
44

5-
namespace launchdarkly::client_side::flag_manager::detail {
5+
namespace launchdarkly::client_side::flag_manager {
66
/**
77
* A notification, for the consumer of the SDK, that a flag value has
88
* changed.
@@ -60,4 +60,4 @@ class FlagValueChangeEvent {
6060

6161
std::ostream& operator<<(std::ostream& out, FlagValueChangeEvent const& event);
6262

63-
} // namespace launchdarkly::client_side::flag_manager::detail
63+
} // namespace launchdarkly::client_side::flag_manager

libs/client-sdk/include/launchdarkly/client_side/flag_manager/flag_notifier.hpp renamed to libs/client-sdk/include/launchdarkly/client_side/flag_notifier.hpp

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

3-
#include <launchdarkly/client_side/connection.hpp>
4-
#include <launchdarkly/client_side/flag_manager/flag_change_event.hpp>
3+
#include <launchdarkly/client_side/flag_change_event.hpp>
4+
#include <launchdarkly/connection.hpp>
55
#include <launchdarkly/value.hpp>
66

7-
namespace launchdarkly::client_side::flag_manager::detail {
7+
#include <functional>
8+
#include <memory>
9+
10+
namespace launchdarkly::client_side::flag_manager {
811

912
/**
1013
* Interface to allow listening for flag changes. Notification events should
@@ -40,4 +43,4 @@ class IFlagNotifier {
4043
IFlagNotifier() = default;
4144
};
4245

43-
} // namespace launchdarkly::client_side::flag_manager::detail
46+
} // namespace launchdarkly::client_side::flag_manager

libs/client-sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "0.0.0",
55
"private": true,
66
"dependencies": {
7+
"launchdarkly-cpp-internal": "0.0.0",
78
"launchdarkly-cpp-common": "0.0.0"
89
}
910
}

libs/client-sdk/src/CMakeLists.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11

22
file(GLOB HEADER_LIST CONFIGURE_DEPENDS
3-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/*.hpp"
43
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/*.hpp"
5-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/data_sources/*.hpp"
6-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/data_sources/detail/*.hpp"
7-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/flag_manager/*.hpp"
8-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/flag_manager/detail/*.hpp"
9-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/event_processor/*.hpp"
10-
"${LaunchDarklyCPPClient_SOURCE_DIR}/include/launchdarkly/client_side/event_processor/detail/*.hpp"
114
)
125

136
# Automatic library: static or dynamic based on user config.
@@ -17,7 +10,7 @@ add_library(${LIBNAME}
1710
data_sources/streaming_data_source.cpp
1811
data_sources/base_64.cpp
1912
data_sources/data_source_event_handler.cpp
20-
data_source_update_sink.cpp
13+
data_sources/data_source_update_sink.cpp
2114
data_sources/polling_data_source.cpp
2215
flag_manager/flag_manager.cpp
2316
flag_manager/flag_updater.cpp
@@ -28,11 +21,25 @@ add_library(${LIBNAME}
2821
event_processor/null_event_processor.cpp
2922
boost_signal_connection.cpp
3023
client_impl.cpp
31-
client.cpp)
24+
client.cpp
25+
data_sources/base_64.hpp
26+
boost_signal_connection.hpp
27+
client_impl.hpp
28+
data_sources/data_source.hpp
29+
data_sources/data_source_event_handler.hpp
30+
data_sources/data_source_status_manager.hpp
31+
data_sources/data_source_update_sink.hpp
32+
data_sources/polling_data_source.hpp
33+
data_sources/streaming_data_source.hpp
34+
event_processor/event_processor.hpp
35+
event_processor/null_event_processor.hpp
36+
flag_manager/flag_manager.hpp
37+
flag_manager/flag_updater.hpp
38+
event_processor.hpp)
3239

3340
target_link_libraries(${LIBNAME}
3441
PUBLIC launchdarkly::common
35-
PRIVATE launchdarkly::sse)
42+
PRIVATE Boost::headers launchdarkly::sse launchdarkly::internal)
3643

3744
add_library(launchdarkly::client ALIAS ${LIBNAME})
3845

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include <launchdarkly/client_side/detail/boost_signal_connection.hpp>
1+
#include "boost_signal_connection.hpp"
22

3-
namespace launchdarkly::client_side::detail {
3+
namespace launchdarkly::client_side {
44

55
SignalConnection::SignalConnection(boost::signals2::connection connection)
66
: connection_(std::move(connection)) {}
@@ -9,4 +9,4 @@ void SignalConnection::Disconnect() {
99
connection_.disconnect();
1010
}
1111

12-
} // namespace launchdarkly::client_side::detail
12+
} // namespace launchdarkly::client_side

0 commit comments

Comments
 (0)