diff --git a/libguh/bluetooth/bluetoothlowenergymanager.cpp b/libguh/bluetooth/bluetoothlowenergymanager.cpp index 4453baa3..ba44a845 100644 --- a/libguh/bluetooth/bluetoothlowenergymanager.cpp +++ b/libguh/bluetooth/bluetoothlowenergymanager.cpp @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "bluetoothlowenergymanager.h" #include "loggingcategories.h" diff --git a/libguh/bluetooth/bluetoothlowenergymanager.h b/libguh/bluetooth/bluetoothlowenergymanager.h index 3309e98c..75838f02 100644 --- a/libguh/bluetooth/bluetoothlowenergymanager.h +++ b/libguh/bluetooth/bluetoothlowenergymanager.h @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef BLUETOOTHLOWENERGYMANAGER_H #define BLUETOOTHLOWENERGYMANAGER_H diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 5dc4edca..ce86a5ec 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -206,15 +206,12 @@ DeviceManager::DeviceManager(const QLocale &locale, QObject *parent) : qRegisterMetaType(); 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 rawData) -//{ -// QList 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 &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 ¬ifyData) -//{ -// foreach (DevicePlugin *devicePlugin, m_devicePlugins) { -// if (devicePlugin->requiredHardware().testFlag(HardwareResource::TypeUpnpDisovery)) { -// devicePlugin->upnpNotifyReceived(notifyData); -// } -// } -//} - -//void DeviceManager::bluetoothDiscoveryFinished(const PluginId &pluginId, const QList &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; diff --git a/libguh/devicemanager.h b/libguh/devicemanager.h index faab60c9..98f8e2df 100644 --- a/libguh/devicemanager.h +++ b/libguh/devicemanager.h @@ -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 rawData); -// void replyReady(const PluginId &pluginId, QNetworkReply *reply); -// void upnpDiscoveryFinished(const QList &deviceDescriptorList, const PluginId &pluginId); -// void upnpNotifyReceived(const QByteArray ¬ifyData); -// void bluetoothDiscoveryFinished(const PluginId &pluginId, const QList &deviceInfos); - - void timerEvent(); - private: bool verifyPluginMetadata(const QJsonObject &data); DeviceError addConfiguredDeviceInternal(const DeviceClassId &deviceClassId, const QString &name, const ParamList ¶ms, const DeviceId id = DeviceId::createDeviceId()); diff --git a/libguh/guhsettings.h b/libguh/guhsettings.h index e55b5f99..9e035e20 100644 --- a/libguh/guhsettings.h +++ b/libguh/guhsettings.h @@ -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; diff --git a/libguh/hardware/gpio.h b/libguh/hardware/gpio.h index 421bb27d..25c6f127 100644 --- a/libguh/hardware/gpio.h +++ b/libguh/hardware/gpio.h @@ -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; diff --git a/libguh/hardware/gpiomonitor.h b/libguh/hardware/gpiomonitor.h index 9980716d..526ecf2b 100644 --- a/libguh/hardware/gpiomonitor.h +++ b/libguh/hardware/gpiomonitor.h @@ -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(); diff --git a/libguh/hardware/pwm.h b/libguh/hardware/pwm.h index d4a8f59f..d3a5431d 100644 --- a/libguh/hardware/pwm.h +++ b/libguh/hardware/pwm.h @@ -67,7 +67,7 @@ public: PolarityInvalid }; - explicit Pwm(int chipNumber, QObject *parent = 0); + explicit Pwm(int chipNumber, QObject *parent = nullptr); ~Pwm(); static bool isAvailable(); diff --git a/libguh/hardware/radio433/radio433.h b/libguh/hardware/radio433/radio433.h index 39481528..a520e193 100644 --- a/libguh/hardware/radio433/radio433.h +++ b/libguh/hardware/radio433/radio433.h @@ -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: diff --git a/libguh/hardware/radio433/radio433brennenstuhlgateway.h b/libguh/hardware/radio433/radio433brennenstuhlgateway.h index 8c50aeca..79f5d370 100644 --- a/libguh/hardware/radio433/radio433brennenstuhlgateway.h +++ b/libguh/hardware/radio433/radio433brennenstuhlgateway.h @@ -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 rawData, int repetitions); bool enable(); diff --git a/libguh/hardware/radio433/radio433transmitter.h b/libguh/hardware/radio433/radio433transmitter.h index 7c6a0d9a..199a96d6 100644 --- a/libguh/hardware/radio433/radio433transmitter.h +++ b/libguh/hardware/radio433/radio433transmitter.h @@ -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(); diff --git a/libguh/hardwaremanager.cpp b/libguh/hardwaremanager.cpp index fd9acfeb..a86aed4b 100644 --- a/libguh/hardwaremanager.cpp +++ b/libguh/hardwaremanager.cpp @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "hardwaremanager.h" #include "plugintimer.h" diff --git a/libguh/hardwaremanager.h b/libguh/hardwaremanager.h index 25223960..3d7bdab7 100644 --- a/libguh/hardwaremanager.h +++ b/libguh/hardwaremanager.h @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef HARDWAREMANAGER_H #define HARDWAREMANAGER_H diff --git a/libguh/hardwareresource.h b/libguh/hardwareresource.h index c04d08eb..0bee2df2 100644 --- a/libguh/hardwareresource.h +++ b/libguh/hardwareresource.h @@ -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; diff --git a/libguh/network/avahi/qtavahiclient.h b/libguh/network/avahi/qtavahiclient.h index 05d43e95..ae36b510 100644 --- a/libguh/network/avahi/qtavahiclient.h +++ b/libguh/network/avahi/qtavahiclient.h @@ -43,7 +43,7 @@ public: QtAvahiClientStateConnecting }; - explicit QtAvahiClient(QObject *parent = 0); + explicit QtAvahiClient(QObject *parent = nullptr); ~QtAvahiClient(); QtAvahiClientState state() const; diff --git a/libguh/network/avahi/qtavahiservice.h b/libguh/network/avahi/qtavahiservice.h index cf8e0e04..61f4da16 100644 --- a/libguh/network/avahi/qtavahiservice.h +++ b/libguh/network/avahi/qtavahiservice.h @@ -45,7 +45,7 @@ public: QtAvahiServiceStateFailure = 4 }; - explicit QtAvahiService(QObject *parent = 0); + explicit QtAvahiService(QObject *parent = nullptr); ~QtAvahiService(); quint16 port() const; diff --git a/libguh/network/avahi/qtavahiservicebrowser.h b/libguh/network/avahi/qtavahiservicebrowser.h index 1256db1c..34e2d7c9 100644 --- a/libguh/network/avahi/qtavahiservicebrowser.h +++ b/libguh/network/avahi/qtavahiservicebrowser.h @@ -54,7 +54,7 @@ public slots: bool disable(); private: - explicit QtAvahiServiceBrowser(QObject *parent = 0); + explicit QtAvahiServiceBrowser(QObject *parent = nullptr); ~QtAvahiServiceBrowser(); QtAvahiServiceBrowserPrivate *d_ptr; diff --git a/libguh/network/networkaccessmanager.h b/libguh/network/networkaccessmanager.h index d4b1121e..933a0b7d 100644 --- a/libguh/network/networkaccessmanager.h +++ b/libguh/network/networkaccessmanager.h @@ -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: diff --git a/libguh/network/oauth2.h b/libguh/network/oauth2.h index 757ed706..0a080243 100644 --- a/libguh/network/oauth2.h +++ b/libguh/network/oauth2.h @@ -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); diff --git a/libguh/network/upnp/upnpdevice.h b/libguh/network/upnp/upnpdevice.h index 9be4df07..f9c51765 100644 --- a/libguh/network/upnp/upnpdevice.h +++ b/libguh/network/upnp/upnpdevice.h @@ -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); diff --git a/libguh/network/upnp/upnpdiscovery.cpp b/libguh/network/upnp/upnpdiscovery.cpp index c8ce747d..6ca9f4cd 100644 --- a/libguh/network/upnp/upnpdiscovery.cpp +++ b/libguh/network/upnp/upnpdiscovery.cpp @@ -52,6 +52,7 @@ #include "loggingcategories.h" #include "guhsettings.h" +#include #include #include #include @@ -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 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(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, 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; diff --git a/libguh/network/upnp/upnpdiscovery.h b/libguh/network/upnp/upnpdiscovery.h index 66df5544..591d57ee 100644 --- a/libguh/network/upnp/upnpdiscovery.h +++ b/libguh/network/upnp/upnpdiscovery.h @@ -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 caller = QPointer(), 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 &deviceDescriptorList, const PluginId & pluginId); void upnpNotify(const QByteArray ¬ifyMessage); private slots: diff --git a/libguh/network/upnp/upnpdiscoveryrequest.cpp b/libguh/network/upnp/upnpdiscoveryrequest.cpp index e7c521ff..b271cee7 100644 --- a/libguh/network/upnp/upnpdiscoveryrequest.cpp +++ b/libguh/network/upnp/upnpdiscoveryrequest.cpp @@ -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 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 UpnpDiscoveryRequest::deviceList() const return m_deviceList; } -PluginId UpnpDiscoveryRequest::pluginId() const +QPointer UpnpDiscoveryRequest::caller() const { - return m_pluginId; + return m_caller; +} + +QString UpnpDiscoveryRequest::callbackMethod() const +{ + return m_callbackMethod; } QString UpnpDiscoveryRequest::searchTarget() const diff --git a/libguh/network/upnp/upnpdiscoveryrequest.h b/libguh/network/upnp/upnpdiscoveryrequest.h index 419663e1..6da909c8 100644 --- a/libguh/network/upnp/upnpdiscoveryrequest.h +++ b/libguh/network/upnp/upnpdiscoveryrequest.h @@ -25,6 +25,7 @@ #include #include +#include #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 caller, const QString &callbackMethod, QString searchTarget, QString userAgent); void discover(); void addDeviceDescriptor(const UpnpDeviceDescriptor &deviceDescriptor); QNetworkRequest createNetworkRequest(UpnpDeviceDescriptor deviveDescriptor); QList deviceList() const; - PluginId pluginId() const; + QPointer caller() const; + QString callbackMethod() const; QString searchTarget() const; QString userAgent() const; private: UpnpDiscovery *m_upnpDiscovery; QTimer *m_timer; - PluginId m_pluginId; + QPointer m_caller; + QString m_callbackMethod; QString m_searchTarget; QString m_userAgent; @@ -60,8 +63,6 @@ private: signals: void discoveryTimeout(); -public slots: - }; #endif // UPNPDISCOVERYREQUEST_H diff --git a/libguh/plugin/device.h b/libguh/plugin/device.h index 8bae8005..2d4a1ab3 100644 --- a/libguh/plugin/device.h +++ b/libguh/plugin/device.h @@ -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); diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index dac15801..1e213021 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -531,23 +531,6 @@ Device *DevicePlugin::findDeviceByParams(const ParamList ¶ms) 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 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; diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index 7b9f5475..a737c36f 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -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 &rawData) {Q_UNUSED(rawData)} - virtual void guhTimer() {} - virtual void upnpDiscoveryFinished(const QList &upnpDeviceDescriptorList) { Q_UNUSED(upnpDeviceDescriptorList) } - virtual void upnpNotifyReceived(const QByteArray ¬ifyData) {Q_UNUSED(notifyData)} - - virtual void networkManagerReplyReady(QNetworkReply *reply) {Q_UNUSED(reply)} - - virtual void bluetoothDiscoveryFinished(const QList &deviceInfos) { Q_UNUSED(deviceInfos) } - - // Configuration QList configurationDescription() const; DeviceManager::DeviceError setConfiguration(const ParamList &configuration); @@ -111,15 +103,6 @@ protected: HardwareManager *hardwareManager() const; Device* findDeviceByParams(const ParamList ¶ms) const; - // Radio 433 - bool transmitData(int delay, QList 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 m_configurationDescription; ParamList m_config; @@ -150,7 +133,6 @@ private: mutable QList m_supportedDevices; - friend class DeviceManager; }; Q_DECLARE_INTERFACE(DevicePlugin, "guru.guh.DevicePlugin") diff --git a/libguh/plugintimer.cpp b/libguh/plugintimer.cpp index 5254a70a..7ea6aa95 100644 --- a/libguh/plugintimer.cpp +++ b/libguh/plugintimer.cpp @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #include "plugintimer.h" #include "loggingcategories.h" diff --git a/libguh/plugintimer.h b/libguh/plugintimer.h index 85877ac2..f5eb582c 100644 --- a/libguh/plugintimer.h +++ b/libguh/plugintimer.h @@ -1,3 +1,25 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * Copyright (C) 2017 Simon Stürz * + * * + * 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 * + * . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + #ifndef PLUGINTIMER_H #define PLUGINTIMER_H @@ -17,6 +39,7 @@ private: int m_intervall = 10000; signals: + // TODO: emit different resolutions void timerEvent(); public slots: diff --git a/libguh/typeutils.h b/libguh/typeutils.h index 8871179d..b361f261 100644 --- a/libguh/typeutils.h +++ b/libguh/typeutils.h @@ -148,7 +148,6 @@ public: StateOperatorOr }; - Types(QObject *parent = 0); }; Q_DECLARE_METATYPE(Types::InputType)