From 9f377d1fa286817a17a5e5de3786a2d73aeaa822 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Mon, 7 Jul 2014 16:58:22 +1000 Subject: Series of crash fixes from Mer, squashed 1)tracing plugin loading 2)m_remoteSensorManager can be nullptr But it seems it does not solve incorrect initialization in the case manager interface is nullptr: init() for different sensors does not check initDone 3)split initSensor() to template function and function most of initSensor() does not depend on template param, so it is better to split it -> less code should be generated 4)do not use sensor manager if it is invalid 5)correct class members initialization order 6)assert sensor interface is not null From what I saw according to logic it should not happen so using Q_ASSERT for better maintainability 7)check local interface pointer in SensorfwTapSensor::start() Signed-off-by: Denis Zalevskiy Change-Id: I5c1bf3999ad2268c0dba9b3fe511d999c2e63fd9 Reviewed-by: Alex Blasche --- src/sensors/qsensormanager.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/sensors') diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp index 29bd4b5f..abe5f853 100644 --- a/src/sensors/qsensormanager.cpp +++ b/src/sensors/qsensormanager.cpp @@ -48,12 +48,15 @@ #include "sensorlog_p.h" #include #include +#include QT_BEGIN_NAMESPACE typedef QHash FactoryForIdentifierMap; typedef QHash BackendIdentifiersForTypeMap; +static QLoggingCategory sensorsCategory("qt.sensors"); + class QSensorManagerPrivate : public QObject { friend class QSensorManager; @@ -77,7 +80,6 @@ public: loadExternalPlugins = false; } } - bool loadExternalPlugins; PluginLoadingState pluginLoadingState; QFactoryLoader *loader; @@ -101,9 +103,16 @@ public: if (config.isEmpty()) return; // QStandardPaths is broken? config += QLatin1String("/QtProject/Sensors.conf"); #endif - if (!QFile::exists(config)) return; + qCDebug(sensorsCategory) << "Loading config from" << config; + if (!QFile::exists(config)) { + qCWarning(sensorsCategory) << "There is no config file" << config; + return; + } QFile cfgfile(config); - if (!cfgfile.open(QFile::ReadOnly)) return; + if (!cfgfile.open(QFile::ReadOnly)) { + qCWarning(sensorsCategory) << "Can't open config file" << config; + return; + } QTextStream stream(&cfgfile); QString line; @@ -169,13 +178,19 @@ Q_GLOBAL_STATIC(QSensorManagerPrivate, sensorManagerPrivate) static void initPlugin(QObject *o) { - if (!o) return; + qCDebug(sensorsCategory) << "Init plugin" << o; + if (!o) { + qCWarning(sensorsCategory) << "Null plugin" << o; + return; + } QSensorManagerPrivate *d = sensorManagerPrivate(); if (!d) return; // hardly likely but just in case... - if (d->seenPlugins.contains(o)) + if (d->seenPlugins.contains(o)) { + qCDebug(sensorsCategory) << "Plugin is seen" << o; return; + } QSensorChangesInterface *changes = qobject_cast(o); if (changes) @@ -184,8 +199,11 @@ static void initPlugin(QObject *o) QSensorPluginInterface *plugin = qobject_cast(o); if (plugin) { + qCDebug(sensorsCategory) << "Register sensors for " << plugin; d->seenPlugins.insert(o); plugin->registerSensors(); + } else { + qCWarning(sensorsCategory) << "Can't cast to plugin" << o; } } -- cgit v1.2.3