C++ Client-Side SDK
LaunchDarkly SDK
flag_updater.hpp
1 #pragma once
2 
3 #include <memory>
4 #include <mutex>
5 #include <string>
6 #include <unordered_map>
7 
8 #include "../data_sources/data_source_update_sink.hpp"
9 #include "flag_store.hpp"
10 
11 #include <launchdarkly/client_side/flag_change_event.hpp>
12 #include <launchdarkly/client_side/flag_notifier.hpp>
13 
14 #include <boost/signals2.hpp>
15 
16 namespace launchdarkly::client_side::flag_manager {
17 
29  public:
30  FlagUpdater(FlagStore& flag_store);
31  void Init(Context const& context,
32  std::unordered_map<std::string, ItemDescriptor> data) override;
33  void Upsert(Context const& context,
34  std::string key,
35  ItemDescriptor item) override;
36  void Apply(Context const& context,
37  FlagChangeSet change_set,
38  bool from_cache) override;
39 
47  std::unique_ptr<IConnection> OnFlagChange(
48  std::string const& key,
49  std::function<void(std::shared_ptr<FlagValueChangeEvent>)> handler)
50  override;
51 
52  private:
53  bool HasListeners() const;
54 
55  FlagStore& flag_store_;
56  std::unordered_map<
57  std::string,
58  boost::signals2::signal<void(std::shared_ptr<FlagValueChangeEvent>)>>
59  signals_;
60 
61  // Recursive mutex so that has_listeners can non-conditionally lock
62  // the mutex. Otherwise a pre-condition for the call would be holding
63  // the mutex, which is more difficult to keep consistent over the code
64  // lifetime.
65  mutable std::recursive_mutex signal_mutex_;
66 
67  void DispatchEvent(FlagValueChangeEvent event);
68 };
69 
70 } // namespace launchdarkly::client_side::flag_manager
Definition: context.hpp:29
Definition: data_source_update_sink.hpp:38
void Apply(Context const &context, FlagChangeSet change_set, bool from_cache) override
Definition: flag_updater.cpp:46
std::unique_ptr< IConnection > OnFlagChange(std::string const &key, std::function< void(std::shared_ptr< FlagValueChangeEvent >)> handler) override
Definition: flag_updater.cpp:95