From 40c0de886361bd781c92a0bd3c4e4430d5185eac Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 23 May 2019 12:39:22 +0200 Subject: [PATCH 1/2] Kodi, AvahiMonitor: Update to new ZeroConf API --- avahimonitor/devicepluginavahimonitor.cpp | 12 ++++++------ avahimonitor/devicepluginavahimonitor.h | 6 +++--- kodi/devicepluginkodi.cpp | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/avahimonitor/devicepluginavahimonitor.cpp b/avahimonitor/devicepluginavahimonitor.cpp index 49f1a1f6..e2e5dd14 100644 --- a/avahimonitor/devicepluginavahimonitor.cpp +++ b/avahimonitor/devicepluginavahimonitor.cpp @@ -44,7 +44,7 @@ #include "plugin/device.h" #include "devicemanager.h" #include "plugininfo.h" -#include "network/avahi/qtavahiservicebrowser.h" +#include "network/zeroconf/zeroconfservicebrowser.h" #include #include @@ -58,8 +58,8 @@ DevicePluginAvahiMonitor::DevicePluginAvahiMonitor() void DevicePluginAvahiMonitor::init() { - connect(hardwareManager()->avahiBrowser(), &QtAvahiServiceBrowser::serviceEntryAdded, this, &DevicePluginAvahiMonitor::onServiceEntryAdded); - connect(hardwareManager()->avahiBrowser(), &QtAvahiServiceBrowser::serviceEntryRemoved, this, &DevicePluginAvahiMonitor::onServiceEntryRemoved); + connect(hardwareManager()->zeroConfServiceBrowser(), &ZeroConfServiceBrowser::serviceEntryAdded, this, &DevicePluginAvahiMonitor::onServiceEntryAdded); + connect(hardwareManager()->zeroConfServiceBrowser(), &ZeroConfServiceBrowser::serviceEntryRemoved, this, &DevicePluginAvahiMonitor::onServiceEntryRemoved); } DeviceManager::DeviceSetupStatus DevicePluginAvahiMonitor::setupDevice(Device *device) @@ -77,7 +77,7 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic return DeviceManager::DeviceErrorDeviceClassNotFound; QList deviceDescriptors; - foreach (const AvahiServiceEntry &service, hardwareManager()->avahiBrowser()->serviceEntries()) { + foreach (const ZeroConfServiceEntry &service, hardwareManager()->zeroConfServiceBrowser()->serviceEntries()) { DeviceDescriptor deviceDescriptor(avahiDeviceClassId, service.name(), service.hostAddress().toString()); ParamList params; params.append(Param(avahiDeviceServiceParamTypeId, service.name())); @@ -97,7 +97,7 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic return DeviceManager::DeviceErrorAsync; } -void DevicePluginAvahiMonitor::onServiceEntryAdded(const AvahiServiceEntry &serviceEntry) +void DevicePluginAvahiMonitor::onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry) { foreach (Device *device, myDevices()) { if (device->paramValue(avahiDeviceServiceParamTypeId).toString() == serviceEntry.name()) { @@ -107,7 +107,7 @@ void DevicePluginAvahiMonitor::onServiceEntryAdded(const AvahiServiceEntry &serv } } -void DevicePluginAvahiMonitor::onServiceEntryRemoved(const AvahiServiceEntry &serviceEntry) +void DevicePluginAvahiMonitor::onServiceEntryRemoved(const ZeroConfServiceEntry &serviceEntry) { foreach (Device *device, myDevices()) { if (device->paramValue(avahiDeviceServiceParamTypeId).toString() == serviceEntry.name()) { diff --git a/avahimonitor/devicepluginavahimonitor.h b/avahimonitor/devicepluginavahimonitor.h index 1ad123a3..7b531491 100644 --- a/avahimonitor/devicepluginavahimonitor.h +++ b/avahimonitor/devicepluginavahimonitor.h @@ -25,7 +25,7 @@ #define DEVICEPLUGINAVAHIMONITOR_H #include "plugin/deviceplugin.h" -#include "network/avahi/avahiserviceentry.h" +#include "network/zeroconf/zeroconfserviceentry.h" #include @@ -45,8 +45,8 @@ public: DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override; private slots: - void onServiceEntryAdded(const AvahiServiceEntry &serviceEntry); - void onServiceEntryRemoved(const AvahiServiceEntry &serviceEntry); + void onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry); + void onServiceEntryRemoved(const ZeroConfServiceEntry &serviceEntry); }; #endif // DEVICEPLUGINAVAHIMONITOR_H diff --git a/kodi/devicepluginkodi.cpp b/kodi/devicepluginkodi.cpp index 8c47a557..cf41811b 100644 --- a/kodi/devicepluginkodi.cpp +++ b/kodi/devicepluginkodi.cpp @@ -65,8 +65,8 @@ #include "plugin/device.h" #include "plugininfo.h" #include "network/upnp/upnpdiscovery.h" -#include "network/avahi/qtavahiservicebrowser.h" -#include "network/avahi/avahiserviceentry.h" +#include "network/zeroconf/zeroconfservicebrowser.h" +#include "network/zeroconf/zeroconfserviceentry.h" #include "network/networkaccessmanager.h" #include @@ -184,7 +184,7 @@ DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId Q_UNUSED(deviceClassId) QList descriptors; - foreach (const AvahiServiceEntry &avahiEntry, hardwareManager()->avahiBrowser()->serviceEntries()) { + foreach (const ZeroConfServiceEntry &avahiEntry, hardwareManager()->zeroConfServiceBrowser()->serviceEntries()) { if (avahiEntry.serviceType() == "_xbmc-jsonrpc._tcp") { qCDebug(dcKodi) << "Zeroconf entry:" << avahiEntry; DeviceDescriptor descriptor(kodiDeviceClassId, avahiEntry.name(), avahiEntry.hostName() + " (" + avahiEntry.hostAddress().toString() + ")"); From 0820dad5efa2fdc1407a5833edf77dce89c7c0ce Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 4 Jun 2019 18:57:50 +0200 Subject: [PATCH 2/2] Another api change --- avahimonitor/devicepluginavahimonitor.cpp | 16 +++++++++------- avahimonitor/devicepluginavahimonitor.h | 6 ++++-- kodi/devicepluginkodi.cpp | 13 +++++++------ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/avahimonitor/devicepluginavahimonitor.cpp b/avahimonitor/devicepluginavahimonitor.cpp index e2e5dd14..8104f777 100644 --- a/avahimonitor/devicepluginavahimonitor.cpp +++ b/avahimonitor/devicepluginavahimonitor.cpp @@ -44,6 +44,7 @@ #include "plugin/device.h" #include "devicemanager.h" #include "plugininfo.h" +#include "platform/platformzeroconfcontroller.h" #include "network/zeroconf/zeroconfservicebrowser.h" #include @@ -56,12 +57,6 @@ DevicePluginAvahiMonitor::DevicePluginAvahiMonitor() } -void DevicePluginAvahiMonitor::init() -{ - connect(hardwareManager()->zeroConfServiceBrowser(), &ZeroConfServiceBrowser::serviceEntryAdded, this, &DevicePluginAvahiMonitor::onServiceEntryAdded); - connect(hardwareManager()->zeroConfServiceBrowser(), &ZeroConfServiceBrowser::serviceEntryRemoved, this, &DevicePluginAvahiMonitor::onServiceEntryRemoved); -} - DeviceManager::DeviceSetupStatus DevicePluginAvahiMonitor::setupDevice(Device *device) { qCDebug(dcAvahiMonitor()) << "Setup" << device->name() << device->params(); @@ -76,8 +71,14 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic if (deviceClassId != avahiDeviceClassId) return DeviceManager::DeviceErrorDeviceClassNotFound; + if (!m_serviceBrowser) { + m_serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser(); + connect(m_serviceBrowser, &ZeroConfServiceBrowser::serviceEntryAdded, this, &DevicePluginAvahiMonitor::onServiceEntryAdded); + connect(m_serviceBrowser, &ZeroConfServiceBrowser::serviceEntryRemoved, this, &DevicePluginAvahiMonitor::onServiceEntryRemoved); + } + QList deviceDescriptors; - foreach (const ZeroConfServiceEntry &service, hardwareManager()->zeroConfServiceBrowser()->serviceEntries()) { + foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) { DeviceDescriptor deviceDescriptor(avahiDeviceClassId, service.name(), service.hostAddress().toString()); ParamList params; params.append(Param(avahiDeviceServiceParamTypeId, service.name())); @@ -99,6 +100,7 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic void DevicePluginAvahiMonitor::onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry) { + qCDebug(dcAvahiMonitor()) << "Service entry added:" << serviceEntry; foreach (Device *device, myDevices()) { if (device->paramValue(avahiDeviceServiceParamTypeId).toString() == serviceEntry.name()) { device->setStateValue(avahiIsPresentStateTypeId, true); diff --git a/avahimonitor/devicepluginavahimonitor.h b/avahimonitor/devicepluginavahimonitor.h index 7b531491..1e349385 100644 --- a/avahimonitor/devicepluginavahimonitor.h +++ b/avahimonitor/devicepluginavahimonitor.h @@ -25,6 +25,7 @@ #define DEVICEPLUGINAVAHIMONITOR_H #include "plugin/deviceplugin.h" +#include "network/zeroconf/zeroconfservicebrowser.h" #include "network/zeroconf/zeroconfserviceentry.h" #include @@ -39,14 +40,15 @@ class DevicePluginAvahiMonitor : public DevicePlugin public: explicit DevicePluginAvahiMonitor(); - void init() override; - DeviceManager::DeviceSetupStatus setupDevice(Device *device) override; DeviceManager::DeviceError discoverDevices(const DeviceClassId &deviceClassId, const ParamList ¶ms) override; private slots: void onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry); void onServiceEntryRemoved(const ZeroConfServiceEntry &serviceEntry); + +private: + ZeroConfServiceBrowser *m_serviceBrowser = nullptr;; }; #endif // DEVICEPLUGINAVAHIMONITOR_H diff --git a/kodi/devicepluginkodi.cpp b/kodi/devicepluginkodi.cpp index cf41811b..49d85141 100644 --- a/kodi/devicepluginkodi.cpp +++ b/kodi/devicepluginkodi.cpp @@ -65,6 +65,7 @@ #include "plugin/device.h" #include "plugininfo.h" #include "network/upnp/upnpdiscovery.h" +#include "platform/platformzeroconfcontroller.h" #include "network/zeroconf/zeroconfservicebrowser.h" #include "network/zeroconf/zeroconfserviceentry.h" #include "network/networkaccessmanager.h" @@ -183,9 +184,10 @@ DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId Q_UNUSED(params) Q_UNUSED(deviceClassId) - QList descriptors; - foreach (const ZeroConfServiceEntry &avahiEntry, hardwareManager()->zeroConfServiceBrowser()->serviceEntries()) { - if (avahiEntry.serviceType() == "_xbmc-jsonrpc._tcp") { + ZeroConfServiceBrowser *serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser("_xbmc-jsonrpc._tcp"); + QTimer::singleShot(5000, this, [this, serviceBrowser](){ + QList descriptors; + foreach (const ZeroConfServiceEntry avahiEntry, serviceBrowser->serviceEntries()) { qCDebug(dcKodi) << "Zeroconf entry:" << avahiEntry; DeviceDescriptor descriptor(kodiDeviceClassId, avahiEntry.name(), avahiEntry.hostName() + " (" + avahiEntry.hostAddress().toString() + ")"); ParamList params; @@ -194,10 +196,9 @@ DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId descriptor.setParams(params); descriptors << descriptor; } - } - if (!descriptors.isEmpty()) { emit devicesDiscovered(kodiDeviceClassId, descriptors); - } + serviceBrowser->deleteLater(); + }); return DeviceManager::DeviceErrorAsync; }