From 1eb2e5360a0a7a152fc6e896fb3829f259f3a5cb Mon Sep 17 00:00:00 2001 From: Lasan Mahaliyana Date: Tue, 10 Feb 2026 18:33:51 +0530 Subject: [PATCH] QoL --- internal/platform/implementation/linux/avahi.cc | 7 +++++++ internal/platform/implementation/linux/avahi.h | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/platform/implementation/linux/avahi.cc b/internal/platform/implementation/linux/avahi.cc index fa443ce1..c437699c 100644 --- a/internal/platform/implementation/linux/avahi.cc +++ b/internal/platform/implementation/linux/avahi.cc @@ -27,7 +27,14 @@ void Server::onResolveServiceReply(const int32_t& interface, const std::string& address, const uint16_t& port, const std::vector>& txt, const uint32_t& flags, const sdbus::Error* error) { + if (error != nullptr && error->isValid()) { + LOG(ERROR) << __func__ << ": ResolveService failed with error '" + << error->getName() << "' message '" << error->getMessage() + << "'"; + return; + } + LOG(INFO) << "Resolved reply received"; NsdServiceInfo info; info.SetServiceName(name); diff --git a/internal/platform/implementation/linux/avahi.h b/internal/platform/implementation/linux/avahi.h index da8cb2ca..4c2578f3 100644 --- a/internal/platform/implementation/linux/avahi.h +++ b/internal/platform/implementation/linux/avahi.h @@ -29,6 +29,16 @@ namespace nearby { namespace linux { namespace avahi { +namespace { +api::WifiLanMedium::DiscoveredServiceCallback MakeNoopDiscoveredServiceCallback() { + api::WifiLanMedium::DiscoveredServiceCallback cb{}; + + cb.service_discovered_cb = [](NsdServiceInfo) {}; + cb.service_lost_cb = [](NsdServiceInfo) {}; + + return cb; +} +} // namespace class Server final : public sdbus::ProxyInterfaces { public: @@ -40,8 +50,12 @@ class Server final registerProxy(); } Server(sdbus::IConnection& system_bus) - : Server(system_bus, {}) {} + : Server(system_bus, MakeNoopDiscoveredServiceCallback()) {} ~Server() { unregisterProxy(); } + void SetDiscoveryCallback( + api::WifiLanMedium::DiscoveredServiceCallback callback) { + discovery_cb_ = std::move(callback); + } api::WifiLanMedium::DiscoveredServiceCallback discovery_cb_; protected: void onStateChanged(const int32_t &state, const std::string &error) override { @@ -88,7 +102,6 @@ class ServiceBrowser final public: ServiceBrowser(sdbus::IConnection &system_bus, const sdbus::ObjectPath &service_browser_object_path, - api::WifiLanMedium::DiscoveredServiceCallback callback, std::shared_ptr avahi_server) : ProxyInterfaces(system_bus, "org.freedesktop.Avahi", service_browser_object_path),