-
Notifications
You must be signed in to change notification settings - Fork 3
feat: server-side C bindings #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cwaldren-ld
merged 20 commits into
server-side
from
cw/sc-210041/server-client-bindings
Aug 31, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
782b53c
copy client-side bindings for server
cwaldren-ld af87841
add server-side binding unit tests
cwaldren-ld 81f762f
comment out c binding impls that are missing
cwaldren-ld 4bc1899
define guards for macros
cwaldren-ld 08a45bd
add server-side config
cwaldren-ld 367a1f2
move LDFlagListener C definitions out of server-side
cwaldren-ld 274b28d
add AllFlagsState bindings
cwaldren-ld 2f913d3
add JSON serialization to AllFlagsState API
cwaldren-ld 3769135
add AllFlagsState Value getter
cwaldren-ld db0f118
remove flag listener API from server-side SDK
cwaldren-ld dcf4e96
update DataSourceState bindings and unit tests
cwaldren-ld 019b870
integrate change to move DataSourceStatus ErrorInfo to common library
cwaldren-ld 2c6cebd
move macro defs to shared file
cwaldren-ld 9aeff8c
align data source status in C binding to CPP implementation
cwaldren-ld 3e10612
rename LD_DATASOURCESTATUS_ enums to LD_SERVERDATASOURCESTATUS
cwaldren-ld 223bb86
slight comment improvements in all_flags_state
cwaldren-ld 409dbda
clearer comments on LDServerSDK_New
cwaldren-ld cae04ca
feat: add hello-c-server (#213)
cwaldren-ld 650382b
initialize variables in example apps
cwaldren-ld d050b34
remove obsolete comment + fix lints
cwaldren-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| add_subdirectory(hello-c-client) | ||
| add_subdirectory(hello-cpp-client) | ||
| add_subdirectory(hello-cpp-server) | ||
| add_subdirectory(hello-c-server) | ||
|
|
||
| add_subdirectory(client-and-server-coexistence) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Required for Apple Silicon support. | ||
| cmake_minimum_required(VERSION 3.19) | ||
|
|
||
| project( | ||
| LaunchDarklyCClientAndServerCoexistence | ||
| VERSION 0.1 | ||
| DESCRIPTION "LaunchDarkly C Client-side and Server-side SDK coexistence in same application" | ||
| LANGUAGES C | ||
| ) | ||
|
|
||
| set(THREADS_PREFER_PTHREAD_FLAG ON) | ||
| find_package(Threads REQUIRED) | ||
|
|
||
| add_executable(c-client-and-server main.c) | ||
| target_link_libraries(c-client-and-server PRIVATE launchdarkly::client launchdarkly::server launchdarkly::sse launchdarkly::common Threads::Threads) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * This application intends to verify that the symbols from the | ||
| * client-side and server-side SDKs do not clash, thus enabling both SDKs to be | ||
| * used within the same application. | ||
| */ | ||
|
|
||
| #include <launchdarkly/client_side/bindings/c/sdk.h> | ||
| #include <launchdarkly/server_side/bindings/c/sdk.h> | ||
|
|
||
| #include <launchdarkly/client_side/bindings/c/config/builder.h> | ||
| #include <launchdarkly/server_side/bindings/c/config/builder.h> | ||
|
|
||
| #include <launchdarkly/bindings/c/context_builder.h> | ||
|
|
||
| int main() { | ||
| LDContextBuilder context_builder = LDContextBuilder_New(); | ||
| LDContextBuilder_AddKind(context_builder, "user", "example-user-key"); | ||
| LDContextBuilder_Attributes_SetName(context_builder, "user", "Sandy"); | ||
| LDContext context = LDContextBuilder_Build(context_builder); | ||
|
|
||
| LDClientConfigBuilder client_config_builder = | ||
| LDClientConfigBuilder_New("foo"); | ||
| LDClientConfig client_config = NULL; | ||
|
|
||
| LDStatus client_config_status = | ||
| LDClientConfigBuilder_Build(client_config_builder, &client_config); | ||
|
|
||
| if (LDStatus_Ok(client_config_status)) { | ||
| LDClientSDK client_sdk = LDClientSDK_New(client_config, context); | ||
| LDClientSDK_Free(client_sdk); | ||
| } | ||
|
|
||
| LDServerConfigBuilder server_config_builder = | ||
| LDServerConfigBuilder_New("foo"); | ||
| LDServerConfig server_config = NULL; | ||
|
|
||
| LDStatus server_config_status = | ||
| LDServerConfigBuilder_Build(server_config_builder, &server_config); | ||
|
|
||
| if (LDStatus_Ok(server_config_status)) { | ||
| LDServerSDK server_sdk = LDServerSDK_New(server_config); | ||
| LDServerSDK_Free(server_sdk); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Required for Apple Silicon support. | ||
| cmake_minimum_required(VERSION 3.19) | ||
|
|
||
| project( | ||
| LaunchDarklyHelloCServer | ||
| VERSION 0.1 | ||
| DESCRIPTION "LaunchDarkly Hello C Server-side SDK" | ||
| LANGUAGES C | ||
| ) | ||
|
|
||
| set(THREADS_PREFER_PTHREAD_FLAG ON) | ||
| find_package(Threads REQUIRED) | ||
|
|
||
| add_executable(hello-c-server main.c) | ||
| target_link_libraries(hello-c-server PRIVATE launchdarkly::server launchdarkly::sse launchdarkly::common Threads::Threads) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #include <launchdarkly/server_side/bindings/c/config/builder.h> | ||
| #include <launchdarkly/server_side/bindings/c/sdk.h> | ||
|
|
||
| #include <launchdarkly/bindings/c/context_builder.h> | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
|
|
||
| // Set SDK_KEY to your LaunchDarkly SKD key. | ||
| #define SDK_KEY "" | ||
|
|
||
| // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate. | ||
| #define FEATURE_FLAG_KEY "my-boolean-flag" | ||
|
|
||
| // Set INIT_TIMEOUT_MILLISECONDS to the amount of time you will wait for | ||
| // the client to become initialized. | ||
| #define INIT_TIMEOUT_MILLISECONDS 3000 | ||
|
|
||
| int main() { | ||
| if (!strlen(SDK_KEY)) { | ||
| printf( | ||
| "*** Please edit main.c to set SDK_KEY to your LaunchDarkly " | ||
| "SDK key first\n\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| LDServerConfigBuilder config_builder = LDServerConfigBuilder_New(SDK_KEY); | ||
|
|
||
| LDServerConfig config = NULL; | ||
| LDStatus config_status = | ||
| LDServerConfigBuilder_Build(config_builder, &config); | ||
| if (!LDStatus_Ok(config_status)) { | ||
| printf("error: config is invalid: %s", LDStatus_Error(config_status)); | ||
| return 1; | ||
| } | ||
|
|
||
| LDServerSDK client = LDServerSDK_New(config); | ||
|
|
||
| bool initialized_successfully = false; | ||
| if (LDServerSDK_Start(client, INIT_TIMEOUT_MILLISECONDS, | ||
| &initialized_successfully)) { | ||
| if (initialized_successfully) { | ||
| printf("*** SDK successfully initialized!\n\n"); | ||
| } else { | ||
| printf("*** SDK failed to initialize\n"); | ||
| return 1; | ||
| } | ||
| } else { | ||
| printf("SDK initialization didn't complete in %dms\n", | ||
| INIT_TIMEOUT_MILLISECONDS); | ||
| return 1; | ||
| } | ||
|
|
||
| LDContextBuilder context_builder = LDContextBuilder_New(); | ||
| LDContextBuilder_AddKind(context_builder, "user", "example-user-key"); | ||
| LDContextBuilder_Attributes_SetName(context_builder, "user", "Sandy"); | ||
| LDContext context = LDContextBuilder_Build(context_builder); | ||
|
|
||
| bool flag_value = | ||
| LDServerSDK_BoolVariation(client, context, FEATURE_FLAG_KEY, false); | ||
|
|
||
| printf("*** Feature flag '%s' is %s for this user\n\n", FEATURE_FLAG_KEY, | ||
| flag_value ? "true" : "false"); | ||
|
|
||
| // Here we ensure that the SDK shuts down cleanly and has a chance to | ||
| // deliver analytics events to LaunchDarkly before the program exits. If | ||
| // analytics events are not delivered, the user properties and flag usage | ||
| // statistics will not appear on your dashboard. In a normal long-running | ||
| // application, the SDK would continue running and events would be delivered | ||
| // automatically in the background. | ||
|
|
||
| LDContext_Free(context); | ||
| LDServerSDK_Free(client); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
libs/common/include/launchdarkly/bindings/c/shared_function_argument_macro_definitions.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** @file */ | ||
| #pragma once | ||
|
|
||
| /* Function should operate asynchronously. */ | ||
| #define LD_NONBLOCKING 0 | ||
|
|
||
| /* Function should discard evaluation details. */ | ||
| #define LD_DISCARD_DETAIL NULL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.