update nullptr and improve upnp discovery

This commit is contained in:
Simon Stürz 2017-11-17 13:34:47 +01:00 committed by Michael Zanetti
parent f02a9fcdd4
commit 89b860a7eb
30 changed files with 193 additions and 188 deletions

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
* *
* This file is part of guh. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "bluetoothlowenergymanager.h"
#include "loggingcategories.h"

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
* *
* This file is part of guh. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef BLUETOOTHLOWENERGYMANAGER_H
#define BLUETOOTHLOWENERGYMANAGER_H

View File

@ -206,15 +206,12 @@ DeviceManager::DeviceManager(const QLocale &locale, QObject *parent) :
qRegisterMetaType<DeviceDescriptor>();
m_hardwareManager = new HardwareManager(this);
connect(m_hardwareManager->pluginTimer(), &PluginTimer::timerEvent, this, &DeviceManager::timerEvent);
// connect(m_hardwareManager->upnpDiscovery(), &UpnpDiscovery::discoveryFinished, this, &DeviceManager::upnpDiscoveryFinished);
// connect(m_hardwareManager->upnpDiscovery(), &UpnpDiscovery::upnpNotify, this, &DeviceManager::upnpNotifyReceived);
// connect(m_hardwareManager->bluetoothScanner(), &BluetoothScanner::bluetoothDiscoveryFinished, this, &DeviceManager::bluetoothDiscoveryFinished);
// Give hardware a chance to start up before loading plugins etc.
QMetaObject::invokeMethod(this, "loadPlugins", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "loadConfiguredDevices", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "startMonitoringAutoDevices", Qt::QueuedConnection);
// Make sure this is always emitted after plugins and devices are loaded
QMetaObject::invokeMethod(this, "onLoaded", Qt::QueuedConnection);
}
@ -1430,73 +1427,6 @@ void DeviceManager::slotDeviceStateValueChanged(const QUuid &stateTypeId, const
emit eventTriggered(event);
}
//void DeviceManager::radio433SignalReceived(QList<int> rawData)
//{
// QList<DevicePlugin*> targetPlugins;
// foreach (Device *device, m_configuredDevices) {
// DeviceClass deviceClass = m_supportedDevices.value(device->deviceClassId());
// DevicePlugin *plugin = m_devicePlugins.value(deviceClass.pluginId());
// if (plugin->requiredHardware().testFlag(HardwareResource::TypeRadio433) && !targetPlugins.contains(plugin)) {
// targetPlugins.append(plugin);
// }
// }
// foreach (DevicePlugin *plugin, m_discoveringPlugins) {
// if (plugin->requiredHardware().testFlag(HardwareResource::TypeRadio433) && !targetPlugins.contains(plugin)) {
// targetPlugins.append(plugin);
// }
// }
// foreach (DevicePlugin *plugin, targetPlugins) {
// plugin->radioData(rawData);
// }
//}
//void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
//{
// foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
// if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeNetworkManager) && devicePlugin->pluginId() == pluginId) {
// devicePlugin->networkManagerReplyReady(reply);
// }
// }
//}
//void DeviceManager::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId)
//{
// foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
// if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery) && devicePlugin->pluginId() == pluginId) {
// devicePlugin->upnpDiscoveryFinished(deviceDescriptorList);
// }
// }
//}
//void DeviceManager::upnpNotifyReceived(const QByteArray &notifyData)
//{
// foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
// if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery)) {
// devicePlugin->upnpNotifyReceived(notifyData);
// }
// }
//}
//void DeviceManager::bluetoothDiscoveryFinished(const PluginId &pluginId, const QList<QBluetoothDeviceInfo> &deviceInfos)
//{
// foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
// if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeBluetoothLE) && devicePlugin->pluginId() == pluginId) {
// devicePlugin->bluetoothDiscoveryFinished(deviceInfos);
// }
// }
//}
void DeviceManager::timerEvent()
{
foreach (DevicePlugin *plugin, m_pluginTimerUsers) {
if (plugin->requiredHardware().testFlag(HardwareResource::TypeTimer)) {
plugin->guhTimer();
}
}
}
bool DeviceManager::verifyPluginMetadata(const QJsonObject &data)
{
QStringList requiredFields;

View File

@ -89,7 +89,7 @@ public:
};
Q_ENUM(DeviceSetupStatus)
explicit DeviceManager(const QLocale &locale, QObject *parent = 0);
explicit DeviceManager(const QLocale &locale, QObject *parent = nullptr);
~DeviceManager();
static QStringList pluginSearchDirs();
@ -167,14 +167,6 @@ private slots:
// Only connect this to Devices. It will query the sender()
void slotDeviceStateValueChanged(const QUuid &stateTypeId, const QVariant &value);
// void radio433SignalReceived(QList<int> rawData);
// void replyReady(const PluginId &pluginId, QNetworkReply *reply);
// void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId);
// void upnpNotifyReceived(const QByteArray &notifyData);
// void bluetoothDiscoveryFinished(const PluginId &pluginId, const QList<QBluetoothDeviceInfo> &deviceInfos);
void timerEvent();
private:
bool verifyPluginMetadata(const QJsonObject &data);
DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QString &name, const ParamList &params, const DeviceId id = DeviceId::createDeviceId());

