mirror of https://github.com/nymea/nymea.git
added networkmanager in libguh and devicemanager
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"')
|
||||
DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\"
|
||||
|
||||
QT+= network
|
||||
|
||||
QMAKE_CXXFLAGS += -Werror
|
||||
CONFIG += c++11
|
||||
|
||||
|
|
|
|||
|
|
@ -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<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) {
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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 <QObject>
|
||||
#include <QTimer>
|
||||
|
|
@ -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<int> rawData);
|
||||
void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &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<Device*> m_pluginTimerUsers;
|
||||
UpnpDiscovery* m_upnpDiscovery;
|
||||
NetworkManager *m_networkManager;
|
||||
|
||||
QHash<QUuid, QPair<DeviceClassId, ParamList> > m_pairingsJustAdd;
|
||||
QHash<QUuid, QPair<DeviceClassId, DeviceDescriptorId> > m_pairingsDiscovery;
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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()) {
|
||||
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.";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue