Class SseTransportProvider

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class SseTransportProvider : public ros2_medkit_gateway::SubscriptionTransportProvider

Built-in SSE transport provider. Refactored from handle_events() logic.

Lifetime: must outlive all HTTP connections. GatewayNode ensures this by stopping the REST server (joining HTTP threads) before destroying transports.

Public Functions

SseTransportProvider(SubscriptionManager &sub_mgr, std::shared_ptr<SSEClientTracker> client_tracker)
inline virtual std::string protocol() const override

Protocol identifier: “sse” (standard), or vendor extension.

virtual tl::expected<std::string, std::string> start(const CyclicSubscriptionInfo &info, ResourceSamplerFn json_sampler, GatewayNode *node) override

Start delivery for a subscription. Returns event_source URI for client.

virtual void notify_update(const std::string &sub_id) override

Subscription interval/duration changed. Transport must re-read info.

virtual void stop(const std::string &sub_id) override

Stop delivery for a subscription.

For HTTP-based transports (SSE), the HTTP server thread join handles synchronous stop - stop() removes state so the streaming loop exits on its next is_active() check. GatewayNode::~GatewayNode() calls stop_rest_server() before shutdown_all() to ensure this ordering.

Non-HTTP transports MUST ensure all delivery threads have stopped before returning from this method.

virtual tl::expected<http::SseStream, ErrorInfo> make_sse_stream(const std::string &sub_id) override

Open a new client stream for the given subscription. HTTP-based transports (SSE) build an whose next_event callback the typed router drives via cpp-httplib’s chunked content provider. Non-HTTP transports (MQTT, WebSocket, Zenoh) return an ErrorInfo so the typed handler renders a SOVD GenericError.

On failure (unknown sub_id, client-limit exhausted, …) the implementation returns a fully-formed ErrorInfo whose http_status drives the wire status code. On success the returned SseStream’s lifetime owns the transport-side client-tracker handle (e.g. via a shared_ptr deleter on a captured tracker token) so the slot is released when the framework destroys the stream - either on client disconnect or end-of-stream.