Skip to content

Commit b6cd25f

Browse files
committed
refactor event classes into common and client namespaces
1 parent ecc7e2f commit b6cd25f

17 files changed

+257
-222
lines changed

libs/common/include/data/evaluation_result.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EvaluationResult {
3535

3636
/**
3737
* A timestamp, which if the current time is before, a client SDK
38-
* should send debug events for the flag.
38+
* should AsyncSend debug events for the flag.
3939
* @return
4040
*/
4141
[[nodiscard]] std::optional<
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include "events/common_events.hpp"
4+
5+
namespace launchdarkly::events::client {
6+
7+
struct IdentifyEventParams {
8+
Date creation_date;
9+
Context context;
10+
};
11+
12+
struct IdentifyEvent {
13+
Date creation_date;
14+
EventContext context;
15+
};
16+
17+
struct FeatureEventParams {
18+
Date creation_date;
19+
std::string key;
20+
Context context;
21+
EvaluationResult eval_result;
22+
};
23+
24+
struct FeatureEventBase {
25+
Date creation_date;
26+
std::string key;
27+
Version version;
28+
std::optional<VariationIndex> variation;
29+
Value value;
30+
std::optional<Reason> reason;
31+
Value default_;
32+
};
33+
34+
struct FeatureEvent {
35+
FeatureEventBase base;
36+
ContextKeys context_keys;
37+
};
38+
39+
struct DebugEvent {
40+
FeatureEventBase base;
41+
EventContext context;
42+
};
43+
44+
} // namespace launchdarkly::events::client
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
#include <chrono>
4+
#include <cstdint>
5+
#include <variant>
6+
7+
#include <boost/json/value.hpp>
8+
#include "context.hpp"
9+
#include "data/evaluation_reason.hpp"
10+
#include "data/evaluation_result.hpp"
11+
12+
namespace launchdarkly::events {
13+
14+
using Value = launchdarkly::Value;
15+
using VariationIndex = size_t;
16+
using Reason = EvaluationReason;
17+
using Result = EvaluationResult;
18+
using Context = launchdarkly::Context;
19+
using EventContext = boost::json::value;
20+
using Version = std::uint64_t;
21+
using ContextKeys = std::map<std::string, std::string>;
22+
23+
struct Date {
24+
std::chrono::system_clock::time_point t;
25+
};
26+
27+
struct VariationSummary {
28+
std::size_t count;
29+
Value value;
30+
};
31+
32+
struct VariationKey {
33+
Version version;
34+
std::optional<VariationIndex> variation;
35+
36+
struct Hash {
37+
auto operator()(VariationKey const& p) const -> size_t {
38+
if (p.variation) {
39+
return std::hash<Version>{}(p.version) ^
40+
std::hash<VariationIndex>{}(*p.variation);
41+
} else {
42+
return std::hash<Version>{}(p.version);
43+
}
44+
}
45+
};
46+
};
47+
48+
struct TrackEventParams {
49+
Date creation_date;
50+
std::string key;
51+
ContextKeys context_keys;
52+
std::optional<Value> data;
53+
std::optional<double> metric_value;
54+
};
55+
56+
// Track (custom) events are directly serialized from their parameters.
57+
using TrackEvent = TrackEventParams;
58+
59+
} // namespace launchdarkly::events

libs/common/include/events/detail/asio_event_processor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class AsioEventProcessor : public IEventProcessor {
2020
config::ServiceHosts const& endpoints,
2121
Logger& logger);
2222

23-
void async_send(InputEvent event) override;
24-
void async_flush() override;
25-
void async_close() override;
23+
void AsyncSend(InputEvent event) override;
24+
void AsyncFlush() override;
25+
void AsyncClose() override;
2626

2727
private:
2828
Logger& logger_;

libs/common/include/events/detail/dispatcher.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
#include <optional>
1010
#include "config/detail/events.hpp"
1111
#include "config/detail/service_hosts.hpp"
12+
#include "context_filter.hpp"
1213
#include "events/detail/conn_pool.hpp"
1314
#include "events/detail/outbox.hpp"
1415
#include "events/detail/summary_state.hpp"
1516
#include "events/events.hpp"
1617
#include "logger.hpp"
17-
#include "context_filter.hpp"
18-
1918

2019
namespace launchdarkly::events::detail {
2120

@@ -27,11 +26,11 @@ class Dispatcher {
2726
std::string authorization,
2827
Logger& logger);
2928

30-
void request_flush();
29+
void AsyncFlush();
3130

32-
void send(InputEvent);
31+
void AsyncSend(InputEvent);
3332

34-
void shutdown();
33+
void AsyncClose();
3534

3635
private:
3736
enum class FlushTrigger {
@@ -63,15 +62,15 @@ class Dispatcher {
6362

6463
Logger& logger_;
6564

66-
void handle_send(InputEvent e);
65+
void HandleSend(InputEvent e);
6766

68-
std::optional<RequestType> make_request();
67+
std::optional<RequestType> MakeRequest();
6968

70-
void flush(FlushTrigger flush_type);
69+
void Flush(FlushTrigger flush_type);
7170

72-
void schedule_flush();
71+
void ScheduleFlush();
7372

74-
std::vector<OutputEvent> process(InputEvent e);
73+
std::vector<OutputEvent> Process(InputEvent e);
7574
};
7675

7776
} // namespace launchdarkly::events::detail

libs/common/include/events/detail/null_event_processor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace launchdarkly::events::detail {
77
class NullEventProcessor : public IEventProcessor {
88
public:
99
NullEventProcessor() = default;
10-
void async_send(InputEvent event) override;
11-
void async_flush() override;
12-
void async_close() override;
10+
void AsyncSend(InputEvent event) override;
11+
void AsyncFlush() override;
12+
void AsyncClose() override;
1313
};
1414
} // namespace launchdarkly::events::detail

libs/common/include/events/event_processor.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ class IEventProcessor {
1212
* soon as possible. The event may be dropped if the inbox lacks capacity.
1313
* @param event InputEvent to deliver.
1414
*/
15-
virtual void async_send(InputEvent event) = 0;
15+
virtual void AsyncSend(InputEvent event) = 0;
1616
/**
1717
* Asynchronously on_flush the processor's outbox, returning as soon as
1818
* possible. Flushing may be a no-op if a on_flush is already in progress.
1919
*/
20-
virtual void async_flush() = 0;
20+
virtual void AsyncFlush() = 0;
2121
/**
2222
* Synchronously close the processor. The processor should attempt to
2323
* on_flush all events in the outbox before shutting down. All asynchronous
2424
* operations MUST be completed before sync_close returns.
2525
*/
26-
virtual void async_close() = 0;
26+
virtual void AsyncClose() = 0;
2727
};
2828

2929
} // namespace launchdarkly::events

libs/common/include/events/events.hpp

Lines changed: 10 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,18 @@
11
#pragma once
22

3-
#include <boost/json/value.hpp>
4-
#include <map>
5-
#include <unordered_map>
6-
#include <unordered_set>
7-
#include <variant>
8-
#include "attribute_reference.hpp"
9-
#include "context.hpp"
10-
#include "data/evaluation_reason.hpp"
11-
#include "value.hpp"
12-
13-
#include <cstdint>
3+
#include "events/client_events.hpp"
4+
// #include "events/server_events.hpp"
5+
// Server-side events would be added to the Input/Output event variants.
146

157
namespace launchdarkly::events {
168

17-
// TODO: Replace with actual types when available.
18-
using Value = launchdarkly::Value;
19-
using VariationIndex = size_t;
20-
using Reason = EvaluationReason;
21-
using Context = launchdarkly::Context;
22-
using EventContext = boost::json::value;
23-
using Version = std::uint64_t;
24-
using ContextKeys = std::map<std::string, std::string>;
25-
26-
struct Date {
27-
std::chrono::system_clock::time_point t;
28-
};
29-
30-
struct FeatureEventFields {
31-
std::string key;
32-
Date creation_date;
33-
Value value;
34-
std::optional<VariationIndex> variation;
35-
Value default_;
36-
std::optional<Reason> reason;
37-
Version version;
38-
std::optional<std::string> prereq_of;
39-
};
40-
41-
struct FeatureEvent {
42-
FeatureEventFields base;
43-
ContextKeys context_keys;
44-
};
45-
46-
struct DebugEvent {
47-
FeatureEventFields base;
48-
Context context;
49-
};
50-
51-
struct IdentifyEvent {
52-
Date creation_date;
53-
Context context;
54-
};
55-
56-
struct OutIdentifyEvent {
57-
Date creation_date;
58-
EventContext context;
59-
};
60-
61-
struct IndexEvent : public OutIdentifyEvent {};
62-
63-
struct CustomEvent {
64-
Date creation_date;
65-
std::string key;
66-
ContextKeys context_keys;
67-
std::optional<Value> data;
68-
std::optional<double> metric_value;
69-
};
70-
71-
struct VariationSummary {
72-
std::size_t count;
73-
Value value;
74-
};
75-
76-
struct VariationKey {
77-
Version version;
78-
std::optional<VariationIndex> variation;
79-
80-
struct Hash {
81-
auto operator()(VariationKey const& p) const -> size_t {
82-
if (p.variation) {
83-
return std::hash<Version>{}(p.version) ^
84-
std::hash<VariationIndex>{}(*p.variation);
85-
} else {
86-
return std::hash<Version>{}(p.version);
87-
}
88-
}
89-
};
90-
};
91-
92-
using InputEvent = std::variant<FeatureEvent, IdentifyEvent, CustomEvent>;
9+
using InputEvent = std::variant<client::FeatureEventParams,
10+
client::IdentifyEventParams,
11+
TrackEventParams>;
9312

94-
using OutputEvent = std::variant<IndexEvent,
95-
DebugEvent,
96-
FeatureEvent,
97-
OutIdentifyEvent,
98-
CustomEvent>;
13+
using OutputEvent = std::variant<client::FeatureEvent,
14+
client::DebugEvent,
15+
client::IdentifyEvent,
16+
TrackEvent>;
9917

10018
} // namespace launchdarkly::events

libs/common/include/serialization/events/json_events.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,33 @@
44

55
#include "events/events.hpp"
66

7-
namespace launchdarkly::events {
8-
7+
namespace launchdarkly::events::client {
98
void tag_invoke(boost::json::value_from_tag const&,
109
boost::json::value& json_value,
11-
Date const& date);
10+
FeatureEvent const& event);
1211

1312
void tag_invoke(boost::json::value_from_tag const&,
1413
boost::json::value& json_value,
15-
IndexEvent const& date);
14+
FeatureEventBase const& event);
1615

1716
void tag_invoke(boost::json::value_from_tag const&,
1817
boost::json::value& json_value,
19-
FeatureEvent const& event);
18+
IdentifyEvent const& event);
2019

