Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::events::NetworkServiceDiscovery Class Reference

mDNS-based network service discovery (Bonjour/DNS-SD). More...

#include <volume_detector.hpp>

Classes

struct  Service
class  Backend
 Backend interface the host installs to get real mDNS. More...

Public Types

using TxtRecords = std::unordered_map<std::string, std::string>
 TXT records carry arbitrary key=value metadata published with a service registration (RFC 6763 §6).

Public Member Functions

 NetworkServiceDiscovery ()=default
 ~NetworkServiceDiscovery ()
void install_backend (std::unique_ptr< Backend > backend)
 Install a concrete backend.
bool has_backend () const noexcept
 Whether a concrete backend is installed.
void browse (std::string_view service_type)
 Start browsing for services of the given type.
void stop ()
 Stop browsing.
bool register_service (std::string_view name, std::string_view type, uint16_t port)
 Register a service on this machine.
bool register_service (std::string_view name, std::string_view type, uint16_t port, const TxtRecords &txt_records)
 Register a service with TXT records (RFC 6763 §6 metadata).
void unregister_service ()
 Unregister a previously registered service.
void notify_service_found (const Service &svc)
 Push a discovered service into the core layer.
void notify_service_lost (const Service &svc)
 Push a lost service into the core layer.
const std::vector< Service > & discovered () const
 Currently discovered services.

Public Attributes

std::function< void(const Service &)> on_service_found
 Called when a service is discovered.
std::function< void(const Service &)> on_service_lost
 Called when a service is lost.

Detailed Description

mDNS-based network service discovery (Bonjour/DNS-SD).

Status — experimental. The core/events module ships the API surface; platform backends are optional. browse() with no backend installed is a no-op (does not claim running); nothing will ever be discovered until a host application installs a backend via install_backend(). register_service() without a backend returns false.

Consumers that need real mDNS must supply their own backend (e.g., linking an application-owned Bonjour wrapper and plumbing the callbacks).

Member Typedef Documentation

◆ TxtRecords

using pulp::events::NetworkServiceDiscovery::TxtRecords = std::unordered_map<std::string, std::string>

TXT records carry arbitrary key=value metadata published with a service registration (RFC 6763 §6).

Keys are case-insensitive ASCII; values may be any bytes (binary-safe via std::string). A backend that cannot encode TXT records (e.g., a degraded UDP heartbeat) should still publish the base service and silently drop the records — never fail registration.

Constructor & Destructor Documentation

◆ NetworkServiceDiscovery()

pulp::events::NetworkServiceDiscovery::NetworkServiceDiscovery ( )
default

◆ ~NetworkServiceDiscovery()

pulp::events::NetworkServiceDiscovery::~NetworkServiceDiscovery ( )

Member Function Documentation

◆ browse()

void pulp::events::NetworkServiceDiscovery::browse ( std::string_view service_type)

Start browsing for services of the given type.

Without an installed backend this is a no-op.

◆ discovered()

const std::vector< Service > & pulp::events::NetworkServiceDiscovery::discovered ( ) const
inline

Currently discovered services.

◆ has_backend()

bool pulp::events::NetworkServiceDiscovery::has_backend ( ) const
inlinenoexcept

Whether a concrete backend is installed.

Callers can use this to detect "no mDNS available" instead of silently discovering nothing.

◆ install_backend()

void pulp::events::NetworkServiceDiscovery::install_backend ( std::unique_ptr< Backend > backend)

Install a concrete backend.

Takes ownership. Pass nullptr to remove.

◆ notify_service_found()

void pulp::events::NetworkServiceDiscovery::notify_service_found ( const Service & svc)

Push a discovered service into the core layer.

Backends call this when they learn about a new service; triggers on_service_found.

◆ notify_service_lost()

void pulp::events::NetworkServiceDiscovery::notify_service_lost ( const Service & svc)

Push a lost service into the core layer.

Backends call this when a service disappears; triggers on_service_lost and removes it from the discovered() list.

◆ register_service() [1/2]

bool pulp::events::NetworkServiceDiscovery::register_service ( std::string_view name,
std::string_view type,
uint16_t port )

Register a service on this machine.

Returns false when no backend is installed or the backend can't register.

◆ register_service() [2/2]

bool pulp::events::NetworkServiceDiscovery::register_service ( std::string_view name,
std::string_view type,
uint16_t port,
const TxtRecords & txt_records )

Register a service with TXT records (RFC 6763 §6 metadata).

Returns false when no backend is installed or registration fails. Backends without TXT support silently drop the records.

◆ stop()

void pulp::events::NetworkServiceDiscovery::stop ( )

Stop browsing.

◆ unregister_service()

void pulp::events::NetworkServiceDiscovery::unregister_service ( )

Unregister a previously registered service.

Member Data Documentation

◆ on_service_found

std::function<void(const Service&)> pulp::events::NetworkServiceDiscovery::on_service_found

Called when a service is discovered.

◆ on_service_lost

std::function<void(const Service&)> pulp::events::NetworkServiceDiscovery::on_service_lost

Called when a service is lost.


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