mirror of https://github.com/nymea/nymea.git
prepared networkmanager for plugins
parent
dcd4ff8c9d
commit
88a8e9dff6
|
|
@ -936,8 +936,11 @@ void DeviceManager::radio433SignalReceived(QList<int> rawData)
|
|||
|
||||
void DeviceManager::replyReady(const PluginId &pluginId, QNetworkReply *reply)
|
||||
{
|
||||
Q_UNUSED(pluginId);
|
||||
Q_UNUSED(reply);
|
||||
foreach (DevicePlugin *devicePlugin, m_devicePlugins) {
|
||||
if (devicePlugin->requiredHardware().testFlag(HardwareResourceNetworkManager) && devicePlugin->pluginId() == pluginId) {
|
||||
devicePlugin->replyReady(reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::timerEvent()
|
||||
|
|
|
|||
|
|
@ -419,18 +419,18 @@ DeviceManager::DeviceError DevicePlugin::setConfigValue(const QString ¶mName
|
|||
if (paramType.name() == paramName) {
|
||||
if (!value.canConvert(paramType.type())) {
|
||||
qWarning() << QString("Wrong parameter type for param %1. Got %2. Expected %3.")
|
||||
.arg(paramName).arg(value.toString()).arg(QVariant::typeToName(paramType.type()));
|
||||
.arg(paramName).arg(value.toString()).arg(QVariant::typeToName(paramType.type()));
|
||||
return DeviceManager::DeviceErrorInvalidParameter;
|
||||
}
|
||||
|
||||
if (paramType.maxValue().isValid() && value > paramType.maxValue()) {
|
||||
qWarning() << QString("Value out of range for param %1. Got %2. Max: %3.")
|
||||
.arg(paramName).arg(value.toString()).arg(paramType.maxValue().toString());
|
||||
.arg(paramName).arg(value.toString()).arg(paramType.maxValue().toString());
|
||||
return DeviceManager::DeviceErrorInvalidParameter;
|
||||
}
|
||||
if (paramType.minValue().isValid() && value < paramType.minValue()) {
|
||||
qWarning() << QString("Value out of range for param %1. Got: %2. Min: %3.")
|
||||
.arg(paramName).arg(value.toString()).arg(paramType.minValue().toString());
|
||||
.arg(paramName).arg(value.toString()).arg(paramType.minValue().toString());
|
||||
return DeviceManager::DeviceErrorInvalidParameter;
|
||||
}
|
||||
found = true;
|
||||
|
|
@ -519,16 +519,43 @@ bool DevicePlugin::transmitData(int delay, QList<int> rawData, int repetitions)
|
|||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
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)
|
||||
QNetworkReply *DevicePlugin::get(const QNetworkRequest &request)
|
||||
{
|
||||
if(requiredHardware().testFlag(DeviceManager::HardwareResourceUpnpDisovery)){
|
||||
deviceManager()->m_upnpDiscovery->discoverDevices(searchTarget, userAgent, pluginId());
|
||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
||||
return deviceManager()->m_networkManager->get(pluginId(), request);
|
||||
} else {
|
||||
qWarning() << "ERROR: network manager resource missing for plugin " << pluginName();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QNetworkReply *DevicePlugin::post(const QNetworkRequest &request, const QByteArray &data)
|
||||
{
|
||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
||||
return deviceManager()->m_networkManager->post(pluginId(), request, data);
|
||||
} else {
|
||||
qWarning() << "ERROR: network manager resource missing for plugin " << pluginName();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QNetworkReply *DevicePlugin::put(const QNetworkRequest &request, const QByteArray &data)
|
||||
{
|
||||
if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) {
|
||||
return deviceManager()->m_networkManager->put(pluginId(), request, data);
|
||||
} else {
|
||||
qWarning() << "ERROR: network manager resource missing for plugin " << pluginName();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QStringList DevicePlugin::verifyFields(const QStringList &fields, const QJsonObject &value) const
|
||||
{
|
||||
QStringList ret;
|
||||
foreach (const QString &field, fields) {
|
||||
if (!value.contains(field)) {
|
||||
ret << field;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ public:
|
|||
virtual void upnpDiscoveryFinished(const QList<UpnpDeviceDescriptor> &upnpDeviceDescriptorList) {Q_UNUSED(upnpDeviceDescriptorList)}
|
||||
virtual void upnpNotifyReceived(const QByteArray ¬ifyData) {Q_UNUSED(notifyData)}
|
||||
|
||||
virtual void replyReady(QNetworkReply *reply) {Q_UNUSED(reply)}
|
||||
|
||||
// Configuration
|
||||
virtual QList<ParamType> configurationDescription() const;
|
||||
DeviceManager::DeviceError setConfiguration(const ParamList &configuration);
|
||||
|
|
@ -91,8 +93,13 @@ protected:
|
|||
QList<Device*> myDevices() const;
|
||||
Device* findDeviceByParams(const ParamList ¶ms) const;
|
||||
|
||||
// Radio 433
|
||||
bool transmitData(int delay, QList<int> rawData);
|
||||
void upnpDiscover(QString searchTarget = "ssdp:all", QString userAgent = QString());
|
||||
|
||||
// Network manager
|
||||
QNetworkReply *get(const QNetworkRequest &request);
|
||||
QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data);
|
||||
QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
|
||||
|
||||
private:
|
||||
void initPlugin(const QJsonObject &metaData, DeviceManager *deviceManager);
|
||||
|
|
|
|||
Loading…
Reference in New Issue