Merge PR #113: Kodi, AvahiMonitor: Update to new ZeroConf API

This commit is contained in:
Jenkins 2019-06-19 23:52:34 +02:00
commit 21e0a52f6e
3 changed files with 28 additions and 23 deletions

View File

@ -44,7 +44,8 @@
#include "plugin/device.h"
#include "devicemanager.h"
#include "plugininfo.h"
#include "network/avahi/qtavahiservicebrowser.h"
#include "platform/platformzeroconfcontroller.h"
#include "network/zeroconf/zeroconfservicebrowser.h"
#include <QDebug>
#include <QStringList>
@ -56,12 +57,6 @@ DevicePluginAvahiMonitor::DevicePluginAvahiMonitor()
}
void DevicePluginAvahiMonitor::init()
{
connect(hardwareManager()->avahiBrowser(), &QtAvahiServiceBrowser::serviceEntryAdded, this, &DevicePluginAvahiMonitor::onServiceEntryAdded);
connect(hardwareManager()->avahiBrowser(), &QtAvahiServiceBrowser::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<DeviceDescriptor> deviceDescriptors;
foreach (const AvahiServiceEntry &service, hardwareManager()->avahiBrowser()->serviceEntries()) {
foreach (const ZeroConfServiceEntry &service, m_serviceBrowser->serviceEntries()) {
DeviceDescriptor deviceDescriptor(avahiDeviceClassId, service.name(), service.hostAddress().toString());
ParamList params;
params.append(Param(avahiDeviceServiceParamTypeId, service.name()));
@ -97,8 +98,9 @@ DeviceManager::DeviceError DevicePluginAvahiMonitor::discoverDevices(const Devic
return DeviceManager::DeviceErrorAsync;
}
void DevicePluginAvahiMonitor::onServiceEntryAdded(const AvahiServiceEntry &serviceEntry)
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);
@ -107,7 +109,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()) {

View File

@ -25,7 +25,8 @@
#define DEVICEPLUGINAVAHIMONITOR_H
#include "plugin/deviceplugin.h"
#include "network/avahi/avahiserviceentry.h"
#include "network/zeroconf/zeroconfservicebrowser.h"
#include "network/zeroconf/zeroconfserviceentry.h"
#include <QProcess>
@ -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 &params) override;
private slots:
void onServiceEntryAdded(const AvahiServiceEntry &serviceEntry);
void onServiceEntryRemoved(const AvahiServiceEntry &serviceEntry);
void onServiceEntryAdded(const ZeroConfServiceEntry &serviceEntry);
void onServiceEntryRemoved(const ZeroConfServiceEntry &serviceEntry);
private:
ZeroConfServiceBrowser *m_serviceBrowser = nullptr;;
};
#endif // DEVICEPLUGINAVAHIMONITOR_H

View File

@ -65,8 +65,9 @@
#include "plugin/device.h"
#include "plugininfo.h"
#include "network/upnp/upnpdiscovery.h"
#include "network/avahi/qtavahiservicebrowser.h"
#include "network/avahi/avahiserviceentry.h"
#include "platform/platformzeroconfcontroller.h"
#include "network/zeroconf/zeroconfservicebrowser.h"
#include "network/zeroconf/zeroconfserviceentry.h"
#include "network/networkaccessmanager.h"
#include <QNetworkRequest>
@ -183,9 +184,10 @@ DeviceManager::DeviceError DevicePluginKodi::discoverDevices(const DeviceClassId
Q_UNUSED(params)
Q_UNUSED(deviceClassId)
QList<DeviceDescriptor> descriptors;
foreach (const AvahiServiceEntry &avahiEntry, hardwareManager()->avahiBrowser()->serviceEntries()) {
if (avahiEntry.serviceType() == "_xbmc-jsonrpc._tcp") {
ZeroConfServiceBrowser *serviceBrowser = hardwareManager()->zeroConfController()->createServiceBrowser("_xbmc-jsonrpc._tcp");
QTimer::singleShot(5000, this, [this, serviceBrowser](){
QList<DeviceDescriptor> 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;
}