Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
service_discovery.hpp
Go to the documentation of this file.
1#pragma once
2
3// pulp::events::ServiceBrowser / ServicePublisher — RAII wrappers around
4// NetworkServiceDiscovery for the common single-publish / single-browse
5// shapes.
6//
7// The underlying NSD object remains the configurable dispatcher when a
8// caller needs install_backend / multiple browses; these wrappers exist
9// because 80% of consumers want "publish this service, stop publishing
10// on scope exit" or "browse this type, stop browsing on scope exit"
11// without managing the NSD lifecycle by hand.
12
14
15#include <functional>
16#include <memory>
17#include <string>
18#include <string_view>
19
20namespace pulp::events {
21
27
36
46public:
47 ServicePublisher(std::string_view name,
48 std::string_view type,
49 uint16_t port,
52
55
56 bool is_published() const noexcept { return published_; }
57
60 NetworkServiceDiscovery& nsd() noexcept { return nsd_; }
61
64 static std::unique_ptr<ServicePublisher> with_backend(
65 std::unique_ptr<NetworkServiceDiscovery::Backend> backend,
66 std::string_view name,
67 std::string_view type,
68 uint16_t port,
70
71private:
72 struct WithBackendTag {};
73 ServicePublisher(WithBackendTag,
74 std::unique_ptr<NetworkServiceDiscovery::Backend> backend,
75 std::string_view name,
76 std::string_view type,
77 uint16_t port,
79
80 NetworkServiceDiscovery nsd_;
81 bool published_ = false;
82};
83
91public:
92 using Callback = std::function<void(ServiceDiscoveryAction,
94
95 ServiceBrowser(std::string_view service_type, Callback callback);
97
100
101 bool is_browsing() const noexcept { return has_backend_; }
102
103 NetworkServiceDiscovery& nsd() noexcept { return nsd_; }
104
107 static std::unique_ptr<ServiceBrowser> with_backend(
108 std::unique_ptr<NetworkServiceDiscovery::Backend> backend,
109 std::string_view service_type,
110 Callback callback);
111
112private:
113 struct WithBackendTag {};
114 ServiceBrowser(WithBackendTag,
115 std::unique_ptr<NetworkServiceDiscovery::Backend> backend,
116 std::string_view service_type,
117 Callback callback);
118
119 void wire_callbacks(Callback callback);
120
122 bool has_backend_ = false;
123};
124
125} // namespace pulp::events
mDNS-based network service discovery (Bonjour/DNS-SD).
Definition volume_detector.hpp:64
std::unordered_map< std::string, std::string > TxtRecords
TXT records carry arbitrary key=value metadata published with a service registration (RFC 6763 §6).
Definition volume_detector.hpp:72
static std::unique_ptr< ServiceBrowser > with_backend(std::unique_ptr< NetworkServiceDiscovery::Backend > backend, std::string_view service_type, Callback callback)
Construct a browser that uses a caller-supplied backend instead of the platform default.
ServiceBrowser(std::string_view service_type, Callback callback)
ServiceBrowser(const ServiceBrowser &)=delete
std::function< void(ServiceDiscoveryAction, const NetworkServiceDiscovery::Service &)> Callback
Definition service_discovery.hpp:92
NetworkServiceDiscovery & nsd() noexcept
Definition service_discovery.hpp:103
bool is_browsing() const noexcept
Definition service_discovery.hpp:101
ServiceBrowser & operator=(const ServiceBrowser &)=delete
ServicePublisher(const ServicePublisher &)=delete
static std::unique_ptr< ServicePublisher > with_backend(std::unique_ptr< NetworkServiceDiscovery::Backend > backend, std::string_view name, std::string_view type, uint16_t port, NetworkServiceDiscovery::TxtRecords txt_records={})
Construct a publisher that uses a caller-supplied backend instead of the platform default.
NetworkServiceDiscovery & nsd() noexcept
Access the underlying NSD object — for tests that want to install a fake backend instead of the platf...
Definition service_discovery.hpp:60
ServicePublisher(std::string_view name, std::string_view type, uint16_t port, NetworkServiceDiscovery::TxtRecords txt_records={})
ServicePublisher & operator=(const ServicePublisher &)=delete
bool is_published() const noexcept
Definition service_discovery.hpp:56
Definition child_process_manager.hpp:18
bool install_default_backend(NetworkServiceDiscovery &nsd)
Try to install the host platform's default mDNS backend on nsd.
ServiceDiscoveryAction
Action delivered to a ServiceBrowser callback.
Definition service_discovery.hpp:23
@ ServiceFound
Definition service_discovery.hpp:24
@ ServiceLost
Definition service_discovery.hpp:25
Definition volume_detector.hpp:74