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 
19  public:
20  FlagUpdater(FlagStore& flag_store);
21  void Init(Context const& context,
22  std::unordered_map<std::string, ItemDescriptor> data) override;
23  void Upsert(Context const& context,
24  std::string key,
25  ItemDescriptor item) override;
26 
34  std::unique_ptr<IConnection> OnFlagChange(
35  std::string const& key,
36  std::function<void(std::shared_ptr<FlagValueChangeEvent>)> handler)
37  override;
38 
39  private:
40  bool HasListeners() const;
41 
42  FlagStore& flag_store_;
43  std::unordered_map<
44  std::string,
45  boost::signals2::signal<void(std::shared_ptr<FlagValueChangeEvent>)>>
46  signals_;
47 
48  // Recursive mutex so that has_listeners can non-conditionally lock
49  // the mutex. Otherwise a pre-condition for the call would be holding
50  // the mutex, which is more difficult to keep consistent over the code
51  // lifetime.
52  mutable std::recursive_mutex signal_mutex_;
53 
54  void DispatchEvent(FlagValueChangeEvent event);
55 };
56 
57 } // namespace launchdarkly::client_side::flag_manager
Definition: context.hpp:29
Definition: data_source_update_sink.hpp:21
std::unique_ptr< IConnection > OnFlagChange(std::string const &key, std::function< void(std::shared_ptr< FlagValueChangeEvent >)> handler) override
Definition: flag_updater.cpp:123