added networkmanager in libguh and devicemanager
This commit is contained in:
parent
d991507f3e
commit
dcd4ff8c9d
2
guh.pri
2
guh.pri
@ -2,6 +2,8 @@
|
|||||||
GUH_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"')
|
GUH_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"')
|
||||||
DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\"
|
DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\"
|
||||||
|
|
||||||
|
QT+= network
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -Werror
|
QMAKE_CXXFLAGS += -Werror
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
|
|||||||
@ -184,9 +184,8 @@ DeviceManager::DeviceManager(QObject *parent) :
|
|||||||
m_radio433->enable();
|
m_radio433->enable();
|
||||||
// TODO: error handling if no Radio433 detected (GPIO or network), disable radio433 plugins or something...
|
// TODO: error handling if no Radio433 detected (GPIO or network), disable radio433 plugins or something...
|
||||||
|
|
||||||
m_upnpDiscovery = new UpnpDiscovery(this);
|
m_networkManager = new NetworkManager(this);
|
||||||
connect(m_upnpDiscovery, &UpnpDiscovery::discoveryFinished, this, &DeviceManager::upnpDiscoveryFinished);
|
connect(m_networkManager, &NetworkManager::replyReady, this, &DeviceManager::replyReady);
|
||||||
connect(m_upnpDiscovery, &UpnpDiscovery::upnpNotify, this, &DeviceManager::upnpNotifyReceived);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Destructor of the DeviceManager. Each loaded \l{DevicePlugin} will be deleted. */
|
/*! Destructor of the DeviceManager. Each loaded \l{DevicePlugin} will be deleted. */
|
||||||
@ -935,22 +934,10 @@ void DeviceManager::radio433SignalReceived(QList<int> rawData)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId)
|
void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
|
||||||
{
|
{
|
||||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
Q_UNUSED(pluginId);
|
||||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceUpnpDisovery) && devicePlugin->pluginId() == pluginId) {
|
Q_UNUSED(reply);
|
||||||
devicePlugin->upnpDiscoveryFinished(deviceDescriptorList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeviceManager::upnpNotifyReceived(const QByteArray ¬ifyData)
|
|
||||||
{
|
|
||||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
|
||||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceUpnpDisovery)) {
|
|
||||||
devicePlugin->upnpNotifyReceived(notifyData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::timerEvent()
|
void DeviceManager::timerEvent()
|
||||||
|
|||||||
@ -27,8 +27,7 @@
|
|||||||
#include "types/action.h"
|
#include "types/action.h"
|
||||||
#include "types/vendor.h"
|
#include "types/vendor.h"
|
||||||
|
|
||||||
#include "network/upnpdiscovery/upnpdiscovery.h"
|
#include "network/networkmanager.h"
|
||||||
#include "network/upnpdiscovery/upnpdevicedescriptor.h"
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@ -48,7 +47,7 @@ public:
|
|||||||
HardwareResourceRadio433 = 0x01,
|
HardwareResourceRadio433 = 0x01,
|
||||||
HardwareResourceRadio868 = 0x02,
|
HardwareResourceRadio868 = 0x02,
|
||||||
HardwareResourceTimer = 0x04,
|
HardwareResourceTimer = 0x04,
|
||||||
HardwareResourceUpnpDisovery = 0x08
|
HardwareResourceNetworkManager = 0x08
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(HardwareResources, HardwareResource)
|
Q_DECLARE_FLAGS(HardwareResources, HardwareResource)
|
||||||
|
|
||||||
@ -131,8 +130,7 @@ private slots:
|
|||||||
void slotDeviceStateValueChanged(const QUuid &stateTypeId, const QVariant &value);
|
void slotDeviceStateValueChanged(const QUuid &stateTypeId, const QVariant &value);
|
||||||
|
|
||||||
void radio433SignalReceived(QList<int> rawData);
|
void radio433SignalReceived(QList<int> rawData);
|
||||||
void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &deviceDescriptorList, const PluginId &pluginId);
|
void replyReady(const PluginId &pluginId, QNetworkReply *reply);
|
||||||
void upnpNotifyReceived(const QByteArray ¬ifyData);
|
|
||||||
void timerEvent();
|
void timerEvent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -159,7 +157,7 @@ private:
|
|||||||
Radio433* m_radio433;
|
Radio433* m_radio433;
|
||||||
QTimer m_pluginTimer;
|
QTimer m_pluginTimer;
|
||||||
QList<Device*> m_pluginTimerUsers;
|
QList<Device*> m_pluginTimerUsers;
|
||||||
UpnpDiscovery* m_upnpDiscovery;
|
NetworkManager *m_networkManager;
|
||||||
|
|
||||||
QHash<QUuid, QPair<DeviceClassId, ParamList> > m_pairingsJustAdd;
|
QHash<QUuid, QPair<DeviceClassId, ParamList> > m_pairingsJustAdd;
|
||||||
QHash<QUuid, QPair<DeviceClassId, DeviceDescriptorId> > m_pairingsDiscovery;
|
QHash<QUuid, QPair<DeviceClassId, DeviceDescriptorId> > m_pairingsDiscovery;
|
||||||
|
|||||||
@ -35,6 +35,7 @@ SOURCES += plugin/device.cpp \
|
|||||||
types/param.cpp \
|
types/param.cpp \
|
||||||
types/paramdescriptor.cpp \
|
types/paramdescriptor.cpp \
|
||||||
types/statedescriptor.cpp \
|
types/statedescriptor.cpp \
|
||||||
|
network/networkmanager.cpp \
|
||||||
|
|
||||||
HEADERS += plugin/device.h \
|
HEADERS += plugin/device.h \
|
||||||
plugin/deviceclass.h \
|
plugin/deviceclass.h \
|
||||||
@ -65,3 +66,5 @@ HEADERS += plugin/device.h \
|
|||||||
types/paramdescriptor.h \
|
types/paramdescriptor.h \
|
||||||
types/statedescriptor.h \
|
types/statedescriptor.h \
|
||||||
typeutils.h \
|
typeutils.h \
|
||||||
|
network/networkmanager.h \
|
||||||
|
|
||||||
|
|||||||
59
libguh/network/networkmanager.cpp
Normal file
59
libguh/network/networkmanager.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
57
libguh/network/networkmanager.h
Normal file
57
libguh/network/networkmanager.h
Normal file
@ -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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#ifndef NETWORKMANAGER_H
|
||||||
|
#define NETWORKMANAGER_H
|
||||||
|
|
||||||
|
#include "typeutils.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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<QNetworkReply *, PluginId> m_replys;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void replyReady(const PluginId &pluginId, QNetworkReply *reply);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void replyFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NETWORKMANAGER_H
|
||||||
@ -512,10 +512,7 @@ bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
|||||||
{
|
{
|
||||||
switch (requiredHardware()) {
|
switch (requiredHardware()) {
|
||||||
case DeviceManager::HardwareResourceRadio433:
|
case DeviceManager::HardwareResourceRadio433:
|
||||||
return deviceManager()->m_radio433->sendData(delay, rawData, repetitions);
|
return deviceManager()->m_radio433->sendData(delay, rawData);
|
||||||
case DeviceManager::HardwareResourceRadio868:
|
|
||||||
qDebug() << "Radio868 not connected yet";
|
|
||||||
return false;
|
|
||||||
default:
|
default:
|
||||||
qWarning() << "Unknown harware type. Cannot send.";
|
qWarning() << "Unknown harware type. Cannot send.";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user