From 3157298a65fef41ce6854a1da0300b42a0e241d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 11 Jan 2016 18:59:36 +0100 Subject: [PATCH] smal fixes --- guh.pri | 1 + libguh/devicemanager.cpp | 51 ++++++++++++++++++++++------------ libguh/devicemanager.h | 2 +- libguh/libguh.pro | 2 +- libguh/plugin/deviceplugin.cpp | 46 +++++++++++++++--------------- libguh/plugin/deviceplugin.h | 7 ++--- 6 files changed, 62 insertions(+), 47 deletions(-) diff --git a/guh.pri b/guh.pri index 23d81e02..06036779 100644 --- a/guh.pri +++ b/guh.pri @@ -10,6 +10,7 @@ DEFINES += GUH_VERSION_STRING=\\\"$${GUH_VERSION_STRING}\\\" \ REST_API_VERSION=\\\"$${REST_API_VERSION}\\\" QT+= network +CONFIG += c++11 QMAKE_CXXFLAGS += -Werror -std=c++11 QMAKE_LFLAGS += -std=c++11 diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 076b96f1..a9ede65d 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -203,13 +203,6 @@ DeviceManager::DeviceManager(QObject *parent) : m_pluginTimer.setInterval(10000); connect(&m_pluginTimer, &QTimer::timeout, this, &DeviceManager::timerEvent); - // 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, "loaded", Qt::QueuedConnection); - m_radio433 = new Radio433(this); connect(m_radio433, &Radio433::dataReceived, this, &DeviceManager::radio433SignalReceived); m_radio433->enable(); @@ -224,7 +217,7 @@ DeviceManager::DeviceManager(QObject *parent) : connect(m_upnpDiscovery, &UpnpDiscovery::upnpNotify, this, &DeviceManager::upnpNotifyReceived); // Bluetooth LE - #ifdef BLUETOOTH_LE +#ifdef BLUETOOTH_LE m_bluetoothScanner = new BluetoothScanner(this); if (!m_bluetoothScanner->isAvailable()) { delete m_bluetoothScanner; @@ -232,7 +225,14 @@ DeviceManager::DeviceManager(QObject *parent) : } else { connect(m_bluetoothScanner, &BluetoothScanner::bluetoothDiscoveryFinished, this, &DeviceManager::bluetoothDiscoveryFinished); } - #endif +#endif + + // 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, "loaded", Qt::QueuedConnection); } /*! Destructor of the DeviceManager. Each loaded \l{DevicePlugin} will be deleted. */ @@ -905,19 +905,28 @@ void DeviceManager::loadPlugins() if (!fi.exists()) { continue; } - QPluginLoader loader(fi.absoluteFilePath()); + + QPluginLoader loader; + loader.setFileName(fi.absoluteFilePath()); + loader.setLoadHints(QLibrary::ResolveAllSymbolsHint); + + if (!loader.load()) { + qCWarning(dcDeviceManager) << "Could not load plugin data of" << entry; + continue; + } DevicePlugin *pluginIface = qobject_cast(loader.instance()); - if (!pluginIface) - qCWarning(dcDeviceManager) << "Could not load plugin interface of" << entry; + if (!pluginIface) { + qCWarning(dcDeviceManager) << "Could not get plugin instance of" << entry; + continue; + } - if (verifyPluginMetadata(loader.metaData().value("MetaData").toObject()) && pluginIface) { + if (verifyPluginMetadata(loader.metaData().value("MetaData").toObject())) { pluginIface->initPlugin(loader.metaData().value("MetaData").toObject(), this); - qCDebug(dcDeviceManager) << "*** Loaded plugin" << pluginIface->pluginName(); + qCDebug(dcDeviceManager) << "**** Loaded plugin" << pluginIface->pluginName(); foreach (const Vendor &vendor, pluginIface->supportedVendors()) { qCDebug(dcDeviceManager) << "* Loaded vendor:" << vendor.name(); if (m_supportedVendors.contains(vendor.id())) { - //qCWarning(dcDeviceManager) << "! Duplicate vendor. Ignoring vendor" << vendor.name(); continue; } m_supportedVendors.insert(vendor.id(), vendor); @@ -932,6 +941,7 @@ void DeviceManager::loadPlugins() m_supportedDevices.insert(deviceClass.id(), deviceClass); qCDebug(dcDeviceManager) << "* Loaded device class:" << deviceClass.name(); } + GuhSettings settings(GuhSettings::SettingsRolePlugins); settings.beginGroup("PluginConfig"); ParamList params; @@ -950,9 +960,12 @@ void DeviceManager::loadPlugins() } } settings.endGroup(); - DeviceError status = pluginIface->setConfiguration(params); - if (status != DeviceErrorNoError) { - qCWarning(dcDeviceManager) << "Error setting params to plugin. Broken configuration?"; + + if (params.count() > 0) { + DeviceError status = pluginIface->setConfiguration(params); + if (status != DeviceErrorNoError) { + qCWarning(dcDeviceManager) << "Error setting params to plugin. Broken configuration?"; + } } } settings.endGroup(); @@ -962,12 +975,14 @@ void DeviceManager::loadPlugins() } m_devicePlugins.insert(pluginIface->pluginId(), pluginIface); + connect(pluginIface, &DevicePlugin::emitEvent, this, &DeviceManager::eventTriggered); connect(pluginIface, &DevicePlugin::devicesDiscovered, this, &DeviceManager::slotDevicesDiscovered); connect(pluginIface, &DevicePlugin::deviceSetupFinished, this, &DeviceManager::slotDeviceSetupFinished); connect(pluginIface, &DevicePlugin::actionExecutionFinished, this, &DeviceManager::actionExecutionFinished); connect(pluginIface, &DevicePlugin::pairingFinished, this, &DeviceManager::slotPairingFinished); connect(pluginIface, &DevicePlugin::autoDevicesAppeared, this, &DeviceManager::autoDevicesAppeared); + qCDebug(dcDeviceManager) << "* Finished loading plugin" << pluginIface->pluginName() << pluginIface->pluginId(); } } } diff --git a/libguh/devicemanager.h b/libguh/devicemanager.h index 42758c6b..46746067 100644 --- a/libguh/devicemanager.h +++ b/libguh/devicemanager.h @@ -143,7 +143,7 @@ signals: void deviceSetupFinished(Device *device, DeviceError status); void deviceEditFinished(Device *device, DeviceError status); void pairingFinished(const PairingTransactionId &pairingTransactionId, DeviceError status, const DeviceId &deviceId = DeviceId()); - void actionExecutionFinished(const ActionId &actionId, DeviceError status); + void actionExecutionFinished(const ActionId &actionId, DeviceManager::DeviceError status); public slots: DeviceError executeAction(const Action &action); diff --git a/libguh/libguh.pro b/libguh/libguh.pro index 03f1176c..5fed54ef 100644 --- a/libguh/libguh.pro +++ b/libguh/libguh.pro @@ -60,6 +60,7 @@ SOURCES += devicemanager.cpp \ types/statedescriptor.cpp \ HEADERS += devicemanager.h \ + libguh.h \ typeutils.h \ loggingcategories.h \ guhsettings.h \ @@ -101,7 +102,6 @@ HEADERS += devicemanager.h \ types/ruleaction.h \ types/ruleactionparam.h \ types/statedescriptor.h \ - libguh.h # install plugininfo python script for libguh-dev generateplugininfo.files = $$top_srcdir/plugins/guh-generateplugininfo diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index 18da0649..de33a813 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -80,20 +80,6 @@ \sa NetworkManager::replyReady() */ -/*! - \fn void DevicePlugin::executeAction(Device *device, const Action &action) - This will be called to actually execute actions on the hardware. The \{Device} and - the \{Action} are contained in the \a device and \a action parameters. - Return the appropriate \l{DeviceManager::DeviceError}{DeviceError}. - - It is possible to execute actions asynchronously. You never should do anything blocking for - a long time (e.g. wait on a network reply from the internet) but instead return - DeviceManager::DeviceErrorAsync and continue processing in an async manner. Once - you have the reply ready, emit actionExecutionFinished() with the appropriate parameters. - - \sa actionExecutionFinished() -*/ - /*! \fn void DevicePlugin::devicesDiscovered(const DeviceClassId &deviceClassId, const QList &devices); This signal is emitted when the discovery of a \a deviceClassId of this DevicePlugin is finished. The \a devices parameter describes the @@ -182,7 +168,7 @@ QString DevicePlugin::pluginName() const * same uuid and don't change it or configurations can't be matched any more. */ PluginId DevicePlugin::pluginId() const { - return m_metaData.value("id").toString(); + return PluginId(m_metaData.value("id").toString()); } /*! Returns the list of \l{Vendor}{Vendors} supported by this DevicePlugin. */ @@ -405,6 +391,24 @@ DeviceManager::DeviceSetupStatus DevicePlugin::confirmPairing(const PairingTrans return DeviceManager::DeviceSetupStatusFailure; } +/*! This will be called to actually execute actions on the hardware. The \{Device} and + * the \{Action} are contained in the \a device and \a action parameters. + * Return the appropriate \l{DeviceManager::DeviceError}{DeviceError}. + * + * It is possible to execute actions asynchronously. You never should do anything blocking for + * a long time (e.g. wait on a network reply from the internet) but instead return + * DeviceManager::DeviceErrorAsync and continue processing in an async manner. Once + * you have the reply ready, emit actionExecutionFinished() with the appropriate parameters. + * + * \sa actionExecutionFinished() +*/ +DeviceManager::DeviceError DevicePlugin::executeAction(Device *device, const Action &action) +{ + Q_UNUSED(device) + Q_UNUSED(action) + return DeviceManager::DeviceErrorNoError; +} + /*! Returns the configuration description of this DevicePlugin as a list of \l{ParamType}{ParamTypes}. */ QList DevicePlugin::configurationDescription() const { @@ -487,13 +491,11 @@ QVariant DevicePlugin::configValue(const QString ¶mName) const return QVariant(); } -/*! - Will be called by the DeviceManager to set a plugin's \a configuration. - */ +/*! Will be called by the DeviceManager to set a plugin's \a configuration. */ DeviceManager::DeviceError DevicePlugin::setConfiguration(const ParamList &configuration) { foreach (const Param ¶m, configuration) { - qCDebug(dcDeviceManager) << "setting config" << param; + qCDebug(dcDeviceManager) << "* setting config" << param; DeviceManager::DeviceError result = setConfigValue(param.name(), param.value()); if (result != DeviceManager::DeviceErrorNoError) { return result; @@ -625,7 +627,7 @@ QNetworkReply *DevicePlugin::networkManagerGet(const QNetworkRequest &request) if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) { return deviceManager()->m_networkManager->get(pluginId(), request); } else { - qCWarning(dcDeviceManager) << "network manager resource missing for plugin " << pluginName(); + qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName(); } return nullptr; } @@ -642,7 +644,7 @@ QNetworkReply *DevicePlugin::networkManagerPost(const QNetworkRequest &request, if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) { return deviceManager()->m_networkManager->post(pluginId(), request, data); } else { - qCWarning(dcDeviceManager) << "network manager resource missing for plugin " << pluginName(); + qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName(); } return nullptr; } @@ -658,7 +660,7 @@ QNetworkReply *DevicePlugin::networkManagerPut(const QNetworkRequest &request, c if (requiredHardware().testFlag(DeviceManager::HardwareResourceNetworkManager)) { return deviceManager()->m_networkManager->put(pluginId(), request, data); } else { - qCWarning(dcDeviceManager) << "network manager resource missing for plugin " << pluginName(); + qCWarning(dcDeviceManager) << "Network manager hardware resource not set for plugin" << pluginName(); } return nullptr; } diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index 711041ad..095f9353 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -69,6 +69,8 @@ public: virtual DeviceManager::DeviceError displayPin(const PairingTransactionId &pairingTransactionId, const DeviceDescriptor &deviceDescriptor); virtual DeviceManager::DeviceSetupStatus confirmPairing(const PairingTransactionId &pairingTransactionId, const DeviceClassId &deviceClassId, const ParamList ¶ms, const QString &secret); + virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action); + // Hardware input virtual void radioData(const QList &rawData) {Q_UNUSED(rawData)} virtual void guhTimer() {} @@ -88,11 +90,6 @@ public: QVariant configValue(const QString ¶mName) const; DeviceManager::DeviceError setConfigValue(const QString ¶mName, const QVariant &value); -public slots: - virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action) { - Q_UNUSED(device) Q_UNUSED(action) - return DeviceManager::DeviceErrorNoError; - } signals: void emitEvent(const Event &event);