11#include "ffi/events.h"
12#include "listener.hpp"
30 int (*
send)(
const uint8_t* data, uint32_t size);
32 Listener&, event_callback,
void* user_data,
char priority,
const char* label
38void registerProtoEntry(std::string name,
ProtoEntry entry);
42template<ExposedEvent T>
43void registerProtoEvent() {
45 using Proto =
typename Traits::Proto;
47 EventSystem::registerEvent<T>();
50 .send = [](
const uint8_t* data, uint32_t size) ->
int {
52 if (not p.ParseFromArray(data,
static_cast<int>(size))) {
55 event::send<T>(Traits::fromProto(p));
59 [](
Listener& l, event_callback callback,
void* user_data,
char priority,
const char* label) {
62 [callback, user_data](T& ev) ->
bool {
64 Proto p = Traits::toProto(ev);
65 std::string bytes = p.SerializeAsString();
66 std::string name {Proto::descriptor()->full_name()};
69 reinterpret_cast<const uint8_t*
>(bytes.data()),
70 static_cast<uint32_t
>(bytes.size()),
73 }
catch (
const std::exception& e) {
75 TOAST_WARN(
"Events",
"Failed to serialize event {}: {}", Proto::descriptor()->full_name(), e.what());
82 .unsubscribe = [](
Listener& l,
const char* label) { l.unsubscribe<T>(std::string_view {label}); },
85 _detail::registerProtoEntry(std::string {Proto::descriptor()->full_name()}, entry);
92 static std::vector<void (*)()> registrars;
98template<ExposedEvent T>
99struct ProtoAutoRegister {
100 ProtoAutoRegister() {
109#define TOAST_PROTO_CAT_IMPL(a, b) a##b
110#define TOAST_PROTO_CAT(a, b) TOAST_PROTO_CAT_IMPL(a, b)
113#define TOAST_PROTO_EVENT(EventType) \
114 static const ::event::_detail::ProtoAutoRegister<EventType> TOAST_PROTO_CAT(_proto_auto_, __LINE__) { }
manages the lifetime, subscription, and unsubscription of callbacks
Definition listener.hpp:39
#define TOAST_WARN(sink,...)
Indicates possible code missuse.
Definition log.hpp:94
auto protoRegistrars() -> std::vector< void(*)()> &
Returns the global list of proto registration callbacks; each TOAST_PROTO_EVENT() macro appends one e...
Definition proto_event.hpp:91
Specialization point that exposes a C++ event type over the C# FFI via protobuf.
Definition event.hpp:188
Dispatch table for one protobuf-backed event type over the FFI.
Definition proto_event.hpp:29
void(* unsubscribe)(Listener &, const char *label)
cancels a subscription by label
Definition proto_event.hpp:34
int(* send)(const uint8_t *data, uint32_t size)
C# -> engine: deserializes bytes and dispatches the event.
Definition proto_event.hpp:30
void(* subscribe)(Listener &, event_callback, void *user_data, char priority, const char *label)
engine -> C#: serializes the event and calls the C# callback
Definition proto_event.hpp:31