View File

@ -43,7 +43,7 @@ public:
SettingsRoleDeviceStates
};
explicit GuhSettings(const SettingsRole &role = SettingsRoleNone, QObject *parent = 0);
explicit GuhSettings(const SettingsRole &role = SettingsRoleNone, QObject *parent = nullptr);
~GuhSettings();
SettingsRole settingsRole() const;

View File

@ -54,7 +54,7 @@ public:
EdgeNone
};
explicit Gpio(const int &gpio, QObject *parent = 0);
explicit Gpio(const int &gpio, QObject *parent = nullptr);
~Gpio();
QString gpioDirectory() const;

View File

@ -36,7 +36,7 @@ class LIBGUH_EXPORT GpioMonitor : public QObject
Q_OBJECT
public:
explicit GpioMonitor(int gpio, QObject *parent = 0);
explicit GpioMonitor(int gpio, QObject *parent = nullptr);
bool enable(bool activeLow = false, Gpio::Edge edgeInterrupt = Gpio::EdgeBoth);
void disable();

View File

@ -67,7 +67,7 @@ public:
PolarityInvalid
};
explicit Pwm(int chipNumber, QObject *parent = 0);
explicit Pwm(int chipNumber, QObject *parent = nullptr);
~Pwm();
static bool isAvailable();

View File

@ -36,7 +36,7 @@ class LIBGUH_EXPORT Radio433 : public HardwareResource
friend class HardwareManager;
private:
explicit Radio433(QObject *parent = 0);
explicit Radio433(QObject *parent = nullptr);
Radio433BrennenstuhlGateway *m_brennenstuhlTransmitter;
private slots:

View File

@ -34,7 +34,7 @@ class LIBGUH_EXPORT Radio433BrennenstuhlGateway : public QObject
{
Q_OBJECT
public:
explicit Radio433BrennenstuhlGateway(QObject *parent = 0);
explicit Radio433BrennenstuhlGateway(QObject *parent = nullptr);
bool sendData(int delay, QList<int> rawData, int repetitions);
bool enable();

View File

@ -37,7 +37,7 @@ class LIBGUH_EXPORT Radio433Trasmitter : public QThread
{
Q_OBJECT
public:
explicit Radio433Trasmitter(QObject *parent = 0, int gpio = 22);
explicit Radio433Trasmitter(QObject *parent = nullptr, int gpio = 22);
~Radio433Trasmitter();
bool startTransmitter();

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
* *
* This file is part of guh. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "hardwaremanager.h"
#include "plugintimer.h"

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
* *
* This file is part of guh. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef HARDWAREMANAGER_H
#define HARDWAREMANAGER_H

View File

@ -50,10 +50,10 @@ public:
bool available() const;
bool enabled() const;
private:
HardwareResource::Type m_hardwareReourceType;
QString m_name;
// Note: default enabled, but not available. Each hardwareresource has explicitly chek if available
bool m_available = false;
bool m_enabled = true;

View File

@ -43,7 +43,7 @@ public:
QtAvahiClientStateConnecting
};
explicit QtAvahiClient(QObject *parent = 0);
explicit QtAvahiClient(QObject *parent = nullptr);
~QtAvahiClient();
QtAvahiClientState state() const;

View File

@ -45,7 +45,7 @@ public:
QtAvahiServiceStateFailure = 4
};
explicit QtAvahiService(QObject *parent = 0);
explicit QtAvahiService(QObject *parent = nullptr);
~QtAvahiService();
quint16 port() const;

