31 case EventType::ClientConnected:
32 return "client_connected";
33 case EventType::ClientDisconnected:
34 return "client_disconnected";
35 case EventType::EvalStart:
37 case EventType::EvalSuccess:
38 return "eval_success";
39 case EventType::EvalError:
41 case EventType::SymbolDefined:
42 return "symbol_defined";
43 case EventType::ServerStart:
44 return "server_start";
45 case EventType::ServerStop:
98 std::optional<std::string>
type;
126 StreamEvent(EventType t, EventData d = std::monostate {});
153 { handler(event) } -> std::same_as<void>;
182 std::unordered_map<EventType, std::vector<std::weak_ptr<Subscription>>>
m_subscribers;
191 void subscribe(EventType type,
const std::shared_ptr<Subscription>& subscriber);
199 template <EventHandler Handler>
204 HandlerSubscription(Handler&& h)
205 : m_handler(std::forward<Handler>(h))
208 void on_event(
const StreamEvent& event)
override { m_handler(event); }
211 subscribe(type, std::make_shared<HandlerSubscription>(std::forward<Handler>(handler)));
std::mutex m_mutex
Mutex for thread safety.
std::unordered_map< EventType, std::vector< std::weak_ptr< Subscription > > > m_subscribers
Subscribers by event type.
void subscribe(EventType type, const std::shared_ptr< Subscription > &subscriber)
Subscribe to an event type with a Subscription object.
void subscribe(EventType type, Handler &&handler)
Subscribe to an event type with a handler function.
void publish(const StreamEvent &event)
Publish an event to all subscribers of its type.
Thread-safe event subscription and publishing system for Lila.
virtual ~Subscription()=default
virtual void on_event(const StreamEvent &event)=0
Called when an event is published.
Abstract base class for event subscriptions.
std::variant< ClientInfo, EvalEvent, std::monostate, ErrorEvent, SymbolEvent > EventData
Variant type for event data.
EventType
Enumerates all event types supported by the Lila event system.
Concept for event handler functions.
constexpr std::string_view to_string(EventType type)
Converts an EventType to its string representation.
std::string session_id
Session identifier (if set)
int fd
Client socket file descriptor.
std::chrono::system_clock::time_point connected_at
Connection timestamp.
auto operator<=>(const ClientInfo &) const =default
Information about a connected client.
std::optional< std::string > details
Optional error details.
std::chrono::system_clock::time_point timestamp
Event timestamp.
std::string message
Error message.
std::optional< std::string > session_id
Optional session ID.
std::chrono::system_clock::time_point timestamp
Event timestamp.
std::string code_snippet
The code being evaluated.
Data for code evaluation events.
EventType type
Type of event.
EventData data
Event data.
std::chrono::system_clock::time_point timestamp
Event timestamp.
Represents a published event in the system.
std::optional< uintptr_t > address
Optional symbol address.
std::optional< std::string > type
Optional symbol type.
std::string name
Symbol name.
Data for symbol definition events.