2120
void tag_invoke(boost::json::value_from_tag const&,
2221
boost::json::value& json_value,
23-
FeatureEventFields const& event);
22+
DebugEvent const& event);
23+
} // namespace launchdarkly::events::client
2424

25-
void tag_invoke(boost::json::value_from_tag const&,
26-
boost::json::value& json_value,
27-
OutIdentifyEvent const& event);
25+
namespace launchdarkly::events {
2826

2927
void tag_invoke(boost::json::value_from_tag const&,
3028
boost::json::value& json_value,
31-
DebugEvent const& event);
29+
Date const& date);
3230

3331
void tag_invoke(boost::json::value_from_tag const&,
3432
boost::json::value& json_value,
35-
CustomEvent const& event);
33+
TrackEvent const& event);
3634

3735
void tag_invoke(boost::json::value_from_tag const&,
3836
boost::json::value& json_value,

libs/common/src/attribute_reference.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ bool ParseRef(std::string str, std::vector<std::string>& components) {
112112
auto p_state = ParseState::kBegin;
113113

114114
std::string tmp_token;
115-
// The loop here extends to the size of the string, so we can send a null
116-
// into the parsing logic to terminate the parsing.
115+
// The loop here extends to the size of the string, so we can AsyncSend a
116+
// null into the parsing logic to terminate the parsing.
117117
for (auto index = 0; index <= str.size(); index++) {
118118
// The character in the string, or null if we go out of bounds of the
119119
// string.

0 commit comments

Comments
 (0)