C++ Server-Side SDK
LaunchDarkly SDK
client.hpp
1 #pragma once
2 
3 #include <launchdarkly/context.hpp>
4 #include <launchdarkly/data/evaluation_detail.hpp>
5 #include <launchdarkly/server_side/config/config.hpp>
6 #include <launchdarkly/value.hpp>
7 
8 #include <launchdarkly/server_side/all_flags_state.hpp>
9 #include <launchdarkly/server_side/data_source_status.hpp>
10 
11 #include <chrono>
12 #include <future>
13 #include <memory>
14 #include <string>
15 #include <unordered_map>
16 
17 namespace launchdarkly::server_side {
21 class IClient {
22  public:
26  using FlagKey = std::string;
27 
50  virtual std::future<bool> StartAsync() = 0;
51 
70  [[nodiscard]] virtual bool Initialized() const = 0;
71 
90  [[nodiscard]] virtual class AllFlagsState AllFlagsState(
91  Context const& context,
93 
105  virtual void Track(Context const& ctx,
106  std::string event_name,
107  Value data,
108  double metric_value) = 0;
109 
118  virtual void Track(Context const& ctx,
119  std::string event_name,
120  Value data) = 0;
121 
128  virtual void Track(Context const& ctx, std::string event_name) = 0;
129 
134  virtual void FlushAsync() = 0;
135 
142  virtual void Identify(Context context) = 0;
143 
152  virtual bool BoolVariation(Context const& ctx,
153  FlagKey const& key,
154  bool default_value) = 0;
155 
165  FlagKey const& key,
166  bool default_value) = 0;
167 
176  virtual std::string StringVariation(Context const& ctx,
177  FlagKey const& key,
178  std::string default_value) = 0;
179 
189  Context const& ctx,
190  FlagKey const& key,
191  std::string default_value) = 0;
192 
201  virtual double DoubleVariation(Context const& ctx,
202  FlagKey const& key,
203  double default_value) = 0;
204 
214  Context const& ctx,
215  FlagKey const& key,
216  double default_value) = 0;
217 
226  virtual int IntVariation(Context const& ctx,
227  FlagKey const& key,
228  int default_value) = 0;
229 
239  FlagKey const& key,
240  int default_value) = 0;
241 
250  virtual Value JsonVariation(Context const& ctx,
251  FlagKey const& key,
252  Value default_value) = 0;
253 
263  Context const& ctx,
264  FlagKey const& key,
265  Value default_value) = 0;
266 
273 
274  virtual ~IClient() = default;
275  IClient(IClient const& item) = delete;
276  IClient(IClient&& item) = delete;
277  IClient& operator=(IClient const&) = delete;
278  IClient& operator=(IClient&&) = delete;
279 
280  protected:
281  IClient() = default;
282 };
283 
284 class Client : public IClient {
285  public:
286  Client(Config config);
287 
288  std::future<bool> StartAsync() override;
289 
290  [[nodiscard]] bool Initialized() const override;
291 
292  using FlagKey = std::string;
293  [[nodiscard]] class AllFlagsState AllFlagsState(
294  Context const& context,
295  enum AllFlagsState::Options options =
297 
298  void Track(Context const& ctx,
299  std::string event_name,
300  Value data,
301  double metric_value) override;
302 
303  void Track(Context const& ctx, std::string event_name, Value data) override;
304 
305  void Track(Context const& ctx, std::string event_name) override;
306 
307  void FlushAsync() override;
308 
309  void Identify(Context context) override;
310 
311  bool BoolVariation(Context const& ctx,
312  FlagKey const& key,
313  bool default_value) override;
314 
316  FlagKey const& key,
317  bool default_value) override;
318 
319  std::string StringVariation(Context const& ctx,
320  FlagKey const& key,
321  std::string default_value) override;
322 
324  Context const& ctx,
325  FlagKey const& key,
326  std::string default_value) override;
327 
328  double DoubleVariation(Context const& ctx,
329  FlagKey const& key,
330  double default_value) override;
331 
333  Context const& ctx,
334  FlagKey const& key,
335  double default_value) override;
336 
337  int IntVariation(Context const& ctx,
338  FlagKey const& key,
339  int default_value) override;
340 
342  FlagKey const& key,
343  int default_value) override;
344 
345  Value JsonVariation(Context const& ctx,
346  FlagKey const& key,
347  Value default_value) override;
348 
350  FlagKey const& key,
351  Value default_value) override;
352 
354 
359  [[nodiscard]] static char const* Version();
360 
361  private:
362  inline static char const* const kVersion =
363  "3.8.0"; // {x-release-please-version}
364  std::unique_ptr<IClient> client;
365 };
366 
367 } // namespace launchdarkly::server_side
Definition: context.hpp:29
Definition: evaluation_detail.hpp:18
Definition: value.hpp:42
Definition: all_flags_state.hpp:27
Options
Definition: all_flags_state.hpp:29
Definition: client.hpp:284
EvaluationDetail< int > IntVariationDetail(Context const &ctx, FlagKey const &key, int default_value) override
Definition: client.cpp:109
bool Initialized() const override
Definition: client.cpp:28
EvaluationDetail< bool > BoolVariationDetail(Context const &ctx, FlagKey const &key, bool default_value) override
Definition: client.cpp:72
void FlushAsync() override
Definition: client.cpp:58
std::future< bool > StartAsync() override
Definition: client.cpp:32
bool BoolVariation(Context const &ctx, FlagKey const &key, bool default_value) override
Definition: client.cpp:66
IDataSourceStatusProvider & DataSourceStatus() override
Definition: client.cpp:127
std::string StringVariation(Context const &ctx, FlagKey const &key, std::string default_value) override
Definition: client.cpp:78
Value JsonVariation(Context const &ctx, FlagKey const &key, Value default_value) override
Definition: client.cpp:115
double DoubleVariation(Context const &ctx, FlagKey const &key, double default_value) override
Definition: client.cpp:91
void Identify(Context context) override
Definition: client.cpp:62
EvaluationDetail< std::string > StringVariationDetail(Context const &ctx, FlagKey const &key, std::string default_value) override
Definition: client.cpp:84
EvaluationDetail< double > DoubleVariationDetail(Context const &ctx, FlagKey const &key, double default_value) override
Definition: client.cpp:97
void Track(Context const &ctx, std::string event_name, Value data, double metric_value) override
Definition: client.cpp:43
EvaluationDetail< Value > JsonVariationDetail(Context const &ctx, FlagKey const &key, Value default_value) override
Definition: client.cpp:121
static char const * Version()
Definition: client.cpp:131
int IntVariation(Context const &ctx, FlagKey const &key, int default_value) override
Definition: client.cpp:103
Definition: client.hpp:21
virtual IDataSourceStatusProvider & DataSourceStatus()=0
virtual EvaluationDetail< std::string > StringVariationDetail(Context const &ctx, FlagKey const &key, std::string default_value)=0
virtual std::string StringVariation(Context const &ctx, FlagKey const &key, std::string default_value)=0
std::string FlagKey
Definition: client.hpp:26
virtual bool BoolVariation(Context const &ctx, FlagKey const &key, bool default_value)=0
virtual Value JsonVariation(Context const &ctx, FlagKey const &key, Value default_value)=0
virtual void Track(Context const &ctx, std::string event_name, Value data, double metric_value)=0
virtual EvaluationDetail< int > IntVariationDetail(Context const &ctx, FlagKey const &key, int default_value)=0
virtual void Track(Context const &ctx, std::string event_name, Value data)=0
virtual std::future< bool > StartAsync()=0
virtual void Track(Context const &ctx, std::string event_name)=0
virtual int IntVariation(Context const &ctx, FlagKey const &key, int default_value)=0
virtual EvaluationDetail< double > DoubleVariationDetail(Context const &ctx, FlagKey const &key, double default_value)=0
virtual bool Initialized() const =0
virtual void Identify(Context context)=0
virtual EvaluationDetail< bool > BoolVariationDetail(Context const &ctx, FlagKey const &key, bool default_value)=0
virtual double DoubleVariation(Context const &ctx, FlagKey const &key, double default_value)=0
virtual EvaluationDetail< Value > JsonVariationDetail(Context const &ctx, FlagKey const &key, Value default_value)=0
Definition: data_source_status.hpp:69
Definition: config.hpp:8