LibQuicR
quicr::PublishNamespaceHandler Class Reference

Publishes and manages tracks below one namespace prefix. More...

#include <publish_namespace_handler.h>

Inheritance diagram for quicr::PublishNamespaceHandler:
quicr::TrackHandler

Public Types

enum class  Status : uint8_t {
  kOk = 0 , kNotConnected , kNotPublished , kPendingResponse ,
  kPublishNotAuthorized , kSendingDone , kError
}
 Status codes for the Publish track. More...
 

Public Member Functions

virtual ~PublishNamespaceHandler ()
 Unpublishes all retained tracks when an attached session still exists. More...
 
virtual void PublishTrack (std::shared_ptr< PublishTrackHandler > handler)
 Publish a new track. More...
 
virtual void UnPublishTrack (std::shared_ptr< PublishTrackHandler > handler)
 Removes and unpublishes a track. More...
 
virtual PublishTrackHandler::PublishObjectStatus PublishObject (uint64_t track_alias, const ObjectHeaders &object_headers, BytesSpan data, std::optional< messages::StreamHeaderProperties > stream_mode=std::nullopt)
 Passthrough PublishObject to Publish Track matching full name hash. More...
 
virtual PublishTrackHandler::PublishObjectStatus ForwardPublishedData ([[maybe_unused]] uint64_t track_alias, [[maybe_unused]] bool is_new_stream, [[maybe_unused]] uint64_t group_id, [[maybe_unused]] uint64_t subgroup_id, [[maybe_unused]] std::shared_ptr< const std::vector< uint8_t >> data)
 Passthrough to Forward received object data to each publish handler. More...
 
const TrackNamespace & GetPrefix () const noexcept
 
constexpr Status GetStatus () const noexcept
 Get the status of the Publish. More...
 
std::optional< Error< ErrorCode > > GetError () const noexcept
 Get the error code and reason for the Publish namespace, if any. More...
 
template<typename T >
requires std::is_base_of_v< TrackHandler, T > std::shared_ptr< T > Get ()
 Get the derived type of the track handler. More...
 
void SetRequestId (std::optional< uint64_t > request_id)
 Sets or clears the connection-scoped request ID. More...
 
std::optional< uint64_t > GetRequestId () const noexcept
 Get the request ID. More...
 
std::optional< uint64_t > GetRequestStreamId () const
 Get the stream ID of the request control stream. More...
 
FullTrackName GetFullTrackName () const noexcept
 Get the full track name. More...
 
uint64_t GetConnectionId () const noexcept
 Gets the transport connection identifier assigned by the session. More...
 
std::shared_ptr< Connection > GetConnection () const
 
Binding GetBinding () const
 

Static Public Member Functions

static auto Create (const TrackNamespace &prefix)
 Creates a namespace publisher with shared ownership. More...
 

Protected Member Functions

 PublishNamespaceHandler (const TrackNamespace &prefix)
 Constructs an inactive namespace publisher. More...
 
virtual void StatusChanged (Status status)
 Notification of Publish status. More...
 
void SetStatus (const Status status) noexcept
 Set the Publish status. More...
 
void SetError (const Error< ErrorCode > &error)
 Stores an error and transitions to kError. More...
 
void RequestOkReceived (const messages::Parameters &params) override
 Handles peer acceptance by entering kOk. More...
 
Reply< messages::Parameters, ErrorCode > RequestUpdateReceived (const messages::Parameters &params) override
 Rejects updates to a namespace publication. More...
 
void RequestError (ErrorCode error_code, std::string reason) override
 Stores a request error and enters kError. More...
 
void SetTransport (std::shared_ptr< Session > transport)
 Sets the session used for control and data operations. More...
 
const std::weak_ptr< Session > & GetSession () const noexcept
 Gets the non-owning session handle. More...
 

Protected Attributes

std::map< std::uint64_t, std::shared_ptr< PublishTrackHandler > > handlers_
 Track publishers keyed by the full-track-name hash. More...
 
FullTrackName full_track_name_
 Full track identity retained for the handler's lifetime. More...
 
std::mutex binding_operation_mutex_
 

Detailed Description

Publishes and manages tracks below one namespace prefix.

The handler owns shared references to registered track publishers. Public operations are not internally synchronized and should be serialized with session/application callbacks.

Member Enumeration Documentation

◆ Status

Status codes for the Publish track.

Enumerator
kOk 

Namespace is accepted and active.

kNotConnected 

Session transport is disconnected.

kNotPublished 

Initial/inactive state.

kPendingResponse 

Waiting for the peer's response.

kPublishNotAuthorized 

Peer denied publication.

kSendingDone 

In this state, callbacks will not be called.

kError 

