mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-15 07:06:11 -04:00
QoL
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user