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. | |
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).
| 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.
|
default |
| pulp::events::NetworkServiceDiscovery::~NetworkServiceDiscovery | ( | ) |
| 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.
|
inline |
Currently discovered services.
|
inlinenoexcept |
Whether a concrete backend is installed.
Callers can use this to detect "no mDNS available" instead of silently discovering nothing.
| void pulp::events::NetworkServiceDiscovery::install_backend | ( | std::unique_ptr< Backend > | backend | ) |
Install a concrete backend.
Takes ownership. Pass nullptr to remove.
| 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.
| 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.
| 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.
| 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.
| void pulp::events::NetworkServiceDiscovery::stop | ( | ) |
Stop browsing.
| void pulp::events::NetworkServiceDiscovery::unregister_service | ( | ) |
Unregister a previously registered service.
| std::function<void(const Service&)> pulp::events::NetworkServiceDiscovery::on_service_found |
Called when a service is discovered.
| std::function<void(const Service&)> pulp::events::NetworkServiceDiscovery::on_service_lost |
Called when a service is lost.