View File

@ -54,7 +54,7 @@ public slots:
bool disable();
private:
explicit QtAvahiServiceBrowser(QObject *parent = 0);
explicit QtAvahiServiceBrowser(QObject *parent = nullptr);
~QtAvahiServiceBrowser();
QtAvahiServiceBrowserPrivate *d_ptr;

View File

@ -58,7 +58,7 @@ public:
private:
// Note: only the HardwareManager is allowed to create this resource
NetworkAccessManager(QNetworkAccessManager *networkManager, QObject *parent = 0);
NetworkAccessManager(QNetworkAccessManager *networkManager, QObject *parent = nullptr);
QNetworkAccessManager *m_manager;
public slots:

View File

@ -39,7 +39,7 @@ class LIBGUH_EXPORT OAuth2 : public QObject
{
Q_OBJECT
public:
explicit OAuth2(QString clientId, QString clientSecret, QObject *parent = 0);
explicit OAuth2(QString clientId, QString clientSecret, QObject *parent = nullptr);
QUrl url() const;
void setUrl(const QUrl &url);

View File

@ -32,7 +32,7 @@ class LIBGUH_EXPORT UpnpDevice : public QObject
{
Q_OBJECT
public:
explicit UpnpDevice(QObject *parent = 0, UpnpDeviceDescriptor upnpDeviceDescriptor = UpnpDeviceDescriptor());
explicit UpnpDevice(QObject *parent = nullptr, UpnpDeviceDescriptor upnpDeviceDescriptor = UpnpDeviceDescriptor());
QUrl location();
void setLocation(const QUrl &location);

View File

@ -52,6 +52,7 @@
#include "loggingcategories.h"
#include "guhsettings.h"
#include <QMetaObject>
#include <QNetworkInterface>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
@ -81,7 +82,7 @@ UpnpDiscovery::~UpnpDiscovery()
/*! Returns false, if the \l{UpnpDiscovery} resource is not available. Returns true, if a device with
* the given \a searchTarget, \a userAgent and \a pluginId can be discovered.*/
bool UpnpDiscovery::discoverDevices(const QString &searchTarget, const QString &userAgent, const PluginId &pluginId)
bool UpnpDiscovery::discoverDevices(QPointer<QObject> caller, const QString &callbackMethod, const QString &searchTarget, const QString &userAgent)
{
if (!available()) {
qCWarning(dcHardware()) << name() << "not available.";
@ -103,10 +104,10 @@ bool UpnpDiscovery::discoverDevices(const QString &searchTarget, const QString &
qCDebug(dcHardware) << name() << "discover" << searchTarget << userAgent;
// create a new request
UpnpDiscoveryRequest *request = new UpnpDiscoveryRequest(this, pluginId, searchTarget, userAgent);
connect(request, &UpnpDiscoveryRequest::discoveryTimeout, this, &UpnpDiscovery::discoverTimeout);
// Create a new request
UpnpDiscoveryRequest *request = new UpnpDiscoveryRequest(this, caller, callbackMethod, searchTarget, userAgent);
connect(request, &UpnpDiscoveryRequest::discoveryTimeout, this, &UpnpDiscovery::discoverTimeout);
request->discover();
m_discoverRequests.append(request);
return true;
@ -419,7 +420,14 @@ void UpnpDiscovery::sendAliveMessage()
void UpnpDiscovery::discoverTimeout()
{
UpnpDiscoveryRequest *discoveryRequest = static_cast<UpnpDiscoveryRequest*>(sender());
emit discoveryFinished(discoveryRequest->deviceList(), discoveryRequest->pluginId());
if (discoveryRequest->caller().isNull()) {
qCWarning(dcHardware()) << name() << "The reciver of the discovery request does not exist any more.";
} else {
// Invoke the method containing the discovered devicelist
// FIXME: check the callback method paramters during compililation
QMetaObject::invokeMethod(discoveryRequest->caller().data(), discoveryRequest->callbackMethod().toLatin1().data(), Q_ARG(QList<UpnpDeviceDescriptor>, discoveryRequest->deviceList()));
}
m_discoverRequests.removeOne(discoveryRequest);
delete discoveryRequest;
@ -443,6 +451,7 @@ bool UpnpDiscovery::enable()
if(!m_socket->bind(QHostAddress::AnyIPv4, m_port, QUdpSocket::ShareAddress)){
qCWarning(dcHardware()) << name() << "could not bind to port" << m_port;
setAvailable(false);
delete m_socket;
m_socket = nullptr;
return false;
@ -450,6 +459,7 @@ bool UpnpDiscovery::enable()
if(!m_socket->joinMulticastGroup(m_host)){
qCWarning(dcHardware()) << name() << "could not join multicast group" << m_host;
setAvailable(false);
delete m_socket;
m_socket = nullptr;
return false;

View File

@ -49,11 +49,11 @@ class LIBGUH_EXPORT UpnpDiscovery : public HardwareResource
friend class HardwareManager;
public:
bool discoverDevices(const QString &searchTarget = "ssdp:all", const QString &userAgent = "", const PluginId &pluginId = PluginId());
bool discoverDevices(QPointer<QObject> caller = QPointer<QObject>(), const QString &callbackMethod = QString(), const QString &searchTarget = "ssdp:all", const QString &userAgent = QString());
void sendToMulticast(const QByteArray &data);
private:
explicit UpnpDiscovery(QNetworkAccessManager *networkAccessManager, QObject *parent = 0);
explicit UpnpDiscovery(QNetworkAccessManager *networkAccessManager, QObject *parent = nullptr);
~UpnpDiscovery();
QUdpSocket *m_socket = nullptr;
@ -71,7 +71,6 @@ private:
void respondToSearchRequest(QHostAddress host, int port);
signals:
void discoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId & pluginId);
void upnpNotify(const QByteArray &notifyMessage);
private slots:

View File

@ -23,10 +23,11 @@
#include "upnpdiscoveryrequest.h"
#include "loggingcategories.h"
UpnpDiscoveryRequest::UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, PluginId pluginId, QString searchTarget, QString userAgent):
UpnpDiscoveryRequest::UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, QPointer<QObject> caller, const QString &callbackMethod, QString searchTarget, QString userAgent):
QObject(upnpDiscovery),
m_upnpDiscovery(upnpDiscovery),
m_pluginId(pluginId),
m_caller(caller),
m_callbackMethod(callbackMethod),
m_searchTarget(searchTarget),
m_userAgent(userAgent)
{
@ -45,6 +46,9 @@ void UpnpDiscoveryRequest::discover()
"USR-AGENT: " + m_userAgent.toUtf8() + "\r\n\r\n");
m_upnpDiscovery->sendToMulticast(ssdpSearchMessage);
// TODO: call in 500ms steps
qCDebug(dcHardware) << "--> UPnP discovery called.";
m_timer->start(5000);
@ -52,7 +56,6 @@ void UpnpDiscoveryRequest::discover()
void UpnpDiscoveryRequest::addDeviceDescriptor(const UpnpDeviceDescriptor &deviceDescriptor)
{
// check if we allready have the device in the list
bool isAlreadyInList = false;
foreach (UpnpDeviceDescriptor upnpDeviceDescriptor, m_deviceList) {
@ -80,9 +83,14 @@ QList<UpnpDeviceDescriptor> UpnpDiscoveryRequest::deviceList() const
return m_deviceList;
}
PluginId UpnpDiscoveryRequest::pluginId() const
QPointer<QObject> UpnpDiscoveryRequest::caller() const
{
return m_pluginId;
return m_caller;
}
QString UpnpDiscoveryRequest::callbackMethod() const
{
return m_callbackMethod;
}
QString UpnpDiscoveryRequest::searchTarget() const

View File

@ -25,6 +25,7 @@
#include <QObject>
#include <QDebug>
#include <QMetaObject>
#include "upnpdiscovery.h"
#include "upnpdevicedescriptor.h"
@ -37,21 +38,23 @@ class LIBGUH_EXPORT UpnpDiscoveryRequest : public QObject
{
Q_OBJECT
public:
explicit UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, PluginId pluginId, QString searchTarget, QString userAgent);
explicit UpnpDiscoveryRequest(UpnpDiscovery *upnpDiscovery, QPointer<QObject> caller, const QString &callbackMethod, QString searchTarget, QString userAgent);
void discover();
void addDeviceDescriptor(const UpnpDeviceDescriptor &deviceDescriptor);
QNetworkRequest createNetworkRequest(UpnpDeviceDescriptor deviveDescriptor);
QList<UpnpDeviceDescriptor> deviceList() const;
PluginId pluginId() const;
QPointer<QObject> caller() const;
QString callbackMethod() const;
QString searchTarget() const;
QString userAgent() const;
private:
UpnpDiscovery *m_upnpDiscovery;
QTimer *m_timer;
PluginId m_pluginId;
QPointer<QObject> m_caller;
QString m_callbackMethod;
QString m_searchTarget;
QString m_userAgent;
@ -60,8 +63,6 @@ private:
signals:
void discoveryTimeout();
public slots:
};
#endif // UPNPDISCOVERYREQUEST_H

View File

@ -75,8 +75,8 @@ signals:
void stateValueChanged(const QUuid &stateTypeId, const QVariant &value);
private:
Device(const PluginId &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent = 0);
Device(const PluginId &pluginId, const DeviceClassId &deviceClassId, QObject *parent = 0);
Device(const PluginId &pluginId, const DeviceId &id, const DeviceClassId &deviceClassId, QObject *parent = nullptr);
Device(const PluginId &pluginId, const DeviceClassId &deviceClassId, QObject *parent = nullptr);
void setupCompleted();
void setSetupComplete(const bool &complete);

View File

@ -531,23 +531,6 @@ Device *DevicePlugin::findDeviceByParams(const ParamList &params) const
return nullptr;
}
/*!
Transmits data contained in \a rawData on the \l{Radio433} devices, depending on the hardware requested by this plugin.
Returns true if, the \a rawData with a certain \a delay (pulse length) can be sent \a repetitions times.
\sa Radio433, requiredHardware()
*/
bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
{
switch (requiredHardware()) {
case HardwareResource::TypeRadio433:
return deviceManager()->m_hardwareManager->radio433()->sendData(delay, rawData, repetitions);
default:
qCWarning(dcDeviceManager) << "Unknown harware type. Cannot send.";
}
return false;
}
void DevicePlugin::setMetaData(const QJsonObject &metaData)
{
m_metaData = metaData;
@ -962,38 +945,6 @@ void DevicePlugin::loadMetaData()
}
}
/*!
Starts a SSDP search for a certain \a searchTarget (ST). Certain UPnP devices need a special ST (i.e. "udap:rootservice"
for LG Smart Tv's), otherwise they will not respond on the SSDP search. Each HTTP request to this device needs sometimes
also a special \a userAgent, which will be written into the HTTP header.
\sa DevicePlugin::requiredHardware(), DevicePlugin::upnpDiscoveryFinished()
*/
void DevicePlugin::upnpDiscover(QString searchTarget, QString userAgent)
{
if(requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery)){
deviceManager()->m_hardwareManager->upnpDiscovery()->discoverDevices(searchTarget, userAgent, pluginId());
} else {
qCWarning(dcDeviceManager) << "UPnP discovery resource not set for plugin" << pluginName();
}
}
/*! Returns the pointer to the central \l{QtAvahiService}{service} browser. */
QtAvahiServiceBrowser *DevicePlugin::avahiServiceBrowser() const
{
return deviceManager()->m_hardwareManager->avahiBrowser();
}
bool DevicePlugin::discoverBluetooth()
{
if(requiredHardware().testFlag(HardwareResource::TypeBluetoothLE)){
return deviceManager()->m_hardwareManager->bluetoothScanner()->discover(pluginId());
} else {
qCWarning(dcDeviceManager) << "Bluetooth LE resource not set for plugin" << pluginName();
}
return false;
}
QStringList DevicePlugin::verifyFields(const QStringList &fields, const QJsonObject &value) const
{
QStringList ret;

View File

@ -49,8 +49,11 @@ class Device;
class LIBGUH_EXPORT DevicePlugin: public QObject
{
Q_OBJECT
friend class DeviceManager;
public:
DevicePlugin(QObject *parent = 0);
DevicePlugin(QObject *parent = nullptr);
virtual ~DevicePlugin();
virtual void init() {}
@ -77,17 +80,6 @@ public:
virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action);
// Hardware input
virtual void radioData(const QList<int> &rawData) {Q_UNUSED(rawData)}
virtual void guhTimer() {}
virtual void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &upnpDeviceDescriptorList) { Q_UNUSED(upnpDeviceDescriptorList) }
virtual void upnpNotifyReceived(const QByteArray &notifyData) {Q_UNUSED(notifyData)}
virtual void networkManagerReplyReady(QNetworkReply *reply) {Q_UNUSED(reply)}
virtual void bluetoothDiscoveryFinished(const QList<QBluetoothDeviceInfo> &deviceInfos) { Q_UNUSED(deviceInfos) }
// Configuration
QList<ParamType> configurationDescription() const;
DeviceManager::DeviceError setConfiguration(const ParamList &configuration);
@ -111,15 +103,6 @@ protected:
HardwareManager *hardwareManager() const;
Device* findDeviceByParams(const ParamList &params) const;
// Radio 433
bool transmitData(int delay, QList<int> rawData);
// Avahi browse services
QtAvahiServiceBrowser *avahiServiceBrowser() const;
// Bluetooth LE discovery
bool discoverBluetooth();
private:
void setMetaData(const QJsonObject &metaData);
void loadMetaData();
@ -140,8 +123,8 @@ private:
static QVariantMap loadInterface(const QString &name);
static QStringList generateInterfaceParentList(const QString &interface);
QTranslator *m_translator;
DeviceManager *m_deviceManager;
QTranslator *m_translator = nullptr;
DeviceManager *m_deviceManager = nullptr;
QList<ParamType> m_configurationDescription;
ParamList m_config;
@ -150,7 +133,6 @@ private:
mutable QList<DeviceClass> m_supportedDevices;
friend class DeviceManager;
};
Q_DECLARE_INTERFACE(DevicePlugin, "guru.guh.DevicePlugin")

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
* *
* This file is part of guh. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "plugintimer.h"
#include "loggingcategories.h"

View File

@ -1,3 +1,25 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Copyright (C) 2017 Simon Stürz <simon.stuerz@guh.io> *
* *
* This file is part of guh. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; If not, see *
* <http://www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef PLUGINTIMER_H
#define PLUGINTIMER_H
@ -17,6 +39,7 @@ private:
int m_intervall = 10000;
signals:
// TODO: emit different resolutions
void timerEvent();
public slots:

View File

@ -148,7 +148,6 @@ public:
StateOperatorOr
};
Types(QObject *parent = 0);
};
Q_DECLARE_METATYPE(Types::InputType)