Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.
Open
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
32 changes: 32 additions & 0 deletions Android.bp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cc_binary {
name: "hello-launchdarkly",

srcs: [
"hello.c",
],

static_libs: [
"libldclientapi",
],

shared_libs: [
"libcurl",
],
}

cc_binary {
name: "hellocpp-launchdarkly",

srcs: [
"hello.cpp",
],

static_libs: [
"libldclientapi",
"libldclientapicpp",
],

shared_libs: [
"libcurl",
],
}
24 changes: 16 additions & 8 deletions hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,20 @@

// Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate.
#define FEATURE_FLAG_KEY "my-boolean-flag"
#define USER_KEY "example-user-key"
#define USER_NAME "Sandy"

#define INIT_TIMEOUT_MILLISECONDS 3000

int main() {
if (!strlen(MOBILE_KEY)) {
printf("*** Please edit hello.c to set MOBILE_KEY to your LaunchDarkly mobile key first\n\n");
int main(int argc, const char* argv[]) {
const char *mobile_key = argc > 1 ? argv[1] : MOBILE_KEY;
const char *feature_flag_key = argc > 2 ? argv[2] : FEATURE_FLAG_KEY;
const char *user_key = argc > 3 ? argv[3] : USER_KEY;
const char *user_name = argc > 4 ? argv[4] : USER_NAME;


if (!strlen(mobile_key)) {
printf("*** Please edit hello.c to set MOBILE_KEY to your LaunchDarkly mobile key first or pass it as the first argument\n\n");
return 1;
}

Expand All @@ -24,12 +32,12 @@ int main() {

LDConfigureGlobalLogger(LD_LOG_INFO, LDBasicLogger);

config = LDConfigNew(MOBILE_KEY);
config = LDConfigNew(mobile_key);

// Set up the user properties. This user should appear on your LaunchDarkly users dashboard
// soon after you run the demo.
user = LDUserNew("example-user-key");
LDUserSetName(user, "Sandy");
user = LDUserNew(user_key);
LDUserSetName(user, user_name);

client = LDClientInit(config, user, INIT_TIMEOUT_MILLISECONDS);

Expand All @@ -40,10 +48,10 @@ int main() {
return 1;
}

LDBoolean flag_value = LDBoolVariation(client, FEATURE_FLAG_KEY, false);
LDBoolean flag_value = LDBoolVariation(client, feature_flag_key, false);

printf("*** Feature flag '%s' is %s for this user\n\n",
FEATURE_FLAG_KEY, flag_value ? "true" : "false");
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,
Expand Down
64 changes: 64 additions & 0 deletions hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

#include <launchdarkly/api.hpp>

// Set MOBILE_KEY to your LaunchDarkly mobile key.
#define MOBILE_KEY ""

// Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate.
#define FEATURE_FLAG_KEY "my-boolean-flag"
#define USER_KEY "example-user-key"
#define USER_NAME "Sandy"

#define INIT_TIMEOUT_MILLISECONDS 3000

int main(int argc, const char* argv[]) {
const char *mobile_key = argc > 1 ? argv[1] : MOBILE_KEY;
const char *feature_flag_key = argc > 2 ? argv[2] : FEATURE_FLAG_KEY;
const char *user_key = argc > 3 ? argv[3] : USER_KEY;
const char *user_name = argc > 4 ? argv[4] : USER_NAME;


if (!strlen(mobile_key)) {
printf("*** Please edit hello.cpp to set MOBILE_KEY to your LaunchDarkly mobile key first or pass it as the first argument\n\n");
return 1;
}

LDConfig *config;
LDClientCPP *client;
LDUser *user;

LDConfigureGlobalLogger(LD_LOG_INFO, LDBasicLogger);

config = LDConfigNew(mobile_key);

// Set up the user properties. This user should appear on your LaunchDarkly users dashboard
// soon after you run the demo.
user = LDUserNew(user_key);
LDUserSetName(user, user_name);

client = LDClientCPP::Init(config, user, INIT_TIMEOUT_MILLISECONDS);

if(client->isInitialized()) {
printf("*** SDK successfully initialized!\n\n");
} else {
printf("*** SDK failed to initialize\n\n");
return 1;
}

LDBoolean flag_value = client->boolVariation(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.
client->close();

return 0;
}