Skip to content

Commit 1003117

Browse files
authored
feat: add Version method to obtain SDK version (#122)
Adds a `Version/LDClientSDK_Version`method, which exposes the client's version via function call. In the previous way, it was a public static class member. This way, we have a bit more encapsulation and can also expose it via C binding.
1 parent ddaa897 commit 1003117

File tree

8 files changed

+36
-5
lines changed

8 files changed

+36
-5
lines changed

libs/client-sdk/include/launchdarkly/client_side/bindings/c/sdk.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ typedef struct _LDClientSDK* LDClientSDK;
3131
LD_EXPORT(LDClientSDK)
3232
LDClientSDK_New(LDClientConfig config, LDContext context);
3333

34+
/**
35+
* Returns the version of the SDK.
36+
* @return String representation of the SDK version.
37+
*/
38+
LD_EXPORT(char const*)
39+
LDClientSDK_Version(void);
40+
3441
/**
3542
* Starts the SDK, initiating a connection to LaunchDarkly if not offline.
3643
*

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,6 @@ class IClient {
254254

255255
class Client : public IClient {
256256
public:
257-
inline static char const* const kVersion =
258-
"0.1.0"; // {x-release-please-version}
259-
260257
Client(Config config, Context context);
261258

262259
Client(Client&&) = delete;
@@ -315,7 +312,15 @@ class Client : public IClient {
315312

316313
flag_manager::IFlagNotifier& FlagNotifier() override;
317314

315+
/**
316+
* Returns the version of the SDK.
317+
* @return String representing version of the SDK.
318+
*/
319+
[[nodiscard]] static char const* Version();
320+
318321
private:
322+
inline static char const* const kVersion =
323+
"0.1.0"; // {x-release-please-version}
319324
std::unique_ptr<IClient> client;
320325
};
321326

libs/client-sdk/src/bindings/c/sdk.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ LDClientSDK_New(LDClientConfig config, LDContext context) {
5858
return FROM_SDK(sdk);
5959
}
6060

61+
LD_EXPORT(char const*)
62+
LDClientSDK_Version(void) {
63+
return Client::Version();
64+
}
65+
6166
LD_EXPORT(bool)
6267
LDClientSDK_Start(LDClientSDK sdk,
6368
unsigned int milliseconds,

libs/client-sdk/src/client.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,8 @@ flag_manager::IFlagNotifier& Client::FlagNotifier() {
9696
return client->FlagNotifier();
9797
}
9898

99+
char const* Client::Version() {
100+
return kVersion;
101+
}
102+
99103
} // namespace launchdarkly::client_side

libs/client-sdk/src/client_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ClientImpl : public IClient {
3737
ClientImpl(ClientImpl const&) = delete;
3838
ClientImpl& operator=(ClientImpl) = delete;
3939
ClientImpl& operator=(ClientImpl&& other) = delete;
40-
40+
4141
bool Initialized() const override;
4242

4343
using FlagKey = std::string;

libs/client-sdk/tests/client_c_bindings_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ TEST(ClientBindings, MinimalInstantiation) {
1818

1919
LDClientSDK sdk = LDClientSDK_New(config, context);
2020

21+
char const* version = LDClientSDK_Version();
22+
ASSERT_TRUE(version);
23+
ASSERT_STREQ(version, "0.1.0"); // {x-release-please-version}
24+
2125
LDClientSDK_Free(sdk);
2226
}

libs/client-sdk/tests/client_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ TEST(ClientTest, ClientConstructedWithMinimalConfigAndContext) {
1313
Context context = ContextBuilder().Kind("cat", "shadow").Build();
1414

1515
Client client(std::move(*config), context);
16+
17+
char const* version = client.Version();
18+
ASSERT_TRUE(version);
19+
ASSERT_STREQ(version, "0.1.0"); // {x-release-please-version}
1620
}
1721

1822
TEST(ClientTest, AllFlagsIsEmpty) {

release-please-config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"libs/client-sdk": {
77
"initial-version": "0.1.0",
88
"extra-files": [
9-
"include/launchdarkly/client_side/client.hpp"
9+
"include/launchdarkly/client_side/client.hpp",
10+
"tests/client_c_bindings_test.cpp",
11+
"tests/client_test.cpp"
1012
]
1113
},
1214
"libs/server-sent-events": {

0 commit comments

Comments
 (0)