Request failed; inspect GetError().

Constructor & Destructor Documentation

◆ PublishNamespaceHandler()

quicr::PublishNamespaceHandler::PublishNamespaceHandler ( const TrackNamespace &  prefix)
protected

Constructs an inactive namespace publisher.

Parameters
prefixPrefix that every contained track must share.

◆ ~PublishNamespaceHandler()

virtual quicr::PublishNamespaceHandler::~PublishNamespaceHandler ( )
virtual

Unpublishes all retained tracks when an attached session still exists.

Note
Destruction may call into the session; retained track handlers are released afterward.

Member Function Documentation

◆ Create()

static auto quicr::PublishNamespaceHandler::Create ( const TrackNamespace &  prefix)
inlinestatic

Creates a namespace publisher with shared ownership.

Parameters
prefixPrefix that every contained track must share.
Returns
Shared ownership of the new handler.

◆ ForwardPublishedData()

virtual PublishTrackHandler::PublishObjectStatus quicr::PublishNamespaceHandler::ForwardPublishedData ( [[maybe_unused] ] uint64_t  track_alias,
[[maybe_unused] ] bool  is_new_stream,
[[maybe_unused] ] uint64_t  group_id,
[[maybe_unused] ] uint64_t  subgroup_id,
[[maybe_unused] ] std::shared_ptr< const std::vector< uint8_t >>  data 
)
inlinevirtual

Passthrough to Forward received object data to each publish handler.

Passthrough to send to the publish handlers. Selection and filters can be applied.

Note
This method must be overridden to be useful. The default always returns kInternalError and does not inspect its arguments or forward data.
Parameters
track_aliasTrack alias
is_new_streamIndicates if this data starts a new stream
group_idGroup ID for stream
subgroup_idSubgroup ID for stream
dataMoQ data to send
Returns
PublishObjectStatus from publish handler

◆ Get()

template<typename T >
requires std::is_base_of_v<TrackHandler, T> std::shared_ptr<T> quicr::TrackHandler::Get ( )
inlineinherited

Get the derived type of the track handler.

Template Parameters
TDerived type of the track handler.
Returns
Shared ownership cast to T, or null when the dynamic type is incompatible.
Exceptions
std::bad_weak_ptrif this object is not currently owned by a shared_ptr.

◆ GetBinding()

Binding quicr::TrackHandler::GetBinding ( ) const
inlineinherited

◆ GetConnection()

std::shared_ptr<Connection> quicr::TrackHandler::GetConnection ( ) const
inherited

◆ GetConnectionId()

uint64_t quicr::TrackHandler::GetConnectionId ( ) const
inlinenoexceptinherited

Gets the transport connection identifier assigned by the session.

Returns
Connection ID, or the initial value zero before assignment.

◆ GetError()

std::optional<Error<ErrorCode> > quicr::PublishNamespaceHandler::GetError ( ) const
inlinenoexcept

Get the error code and reason for the Publish namespace, if any.

Returns
Publish namespace error code and reason.

◆ GetFullTrackName()

FullTrackName quicr::TrackHandler::GetFullTrackName ( ) const
inlinenoexceptinherited

Get the full track name.

Returns
A copy of the full track name.

◆ GetPrefix()

const TrackNamespace& quicr::PublishNamespaceHandler::GetPrefix ( ) const
inlinenoexcept
Returns
Borrowed immutable prefix, valid for this handler's lifetime.

◆ GetRequestId()

std::optional<uint64_t> quicr::TrackHandler::GetRequestId ( ) const
inlinenoexceptinherited

Get the request ID.

Returns
Current connection-scoped request ID, or std::nullopt when none is assigned.

◆ GetRequestStreamId()

std::optional<uint64_t> quicr::TrackHandler::GetRequestStreamId ( ) const
inherited

Get the stream ID of the request control stream.

Returns
Request stream's ID, or std::nullopt if no stream is attached.
Note
Thread-safe with request-stream installation/removal.

◆ GetSession()

const std::weak_ptr<Session>& quicr::TrackHandler::GetSession ( ) const
protectednoexceptinherited

Gets the non-owning session handle.

Returns
Borrowed reference to the stored weak pointer, valid for this handler's lifetime. Callers must lock it before use.

◆ GetStatus()

constexpr Status quicr::PublishNamespaceHandler::GetStatus ( ) const
inlineconstexprnoexcept

Get the status of the Publish.

Returns
Status of the Publish

◆ PublishObject()

virtual PublishTrackHandler::PublishObjectStatus quicr::PublishNamespaceHandler::PublishObject ( uint64_t  track_alias,
const ObjectHeaders &  object_headers,
BytesSpan  data,
std::optional< messages::StreamHeaderProperties >  stream_mode = std::nullopt 
)
virtual

