diff --git a/guh.pri b/guh.pri index 20989324..9ae65b9d 100644 --- a/guh.pri +++ b/guh.pri @@ -2,6 +2,8 @@ GUH_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"') DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\" +QT+= network + QMAKE_CXXFLAGS += -Werror CONFIG += c++11 diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index b6144e7b..28279bed 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -184,9 +184,8 @@ DeviceManager::DeviceManager(QObject *parent) : m_radio433->enable(); // TODO: error handling if no Radio433 detected (GPIO or network), disable radio433 plugins or something... - m_upnpDiscovery = new UpnpDiscovery(this); - connect(m_upnpDiscovery, &UpnpDiscovery::discoveryFinished, this, &DeviceManager::upnpDiscoveryFinished); - connect(m_upnpDiscovery, &UpnpDiscovery::upnpNotify, this, &DeviceManager::upnpNotifyReceived); + m_networkManager = new NetworkManager(this); + connect(m_networkManager, &NetworkManager::replyReady, this, &DeviceManager::replyReady); } /*! Destructor of the DeviceManager. Each loaded \l{DevicePlugin} will be deleted. */ @@ -935,22 +934,10 @@ void DeviceManager::radio433SignalReceived(QList rawData) } } -void DeviceManager::upnpDiscoveryFinished(const QList &deviceDescriptorList, const PluginId &pluginId) +void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply) { - foreach (DevicePlugin *devicePlugin, m_devicePlugins) { - if (devicePlugin->requiredHardware().testFlag(HardwareResourceUpnpDisovery) && devicePlugin->pluginId() == pluginId) { - devicePlugin->upnpDiscoveryFinished(deviceDescriptorList); - } - } -} - -void DeviceManager::upnpNotifyReceived(const QByteArray ¬ifyData) -{ - foreach (DevicePlugin *devicePlugin, m_devicePlugins) { - if (devicePlugin->requiredHardware().testFlag(HardwareResourceUpnpDisovery)) { - devicePlugin->upnpNotifyReceived(notifyData); - } - } + Q_UNUSED(pluginId); + Q_UNUSED(reply); } void DeviceManager::timerEvent() diff --git a/libguh/devicemanager.h b/libguh/devicemanager.h index 7dc56e1b..8642cac6 100644 --- a/libguh/devicemanager.h +++ b/libguh/devicemanager.h @@ -27,8 +27,7 @@ #include "types/action.h" #include "types/vendor.h" -#include "network/upnpdiscovery/upnpdiscovery.h" -#include "network/upnpdiscovery/upnpdevicedescriptor.h" +#include "network/networkmanager.h" #include #include @@ -48,7 +47,7 @@ public: HardwareResourceRadio433 = 0x01, HardwareResourceRadio868 = 0x02, HardwareResourceTimer = 0x04, - HardwareResourceUpnpDisovery = 0x08 + HardwareResourceNetworkManager = 0x08 }; Q_DECLARE_FLAGS(HardwareResources, HardwareResource) @@ -131,8 +130,7 @@ private slots: void slotDeviceStateValueChanged(const QUuid &stateTypeId, const QVariant &value); void radio433SignalReceived(QList rawData); - void upnpDiscoveryFinished(const QList &deviceDescriptorList, const PluginId &pluginId); - void upnpNotifyReceived(const QByteArray ¬ifyData); + void replyReady(const PluginId &pluginId, QNetworkReply *reply); void timerEvent(); private: @@ -159,7 +157,7 @@ private: Radio433* m_radio433; QTimer m_pluginTimer; QList m_pluginTimerUsers; - UpnpDiscovery* m_upnpDiscovery; + NetworkManager *m_networkManager; QHash > m_pairingsJustAdd; QHash > m_pairingsDiscovery; diff --git a/libguh/libguh.pro b/libguh/libguh.pro index 69e8bd15..1dc3eb62 100644 --- a/libguh/libguh.pro +++ b/libguh/libguh.pro @@ -35,6 +35,7 @@ SOURCES += plugin/device.cpp \ types/param.cpp \ types/paramdescriptor.cpp \ types/statedescriptor.cpp \ + network/networkmanager.cpp \ HEADERS += plugin/device.h \ plugin/deviceclass.h \ @@ -65,3 +66,5 @@ HEADERS += plugin/device.h \ types/paramdescriptor.h \ types/statedescriptor.h \ typeutils.h \ + network/networkmanager.h \ + diff --git a/libguh/network/networkmanager.cpp b/libguh/network/networkmanager.cpp new file mode 100644 index 00000000..08b9a872 --- /dev/null +++ b/libguh/network/networkmanager.cpp @@ -0,0 +1,59 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "networkmanager.h" + +NetworkManager::NetworkManager(QObject *parent) : + QObject(parent) +{ + m_manager = new QNetworkAccessManager(this); + + connect(m_manager, &QNetworkAccessManager::finished, this, &NetworkManager::replyFinished); +} + +QNetworkReply *NetworkManager::get(const PluginId &pluginId, const QNetworkRequest &request) +{ + QNetworkReply *reply = m_manager->get(request); + m_replys.insert(reply, pluginId); + return reply; +} + +QNetworkReply *NetworkManager::post(const PluginId &pluginId, const QNetworkRequest &request, const QByteArray &data) +{ + QNetworkReply *reply = m_manager->post(request, data); + m_replys.insert(reply, pluginId); + return reply; +} + +QNetworkReply *NetworkManager::put(const PluginId &pluginId, const QNetworkRequest &request, const QByteArray &data) +{ + QNetworkReply *reply = m_manager->put(request, data); + m_replys.insert(reply, pluginId); + return reply; +} + +void NetworkManager::replyFinished(QNetworkReply *reply) +{ + if (reply->error()) { + qWarning() << "ERROR: network manager reply error: " << reply->errorString(); + } + + // NOTE: Each plugin has to delete his own replys with deleteLater()!! + PluginId pluginId = m_replys.take(reply); + emit replyReady(pluginId, reply); +} diff --git a/libguh/network/networkmanager.h b/libguh/network/networkmanager.h new file mode 100644 index 00000000..39583e1f --- /dev/null +++ b/libguh/network/networkmanager.h @@ -0,0 +1,57 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * + * This file is part of guh. * + * * + * Guh is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2 of the License. * + * * + * Guh 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with guh. If not, see . * + * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef NETWORKMANAGER_H +#define NETWORKMANAGER_H + +#include "typeutils.h" + +#include +#include +#include +#include +#include +#include + + + +class NetworkManager : public QObject +{ + Q_OBJECT +public: + explicit NetworkManager(QObject *parent = 0); + + QNetworkReply *get(const PluginId &pluginId, const QNetworkRequest &request); + QNetworkReply *post(const PluginId &pluginId, const QNetworkRequest &request, const QByteArray &data); + QNetworkReply *put(const PluginId &pluginId, const QNetworkRequest &request, const QByteArray &data); + +private: + QNetworkAccessManager *m_manager; + QHash m_replys; + +signals: + void replyReady(const PluginId &pluginId, QNetworkReply *reply); + +private slots: + void replyFinished(QNetworkReply *reply); + +public slots: + +}; + +#endif // NETWORKMANAGER_H diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index 90c5cd3d..0653ad3d 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -512,10 +512,7 @@ bool DevicePlugin::transmitData(int delay, QList rawData, int repetitions) { switch (requiredHardware()) { case DeviceManager::HardwareResourceRadio433: - return deviceManager()->m_radio433->sendData(delay, rawData, repetitions); - case DeviceManager::HardwareResourceRadio868: - qDebug() << "Radio868 not connected yet"; - return false; + return deviceManager()->m_radio433->sendData(delay, rawData); default: qWarning() << "Unknown harware type. Cannot send."; }