17#include <condition_variable>
18#include <unordered_map>
30 void start(std::chrono::milliseconds interval = std::chrono::seconds(2));
42 std::function<void(
const std::vector<std::string>& volumes)>
on_change;
45 std::atomic<bool> running_{
false};
48 std::condition_variable cv_;
49 std::vector<std::string> last_volumes_;
72 using TxtRecords = std::unordered_map<std::string, std::string>;
91 virtual void browse(std::string_view service_type,
95 std::string_view type,
101 std::string_view type,
123 void browse(std::string_view service_type);
136 std::string_view type,
160 const std::vector<Service>&
discovered()
const {
return services_; }
163 std::vector<Service> services_;
164 std::atomic<bool> running_{
false};
165 std::thread browse_thread_;
166 std::unique_ptr<Backend> backend_;
182 std::atomic<bool> pending_{
false};
184 std::condition_variable cv_;
Locking variant of CoalescedUpdater — blocks the trigger thread until the update is processed on the ...
Definition volume_detector.hpp:171
virtual ~LockingCoalescedUpdater()=default
virtual void on_update()=0
Override to handle the update.
void trigger_and_wait()
Trigger and wait for the update to be processed.
void start(std::chrono::milliseconds interval=std::chrono::seconds(2))
Start monitoring with the given poll interval.
bool is_running() const
Whether monitoring is active.
Definition volume_detector.hpp:36
MountedVolumeListChangeDetector()=default
std::function< void(const std::vector< std::string > &volumes)> on_change
Called when the volume list changes.
Definition volume_detector.hpp:42
~MountedVolumeListChangeDetector()
static std::vector< std::string > get_mounted_volumes()
Get current list of mounted volumes.
void stop()
Stop monitoring.
Backend interface the host installs to get real mDNS.
Definition volume_detector.hpp:88
virtual void browse(std::string_view service_type, NetworkServiceDiscovery &owner)=0
virtual bool register_service(std::string_view name, std::string_view type, uint16_t port, const TxtRecords &)
Default implementation drops the TXT records and forwards to the base three-argument register_service...
Definition volume_detector.hpp:100
virtual ~Backend()=default
virtual bool register_service(std::string_view name, std::string_view type, uint16_t port)=0
virtual void unregister_service()=0
NetworkServiceDiscovery()=default
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.
std::function< void(const Service &)> on_service_lost
Called when a service is lost.
Definition volume_detector.hpp:157
void stop()
Stop browsing.
std::function< void(const Service &)> on_service_found
Called when a service is discovered.
Definition volume_detector.hpp:154
bool has_backend() const noexcept
Whether a concrete backend is installed.
Definition volume_detector.hpp:119
void browse(std::string_view service_type)
Start browsing for services of the given type.
bool register_service(std::string_view name, std::string_view type, uint16_t port)
Register a service on this machine.
void install_backend(std::unique_ptr< Backend > backend)
Install a concrete backend.
~NetworkServiceDiscovery()
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
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.
const std::vector< Service > & discovered() const
Currently discovered services.
Definition volume_detector.hpp:160
Definition child_process_manager.hpp:18
Definition volume_detector.hpp:74
std::string type
Definition volume_detector.hpp:76
uint16_t port
Definition volume_detector.hpp:79
TxtRecords txt_records
Definition volume_detector.hpp:80
std::string hostname
Definition volume_detector.hpp:77
std::string address
Definition volume_detector.hpp:78
std::string name
Definition volume_detector.hpp:75