Passthrough PublishObject to Publish Track matching full name hash.

Passthrough to send to the publish handler. Selection and filters maybe applied.

Parameters
track_aliasTrack alias
object_headersObject headers, must include group and object Ids
dataFull complete payload data for the object
stream_modeMOQT stream mode, stream mode
Returns
PublishObjectStatus from publish handler

The alias is looked up in handlers_. No handler yields kInternalError. The payload view is borrowed only for this call; the selected handler copies it before asynchronous transmission.

Exceptions
TransportExceptionPropagated if the selected publisher cannot enqueue data.

◆ PublishTrack()

virtual void quicr::PublishNamespaceHandler::PublishTrack ( std::shared_ptr< PublishTrackHandler >  handler)
virtual

Publish a new track.

Creates a new publish track handler that will be used to send data for a track. Selection and filters may be applied here.

Parameters
handlerPublish Track Handler for the publish
Exceptions
std::invalid_argumentif the handler's namespace does not share this prefix.
std::runtime_errorif this namespace handler has no live session.

Retains shared ownership under the track-name hash and asks the session to publish it. handler must not be null.

◆ RequestError()

void quicr::PublishNamespaceHandler::RequestError ( ErrorCode  error_code,
std::string  reason 
)
inlineoverrideprotectedvirtual

Stores a request error and enters kError.

Parameters
error_codePeer-provided error code.
reasonPeer-provided reason, moved into the stored error.

Reimplemented from quicr::TrackHandler.

◆ RequestOkReceived()

void quicr::PublishNamespaceHandler::RequestOkReceived ( const messages::Parameters &  params)
overrideprotectedvirtual

Handles peer acceptance by entering kOk.

Parameters
paramsResponse parameters, which are ignored without validation.

Implements quicr::TrackHandler.

◆ RequestUpdateReceived()

Reply<messages::Parameters, ErrorCode> quicr::PublishNamespaceHandler::RequestUpdateReceived ( const messages::Parameters &  params)
overrideprotectedvirtual

Rejects updates to a namespace publication.

Parameters
paramsUnused update parameters.
Returns
Never returns.
Exceptions
messages::ProtocolViolationExceptionAlways.

Implements quicr::TrackHandler.

◆ SetError()

void quicr::PublishNamespaceHandler::SetError ( const Error< ErrorCode > &  error)
inlineprotected

Stores an error and transitions to kError.

Parameters
errorError code and optional reason, copied into the handler.

◆ SetRequestId()

void quicr::TrackHandler::SetRequestId ( std::optional< uint64_t >  request_id)
inlineinherited

Sets or clears the connection-scoped request ID.

Parameters
request_idRequest ID assigned by the session, or std::nullopt when unbound.
Note
Thread-safe with request-stream installation and removal.

◆ SetStatus()

void quicr::PublishNamespaceHandler::SetStatus ( const Status  status)
inlineprotectednoexcept

Set the Publish status.

Parameters
statusStatus of the Publish

Entering kError without a preceding SetError() installs an internal-error fallback, then invokes StatusChanged even if the value did not change.

◆ SetTransport()

void quicr::TrackHandler::SetTransport ( std::shared_ptr< Session >  transport)
protectedinherited

Sets the session used for control and data operations.

Parameters
transportSession retained weakly; passing null clears effective access.
Note
The caller must keep the session alive independently.

◆ StatusChanged()

virtual void quicr::PublishNamespaceHandler::StatusChanged ( Status  status)
protectedvirtual

Notification of Publish status.

Notification of the Publish status

Parameters
statusIndicates status of the Publish
Note
Default implementation does nothing. Called synchronously on a session path.

◆ UnPublishTrack()

virtual void quicr::PublishNamespaceHandler::UnPublishTrack ( std::shared_ptr< PublishTrackHandler >  handler)
virtual

Removes and unpublishes a track.

Parameters
handlerTrack publisher to remove; must not be null.
Exceptions
std::runtime_errorif this namespace handler has no live session.

Member Data Documentation

◆ binding_operation_mutex_

std::mutex quicr::TrackHandler::binding_operation_mutex_
protectedinherited

◆ full_track_name_

FullTrackName quicr::TrackHandler::full_track_name_
protectedinherited

Full track identity retained for the handler's lifetime.

◆ handlers_

std::map<std::uint64_t, std::shared_ptr<PublishTrackHandler> > quicr::PublishNamespaceHandler::handlers_
protected

Track publishers keyed by the full-track-name hash.

Entries retain shared ownership until explicitly unpublished or this namespace handler is destroyed. Derived classes may inspect or customize routing through this map.


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