C++ Server-Side SDK
LaunchDarkly SDK
Loading...
Searching...
No Matches
event_handler.hpp
1#pragma once
2
3#include "../../../../data_components/dependency_tracker/data_kind.hpp"
4#include "../../../../data_components/status_notifications/data_source_status_manager.hpp"
5#include "../../../../data_interfaces/destination/idestination.hpp"
6
7#include <launchdarkly/data/evaluation_result.hpp>
8#include <launchdarkly/data_model/descriptors.hpp>
9#include <launchdarkly/logging/logger.hpp>
10
11#include <boost/asio/any_io_executor.hpp>
12
13#include <cstdint>
14
15namespace launchdarkly::server_side::data_systems {
16
17// The FlagsPath and SegmentsPath are made to turn a string literal into a type
18// for use in a template.
19// You can use a char array as a const char* template
20// parameter, but this causes a number of issues with the clang linter.
21
22struct FlagsPath {
23 static constexpr std::string_view path = "/flags/";
24};
25
27 static constexpr std::string_view path = "/segments/";
28};
29
30template <data_components::DataKind kind, typename TPath>
32 public:
33 static data_components::DataKind Kind() { return kind; }
34 static bool IsKind(std::string const& patch_path) {
35 return patch_path.rfind(TPath::path) == 0;
36 }
37 static std::string Key(std::string const& patch_path) {
38 return patch_path.substr(TPath::path.size());
39 }
40};
41
44 using Segment =
46
47 static std::optional<data_components::DataKind> Kind(
48 std::string const& path) {
49 if (Flag::IsKind(path)) {
50 return data_components::DataKind::kFlag;
51 }
52 if (Segment::IsKind(path)) {
53 return data_components::DataKind::kSegment;
54 }
55 return std::nullopt;
56 }
57
58 static std::optional<std::string> Key(std::string const& path) {
59 if (Flag::IsKind(path)) {
60 return Flag::Key(path);
61 }
62 if (Segment::IsKind(path)) {
63 return Segment::Key(path);
64 }
65 return std::nullopt;
66 }
67};
68
78 public:
83 enum class MessageStatus {
84 kMessageHandled,
85 kInvalidMessage,
86 kUnhandledVerb
87 };
88
89 struct Put {
90 data_model::SDKDataSet data;
91 };
92
93 struct Patch {
94 std::string key;
95 std::variant<data_model::FlagDescriptor, data_model::SegmentDescriptor>
96 data;
97 };
98
99 struct Delete {
100 std::string key;
101 data_components::DataKind kind;
102 uint64_t version;
103 };
104
107 Logger const& logger,
109
116 MessageStatus HandleMessage(std::string const& type,
117 std::string const& data);
118
119 private:
121 Logger const& logger_;
123};
124} // namespace launchdarkly::server_side::data_systems
IDestination represents a sink for data received by the SDK. A destination may be a database,...
Definition idestination.hpp:14
MessageStatus HandleMessage(std::string const &type, std::string const &data)
Definition event_handler.cpp:134