smal fixes

pull/135/head
Simon Stürz 2016-01-11 18:59:36 +01:00 committed by Michael Zanetti
parent 16e6e2de3b
commit 3157298a65
6 changed files with 62 additions and 47 deletions

View File

@ -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

View File

@ -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<DevicePlugin *>(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();
}
}
}

View File

@ -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);

View File

@ -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

View File

@ -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<DeviceDescriptor> &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<ParamType> DevicePlugin::configurationDescription() const
{
@ -487,13 +491,11 @@ QVariant DevicePlugin::configValue(const QString &paramName) 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 &param, 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;
}

View File

@ -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 &params, const QString &secret);
virtual DeviceManager::DeviceError executeAction(Device *device, const Action &action);
// Hardware input
virtual void radioData(const QList<int> &rawData) {Q_UNUSED(rawData)}
virtual void guhTimer() {}
@ -88,11 +90,6 @@ public:
QVariant configValue(const QString &paramName) const;
DeviceManager::DeviceError setConfigValue(const QString &paramName, 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);