summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLutz Schönemann <lutz.schoenemann@basyskom.com>2014-10-08 14:05:33 +0200
committerMartin Leutelt <martin.leutelt@basyskom.com>2014-10-09 17:01:20 +0200
commita00a35e6e6410af797c1b8d0f220523fcee6a6ca (patch)
tree4473e385cbe13069d83ab9a07d1fed3085b1659d /src
parentf258fbbaf2b14ad0af60ce3f74cd2ce26a139689 (diff)
Fixing crash when stopping poll loop
When stopping the neard adapter poll loop without starting it from the same QNearFieldManagerPrivateImpl instance the m_adapter variable does not hold a valid pointer to an instance of OrgNeardAdapterInterface. This patch fixes that issue by creating a temporary instance on the stack to call the appropriate function on the D-Bus interface. Change-Id: I42ced8d00ca9f87756c8f3f81ca78969702344c1 Reviewed-by: Martin Leutelt <martin.leutelt@basyskom.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/nfc/qnearfieldmanager_neard.cpp58
-rw-r--r--src/nfc/qnearfieldmanager_neard_p.h4
2 files changed, 32 insertions, 30 deletions
diff --git a/src/nfc/qnearfieldmanager_neard.cpp b/src/nfc/qnearfieldmanager_neard.cpp
index 41331a23..65cf0ee3 100644
--- a/src/nfc/qnearfieldmanager_neard.cpp
+++ b/src/nfc/qnearfieldmanager_neard.cpp
@@ -54,8 +54,6 @@ Q_DECLARE_LOGGING_CATEGORY(QT_NFC_NEARD)
// TODO We need a constructor that lets us select an adapter
QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
: QNearFieldManagerPrivate(),
- m_adapter(0),
- m_dbusProperties(0),
m_neardHelper(NeardHelper::instance())
{
QDBusPendingReply<ManagedObjectList> reply = m_neardHelper->dbusObjectManager()->GetManagedObjects();
@@ -124,21 +122,18 @@ bool QNearFieldManagerPrivateImpl::startTargetDetection()
if (!isAvailable())
return false;
- if (!m_dbusProperties) {
- m_dbusProperties = new OrgFreedesktopDBusPropertiesInterface(QStringLiteral("org.neard"),
- m_adapterPath,
- QDBusConnection::systemBus(),
- this);
- }
+ OrgFreedesktopDBusPropertiesInterface dbusProperties(QStringLiteral("org.neard"),
+ m_adapterPath,
+ QDBusConnection::systemBus());
- if (!m_dbusProperties->isValid()) {
+ if (!dbusProperties.isValid()) {
qCWarning(QT_NFC_NEARD) << "dbus property interface invalid";
return false;
}
// check if the adapter is currently polling
- QDBusPendingReply<QDBusVariant> replyPolling = m_dbusProperties->Get(QStringLiteral("org.neard.Adapter"),
- QStringLiteral("Polling"));
+ QDBusPendingReply<QDBusVariant> replyPolling = dbusProperties.Get(QStringLiteral("org.neard.Adapter"),
+ QStringLiteral("Polling"));
replyPolling.waitForFinished();
if (!replyPolling.isError()) {
if (replyPolling.value().variant().toBool()) {
@@ -151,16 +146,16 @@ bool QNearFieldManagerPrivateImpl::startTargetDetection()
}
// check if the adapter it powered
- QDBusPendingReply<QDBusVariant> replyPowered = m_dbusProperties->Get(QStringLiteral("org.neard.Adapter"),
- QStringLiteral("Powered"));
+ QDBusPendingReply<QDBusVariant> replyPowered = dbusProperties.Get(QStringLiteral("org.neard.Adapter"),
+ QStringLiteral("Powered"));
replyPowered.waitForFinished();
if (!replyPowered.isError()) {
if (replyPowered.value().variant().toBool()) {
qCDebug(QT_NFC_NEARD) << "adapter is already powered";
} else {
- QDBusPendingReply<QDBusVariant> replyTryPowering = m_dbusProperties->Set(QStringLiteral("org.neard.Adapter"),
- QStringLiteral("Powered"),
- QDBusVariant(true));
+ QDBusPendingReply<QDBusVariant> replyTryPowering = dbusProperties.Set(QStringLiteral("org.neard.Adapter"),
+ QStringLiteral("Powered"),
+ QDBusVariant(true));
replyTryPowering.waitForFinished();
if (!replyTryPowering.isError()) {
qCDebug(QT_NFC_NEARD) << "powering adapter";
@@ -172,15 +167,12 @@ bool QNearFieldManagerPrivateImpl::startTargetDetection()
}
// create adapter and start poll loop
- if (!m_adapter) {
- m_adapter = new OrgNeardAdapterInterface(QStringLiteral("org.neard"),
- m_adapterPath,
- QDBusConnection::systemBus(),
- this);
- }
+ OrgNeardAdapterInterface neardAdapter(QStringLiteral("org.neard"),
+ m_adapterPath,
+ QDBusConnection::systemBus());
// possible modes: "Target", "Initiator", "Dual"
- QDBusPendingReply<> replyPollLoop = m_adapter->StartPollLoop(QStringLiteral("Dual"));
+ QDBusPendingReply<> replyPollLoop = neardAdapter.StartPollLoop(QStringLiteral("Dual"));
replyPollLoop.waitForFinished();
if (replyPollLoop.isError()) {
qCWarning(QT_NFC_NEARD) << "error when starting polling";
@@ -198,13 +190,27 @@ void QNearFieldManagerPrivateImpl::stopTargetDetection()
if (!isAvailable())
return;
+ OrgFreedesktopDBusPropertiesInterface dbusProperties(QStringLiteral("org.neard"),
+ m_adapterPath,
+ QDBusConnection::systemBus());
+
+ if (!dbusProperties.isValid()) {
+ qCWarning(QT_NFC_NEARD) << "dbus property interface invalid";
+ return;
+ }
+
// check if the adapter is currently polling
- QDBusPendingReply<QDBusVariant> replyPolling = m_dbusProperties->Get(QStringLiteral("org.neard.Adapter"),
- QStringLiteral("Polling"));
+ QDBusPendingReply<QDBusVariant> replyPolling = dbusProperties.Get(QStringLiteral("org.neard.Adapter"),
+ QStringLiteral("Polling"));
replyPolling.waitForFinished();
if (!replyPolling.isError()) {
if (replyPolling.value().variant().toBool()) {
- QDBusPendingReply<> replyStopPolling = m_adapter->StopPollLoop();
+ // create adapter and stop poll loop
+ OrgNeardAdapterInterface neardAdapter(QStringLiteral("org.neard"),
+ m_adapterPath,
+ QDBusConnection::systemBus());
+
+ QDBusPendingReply<> replyStopPolling = neardAdapter.StopPollLoop();
replyStopPolling.waitForFinished();
if (replyStopPolling.isError())
qCWarning(QT_NFC_NEARD) << "error when stopping polling";
diff --git a/src/nfc/qnearfieldmanager_neard_p.h b/src/nfc/qnearfieldmanager_neard_p.h
index ee72595c..8df4149b 100644
--- a/src/nfc/qnearfieldmanager_neard_p.h
+++ b/src/nfc/qnearfieldmanager_neard_p.h
@@ -52,9 +52,7 @@
#include <QDBusVariant>
#include <QMap>
-class OrgNeardAdapterInterface;
class OrgNeardManagerInterface;
-class OrgFreedesktopDBusPropertiesInterface;
QT_BEGIN_NAMESPACE
@@ -89,8 +87,6 @@ private Q_SLOTS:
private:
QString m_adapterPath;
- OrgNeardAdapterInterface *m_adapter;
- OrgFreedesktopDBusPropertiesInterface *m_dbusProperties;
QMap<QString, QNearFieldTarget*> m_activeTags;
NeardHelper *m_neardHelper;
};