Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::EventSource Class Reference

Base class for anything that produces a stream of events for MCP clients. More...

#include <eventsource.h>

Inheritance diagram for Sonde::EventSource:
Sonde::LogEventSource Sonde::StallEventSource anonymous_namespace{test_instruments.cpp}::NetSource

Public Member Functions

 EventSource (QString name, QString description={ }, QObject *parent=nullptr)
 Creates a source called name (used in filters and resource URIs), described by description in the events tools' descriptions.
 ~EventSource () override
 Destroys the source; the server forgets it.
QString name () const
 The source's name.
QString description () const
 Human-readable description shown in tool descriptions.
void emitEvent (LogLevel level, const QString &message, const QString &category={ }, const QJsonObject &data={ })
 Emits an event.
void eventOccurred (const Sonde::Event &event)
 An event was emitted (sequence is still 0; the server assigns it).

Private Attributes

PrivatePtr< EventSourcePrivate > d
 Implementation.

Detailed Description

Base class for anything that produces a stream of events for MCP clients.

Events emitted by sources added to a Server are kept in a ring buffer and made available through:

  • MCP log notifications (notifications/message, filtered by logging/setLevel)
  • the event_read / event_wait tools
  • a subscribable resource, events://<name>

Use it directly or subclass it:

auto *net = new Sonde::EventSource("network", "requests to the API server");
server.addEventSource(net);
net->emitEvent(Sonde::LogLevel::Warning, "Request timed out", "api");
Base class for anything that produces a stream of events for MCP clients.
Definition eventsource.h:30
@ Warning
Warning conditions.
Definition types.h:35

Constructor & Destructor Documentation

◆ EventSource()

Sonde::EventSource::EventSource ( QString name,
QString description = { },
QObject * parent = nullptr )
explicit

Creates a source called name (used in filters and resource URIs), described by description in the events tools' descriptions.

Both are fixed: the server builds the tools' descriptions from them when the source is added.

Member Function Documentation

◆ emitEvent()

void Sonde::EventSource::emitEvent ( LogLevel level,
const QString & message,
const QString & category = { },
const QJsonObject & data = { } )

Emits an event.

Thread-safe: eventOccurred() is emitted on the calling thread, and a Server records the event there, so it is buffered even while the source's own thread is blocked. Don't destroy the source while another thread may call this.

◆ eventOccurred()

void Sonde::EventSource::eventOccurred ( const Sonde::Event & event)

An event was emitted (sequence is still 0; the server assigns it).

Emitted on the thread that called emitEvent(). Connect with a context object (the usual automatic connection) to receive it on that object's thread.


The documentation for this class was generated from the following files: