This commit is contained in:
Lasan Mahaliyana
2026-02-10 18:33:51 +05:30
parent 98675edaca
commit 1eb2e5360a
2 changed files with 22 additions and 2 deletions
@@ -27,7 +27,14 @@ void Server::onResolveServiceReply(const int32_t& interface,
const std::string& address, const uint16_t& port,
const std::vector<std::vector<uint8_t>>& 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);
+15 -2
View File
@@ -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<org::freedesktop::Avahi::Server2_proxy> {
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<Server> avahi_server)
: ProxyInterfaces(system_bus, "org.freedesktop.Avahi",
service_browser_object_path),