C Client-Side SDK
LaunchDarkly SDK
client.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <stddef.h>
9 
10 #include <launchdarkly/boolean.h>
11 #include <launchdarkly/config.h>
12 #include <launchdarkly/export.h>
13 #include <launchdarkly/json.h>
14 #include <launchdarkly/user.h>
15 
17 struct LDClient;
18 
21 #define LDPrimaryEnvironmentName "default"
22 
24 typedef enum
25 {
26  LDStatusInitializing = 0,
27  LDStatusInitialized,
28  LDStatusFailed,
29  LDStatusShuttingdown,
34 } LDStatus;
35 
41 typedef struct
42 {
43  int variationIndex;
44  struct LDJSON *reason;
46 
48 LD_EXPORT(struct LDClient *) LDClientGet(void);
49 
55 LD_EXPORT(struct LDClient *) LDClientGetForMobileKey(const char *const keyName);
56 
72 LD_EXPORT(struct LDClient *)
74  struct LDConfig *const config,
75  struct LDUser *const user,
76  const unsigned int maxwaitmilli);
77 
79 LD_EXPORT(char *) LDClientSaveFlags(struct LDClient *const client);
80 
82 LD_EXPORT(LDBoolean)
83 LDClientRestoreFlags(struct LDClient *const client, const char *const data);
84 
102 LD_EXPORT(void)
103 LDClientIdentify(struct LDClient *const client, struct LDUser *const user);
104 
109 LD_EXPORT(void) LDClientFlush(struct LDClient *const client);
110 
112 LD_EXPORT(LDBoolean) LDClientIsInitialized(struct LDClient *const client);
113 
115 LD_EXPORT(LDBoolean)
117  struct LDClient *const client, const unsigned int timeoutmilli);
118 
120 LD_EXPORT(LDBoolean) LDClientIsOffline(struct LDClient *const client);
121 
123 LD_EXPORT(void) LDClientSetOffline(struct LDClient *const client);
124 
126 LD_EXPORT(void) LDClientSetOnline(struct LDClient *const client);
127 
129 LD_EXPORT(void)
131  struct LDClient *const client, const LDBoolean background);
132 
137 LD_EXPORT(void) LDClientClose(struct LDClient *const client);
138 
148 LD_EXPORT(void) LDSetClientStatusCallback(void(callback)(int status));
149 
150 
155 typedef void (*LDstatusfn)(LDStatus status, void *userData);
156 
157 
166 LD_EXPORT(void) LDSetClientStatusCallbackUserData(LDstatusfn callback, void *userData);
167 
169 LD_EXPORT(void)
171  struct LDClient * client,
172  const struct LDUser *currentUser,
173  const struct LDUser *previousUser);
174 
176 LD_EXPORT(void)
177 LDClientTrack(struct LDClient *const client, const char *const name);
178 
180 LD_EXPORT(void)
182  struct LDClient *const client,
183  const char *const name,
184  struct LDJSON *const data);
185 
187 LD_EXPORT(void)
189  struct LDClient *const client,
190  const char *const name,
191  struct LDJSON *const data,
192  const double metric);
193 
196 LD_EXPORT(struct LDJSON *) LDAllFlags(struct LDClient *const client);
197 
199 LD_EXPORT(LDBoolean)
201  struct LDClient *const client,
202  const char *const featureKey,
203  const LDBoolean fallback);
204 
208 LD_EXPORT(int)
210  struct LDClient *const client,
211  const char *const featureKey,
212  const int fallback);
213 
215 LD_EXPORT(double)
217  struct LDClient *const client,
218  const char *const featureKey,
219  const double fallback);
220 
222 LD_EXPORT(char *)
224  struct LDClient *const client,
225  const char *const featureKey,
226  const char *const fallback);
227 
229 LD_EXPORT(char *)
231  struct LDClient *const client,
232  const char *const featureKey,
233  const char *const fallback,
234  char *const resultBuffer,
235  const size_t resultBufferSize);
236 
238 LD_EXPORT(struct LDJSON *)
240  struct LDClient *const client,
241  const char *const featureKey,
242  const struct LDJSON *const fallback);
243 
245 LD_EXPORT(LDBoolean)
247  struct LDClient *const client,
248  const char *const featureKey,
249  const LDBoolean fallback,
250  LDVariationDetails *const details);
251 
255 LD_EXPORT(int)
257  struct LDClient *const client,
258  const char *const featureKey,
259  const int fallback,
260  LDVariationDetails *const details);
261 
263 LD_EXPORT(double)
265  struct LDClient *const client,
266  const char *const featureKey,
267  const double fallback,
268  LDVariationDetails *const details);
269 
271 LD_EXPORT(char *)
273  struct LDClient *const client,
274  const char *const featureKey,
275  const char *const fallback,
276  LDVariationDetails *const details);
277 
279 LD_EXPORT(char *)
281  struct LDClient *const client,
282  const char *const featureKey,
283  const char *const fallback,
284  char *const resultBuffer,
285  const size_t resultBufferSize,
286  LDVariationDetails *const details);
287 
289 LD_EXPORT(struct LDJSON *)
291  struct LDClient *const client,
292  const char *const key,
293  const struct LDJSON *const fallback,
294  LDVariationDetails *const details);
295 
298 
303 typedef void (*LDlistenerfn)(const char *const flagKey, const int status);
304 
306 LD_EXPORT(LDBoolean)
308  struct LDClient *const client,
309  const char *const flagKey,
310  LDlistenerfn listener);
311 
314 LD_EXPORT(void)
316  struct LDClient *const client,
317  const char *const flagKey,
318  LDlistenerfn listener);
LDClientTrackData
void LDClientTrackData(struct LDClient *const client, const char *const name, struct LDJSON *const data)
Record a custom event and include custom data.
LDSetClientStatusCallback
void LDSetClientStatusCallback(void(callback)(int status))
Add callback for client status changes, replacing any existing callback (including any set with LDSet...
LDStringVariation
char * LDStringVariation(struct LDClient *const client, const char *const featureKey, const char *const fallback, char *const resultBuffer, const size_t resultBufferSize)
Evaluate String flag into fixed buffer.
LDClientIsInitialized
LDBoolean LDClientIsInitialized(struct LDClient *const client)
Returns true if the client has been initialized.
LDStringVariationAllocDetail
char * LDStringVariationAllocDetail(struct LDClient *const client, const char *const featureKey, const char *const fallback, LDVariationDetails *const details)
Evaluate String flag with details.
LDFreeDetailContents
void LDFreeDetailContents(LDVariationDetails details)
Clear any memory associated with LDVariationDetails
LDClientInit
struct LDClient * LDClientInit(struct LDConfig *const config, struct LDUser *const user, const unsigned int maxwaitmilli)
Initialize the client with the config and user. After this call,.
LDClientAwaitInitialized
LDBoolean LDClientAwaitInitialized(struct LDClient *const client, const unsigned int timeoutmilli)
Block until initialized up to timeout, returns true if initialized.
boolean.h
A custom c89 boolean type.
LDClientTrack
void LDClientTrack(struct LDClient *const client, const char *const name)
Record a custom event.
LDIntVariation
int LDIntVariation(struct LDClient *const client, const char *const featureKey, const int fallback)
Evaluate Int flag.
LDClientSetOffline
void LDClientSetOffline(struct LDClient *const client)
Make the client operate in offline mode. No network traffic.
LDStatusShutdown
@ LDStatusShutdown
Definition: client.h:33
LDstatusfn
void(* LDstatusfn)(LDStatus status, void *userData)
Status callback type.
Definition: client.h:155
LDClientIdentify
void LDClientIdentify(struct LDClient *const client, struct LDUser *const user)
Asynchronously update the client with a new user.
LDSetClientStatusCallbackUserData
void LDSetClientStatusCallbackUserData(LDstatusfn callback, void *userData)
Add callback for client status changes, replacing any existing callback (including any set with LDSet...
LDClientSetOnline
void LDClientSetOnline(struct LDClient *const client)
Return the client to online mode.
LDDoubleVariation
double LDDoubleVariation(struct LDClient *const client, const char *const featureKey, const double fallback)
Evaluate Double flag.
LDClientSaveFlags
char * LDClientSaveFlags(struct LDClient *const client)
Get JSON string containing all flags.
LDClientClose
void LDClientClose(struct LDClient *const client)
Close the client, free resources, and generally shut down.
LDJSONVariationDetail
struct LDJSON * LDJSONVariationDetail(struct LDClient *const client, const char *const key, const struct LDJSON *const fallback, LDVariationDetails *const details)
Evaluate JSON flag with details.
LDClientAlias
void LDClientAlias(struct LDClient *client, const struct LDUser *currentUser, const struct LDUser *previousUser)
Record a alias event.
LDClientFlush
void LDClientFlush(struct LDClient *const client)
Send any pending events to the server. They will normally be.
LDClientRestoreFlags
LDBoolean LDClientRestoreFlags(struct LDClient *const client, const char *const data)
Set flag store from JSON string.
LD_EXPORT
#define LD_EXPORT(x)
Used to ensure only intended symbols are exported in the binaries.
Definition: export.h:10
LDUser
An opaque user object.
LDStatus
LDStatus
Current status of the client.
Definition: client.h:24
LDVariationDetails
To use detail variations you must provide a pointer to an LDVariationDetails struct that will be fill...
Definition: client.h:41
LDClientSetBackground
void LDClientSetBackground(struct LDClient *const client, const LDBoolean background)
Enable or disable polling mode.
LDIntVariationDetail
int LDIntVariationDetail(struct LDClient *const client, const char *const featureKey, const int fallback, LDVariationDetails *const details)
Evaluate Int flag with details.
LDStringVariationAlloc
char * LDStringVariationAlloc(struct LDClient *const client, const char *const featureKey, const char *const fallback)
Evaluate String flag.
LDDoubleVariationDetail
double LDDoubleVariationDetail(struct LDClient *const client, const char *const featureKey, const double fallback, LDVariationDetails *const details)
Evaluate Double flag with details.
LDBoolVariationDetail
LDBoolean LDBoolVariationDetail(struct LDClient *const client, const char *const featureKey, const LDBoolean fallback, LDVariationDetails *const details)
Evaluate Bool flag with details.
LDClientUnregisterFeatureFlagListener
void LDClientUnregisterFeatureFlagListener(struct LDClient *const client, const char *const flagKey, LDlistenerfn listener)
Unregister a callback registered with LDClientRegisterFeatureFlagListener
LDJSONVariation
struct LDJSON * LDJSONVariation(struct LDClient *const client, const char *const featureKey, const struct LDJSON *const fallback)
Evaluate JSON flag.
LDClientTrackMetric
void LDClientTrackMetric(struct LDClient *const client, const char *const name, struct LDJSON *const data, const double metric)
Record a custom event and include custom data / a metric.
LDClientRegisterFeatureFlagListener
LDBoolean LDClientRegisterFeatureFlagListener(struct LDClient *const client, const char *const flagKey, LDlistenerfn listener)
Register a callback for when a flag is updated.
user.h
Public API Interface for User construction.
json.h
Public API Interface for JSON usage.
LDAllFlags
struct LDJSON * LDAllFlags(struct LDClient *const client)
Returns an object of all flags. This must be freed with LDJSONFree.
config.h
Public API Interface for Configuration.
LDlistenerfn
void(* LDlistenerfn)(const char *const flagKey, const int status)
Feature flag listener callback type. Callbacks are not reentrant safe.
Definition: client.h:303
LDClientGetForMobileKey
struct LDClient * LDClientGetForMobileKey(const char *const keyName)
Get a reference to a secondary environment established in the configuration.
LDClientIsOffline
LDBoolean LDClientIsOffline(struct LDClient *const client)
Returns the offline status of the client.
LDClientGet
struct LDClient * LDClientGet(void)
Get a reference to the (single, global) client.
LDStringVariationDetail
char * LDStringVariationDetail(struct LDClient *const client, const char *const featureKey, const char *const fallback, char *const resultBuffer, const size_t resultBufferSize, LDVariationDetails *const details)
Evaluate String flag into fixed buffer with details.
LDBoolVariation
LDBoolean LDBoolVariation(struct LDClient *const client, const char *const featureKey, const LDBoolean fallback)
Evaluate Bool flag.
export.h
Public. Configuration of exported symbols.