summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2014-06-20 08:14:39 +0200
committerFabian Bumberger <fbumberger@rim.com>2014-07-02 12:41:46 +0200
commit9d09719e28e990f616c23dde9a3d6bcee7374e81 (patch)
tree9408f7f16529d8e6c933b29e61f5ef1204ea4710 /src
parent1727e5b732d3c6603bd12cf0839508cf267272e2 (diff)
Initial implementation of the QNearfieldmanager
While the QNearFielManager is not functional yet, this commit contains a sceleton implementation on which the future implementation can be built on. Change-Id: I075b42bb74051db4629e7a93b2aaea89785807b9 Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/nfc/neard/adapter.cpp2
-rw-r--r--src/nfc/neard/manager.cpp2
-rw-r--r--src/nfc/nfc.pro27
-rw-r--r--src/nfc/qnearfieldmanager_neard.cpp222
-rw-r--r--src/nfc/qnearfieldmanager_neard.h89
5 files changed, 338 insertions, 4 deletions
diff --git a/src/nfc/neard/adapter.cpp b/src/nfc/neard/adapter.cpp
index 4944a921..e2129ec4 100644
--- a/src/nfc/neard/adapter.cpp
+++ b/src/nfc/neard/adapter.cpp
@@ -9,7 +9,7 @@
* before re-generating it.
*/
-#include "adapter.h"
+#include "adapter_p.h" // HAND-EDIT
/*
* Implementation of interface class OrgNeardAdapterInterface
diff --git a/src/nfc/neard/manager.cpp b/src/nfc/neard/manager.cpp
index d431f904..97c7075c 100644
--- a/src/nfc/neard/manager.cpp
+++ b/src/nfc/neard/manager.cpp
@@ -9,7 +9,7 @@
* before re-generating it.
*/
-#include "manager.h"
+#include "manager_p.h" // HAND-EDIT
/*
* Implementation of interface class OrgNeardManagerInterface
diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro
index 7b88d4f0..b8c6e992 100644
--- a/src/nfc/nfc.pro
+++ b/src/nfc/nfc.pro
@@ -53,7 +53,8 @@ SOURCES += \
qqmlndefrecord.cpp \
qndefnfcsmartposterrecord.cpp \
qnearfieldsharemanager.cpp \
- qnearfieldsharetarget.cpp
+ qnearfieldsharetarget.cpp \
+ qnearfieldmanager_neard.cpp
CONFIG(blackberry) {
NFC_BACKEND_AVAILABLE = yes
@@ -99,6 +100,27 @@ CONFIG(blackberry) {
}
}
+linux {
+ NFC_BACKEND_AVAILABLE = yes
+
+ QT += dbus
+
+ PRIVATE_HEADERS += \
+ qllcpsocket_p_p.h \
+ qllcpserver_p_p.h \
+ qnearfieldmanager_neard.h \
+ qnearfieldsharemanagerimpl_p.h \
+ qnearfieldsharetargetimpl_p.h
+
+ SOURCES += \
+ qllcpsocket_p.cpp \
+ qllcpserver_p.cpp \
+ qnearfieldsharemanagerimpl_p.cpp \
+ qnearfieldsharetargetimpl_p.cpp
+
+ include(neard/neard.pri)
+}
+
simulator {
NFC_BACKEND_AVAILABLE = yes
@@ -140,4 +162,5 @@ isEmpty(NFC_BACKEND_AVAILABLE) {
qnearfieldsharetargetimpl_p.cpp
}
-HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS
+HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS \
+ qnearfieldmanager_neard.h
diff --git a/src/nfc/qnearfieldmanager_neard.cpp b/src/nfc/qnearfieldmanager_neard.cpp
new file mode 100644
index 00000000..acd30405
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_neard.cpp
@@ -0,0 +1,222 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qnearfieldmanager_neard.h"
+#include "neard/adapter_p.h"
+#include "neard/manager_p.h"
+
+QT_BEGIN_NAMESPACE
+
+// TODO We need a constructor that lets us select a adapter
+QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl()
+ : m_adapter(0)
+{
+ // Look for a NFC adapter
+ OrgNeardManagerInterface manager(QStringLiteral("org.neard"), QStringLiteral("/"),
+ QDBusConnection::systemBus());
+ QDBusPendingReply<QVariantMap> reply = manager.GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ qDebug() << "Error getting manager properties." << "Neard daemon running?";
+
+ const QDBusArgument &paths = reply.value().value(QStringLiteral("Adapters")).value<QDBusArgument>();
+
+ paths.beginArray();
+ while (!paths.atEnd()) {
+ QDBusObjectPath path;
+ paths >> path;
+ m_adapterPath = path.path();
+ //qDebug() << "path is" << m_adapterPath;
+ break;
+ }
+ paths.endArray();
+}
+
+QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl()
+{
+ stopTargetDetection();
+}
+
+bool QNearFieldManagerPrivateImpl::isAvailable() const
+{
+ OrgNeardManagerInterface manager(QStringLiteral("org.neard"), QStringLiteral("/"),
+ QDBusConnection::systemBus());
+ QDBusPendingReply<QVariantMap> reply = manager.GetProperties();
+ reply.waitForFinished();
+ if (reply.isError())
+ qDebug() << "Error getting manager properties." << "Neard daemon running?";
+
+ QDBusArgument paths = reply.value().value(QStringLiteral("Adapters")).value<QDBusArgument>();
+
+ paths.beginArray();
+ while (!paths.atEnd()) {
+ QDBusObjectPath path;
+ paths >> path;
+ //Check if the adapter exists
+ if (path.path() == m_adapterPath)
+ return true;
+ }
+ return false;
+}
+
+bool QNearFieldManagerPrivateImpl::startTargetDetection()
+{
+ if (!isAvailable())
+ return false;
+
+ // TODO define behavior when target detection is started again
+ if (m_adapter)
+ return false;
+
+ //qDebug() << "Constructing interface with path" << m_adapterPath;
+ m_adapter = new OrgNeardAdapterInterface(QStringLiteral("org.neard"), m_adapterPath,
+ QDBusConnection::systemBus());
+
+ {
+ QDBusPendingReply<QVariantMap> reply = m_adapter->GetProperties();
+ reply.waitForFinished();
+ if (!reply.isError()) {
+ if (reply.value().value(QStringLiteral("Polling")) == true) {
+ //qDebug() << "Adapter" << m_adapterPath << "is busy";
+ return false; // Should we return false or true?
+ }
+ }
+ }
+
+ // Switch on the NFC adapter if it is not already
+ QDBusPendingReply<> reply = m_adapter->SetProperty(QStringLiteral("Powered"), QDBusVariant(true));
+ reply.waitForFinished();
+
+ //qDebug() << (reply.isError() ? "Error setting up adapter" : "Adapter powered on");
+ reply = m_adapter->StartPollLoop(QStringLiteral("Dual"));
+ reply.waitForFinished();
+ //qDebug() << (reply.isError() ? "Error when starting polling" : "Successfully started to poll");
+
+ // TagFound and TagLost DBus signals don't work
+// connect(m_adapter, SIGNAL(TagFound(const QDBusObjectPath&)),
+// this, SLOT(tagFound(const QDBusObjectPath&)));
+// connect(m_adapter, SIGNAL(TagLost(const QDBusObjectPath&)),
+// this, SLOT(tagFound(const QDBusObjectPath&)));
+ connect(m_adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)),
+ this, SLOT(propertyChanged(QString,QDBusVariant)));
+ return true;
+}
+
+void QNearFieldManagerPrivateImpl::stopTargetDetection()
+{
+ //qDebug() << "Stop target detection";
+ QDBusPendingReply<> reply = m_adapter->StopPollLoop();
+ reply.waitForFinished();
+ // TODO Should we really power down the adapter?
+ reply = m_adapter->SetProperty(QStringLiteral("Powered"), QDBusVariant(false));
+ reply.waitForFinished();
+ delete m_adapter;
+ m_adapter = 0;
+}
+
+int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(QObject *object, const QMetaMethod &method)
+{
+ Q_UNUSED(object);
+ Q_UNUSED(method);
+ return 0;
+}
+
+int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(const QNdefFilter &filter, QObject *object, const QMetaMethod &method)
+{
+ Q_UNUSED(filter);
+ Q_UNUSED(object);
+ Q_UNUSED(method);
+ return -1;
+}
+
+bool QNearFieldManagerPrivateImpl::unregisterNdefMessageHandler(int handlerId)
+{
+ Q_UNUSED(handlerId);
+ return false;
+}
+
+void QNearFieldManagerPrivateImpl::requestAccess(QNearFieldManager::TargetAccessModes accessModes)
+{
+ Q_UNUSED(accessModes);
+}
+
+void QNearFieldManagerPrivateImpl::releaseAccess(QNearFieldManager::TargetAccessModes accessModes)
+{
+ Q_UNUSED(accessModes);
+}
+
+void QNearFieldManagerPrivateImpl::tagFound(const QDBusObjectPath &path)
+{
+ qDebug() << "Tag found" << path.path();
+}
+
+void QNearFieldManagerPrivateImpl::propertyChanged(QString property, QDBusVariant value)
+{
+ qDebug() << "Property changed" << property;
+ // New device detected
+ if (property == QStringLiteral("Devices")) {
+ const QDBusArgument &devices = value.variant().value<QDBusArgument>();
+ QStringList devicesList;
+ devices.beginArray();
+ while (!devices.atEnd()) {
+ QDBusObjectPath path;
+ devices >> path;
+ devicesList.append(path.path());
+ qDebug() << "New device" << devicesList;
+ }
+ devices.endArray();
+ qDebug() << "Devices list changed" << devicesList;
+ } else if (property == QStringLiteral("Tags")) {
+ const QDBusArgument &tags = value.variant().value<QDBusArgument>();
+ QStringList tagList;
+ tags.beginArray();
+ while (!tags.atEnd()) {
+ QDBusObjectPath path;
+ tags >> path;
+ tagList.append(path.path());
+ qDebug() << "New tag" << path.path();
+ }
+ tags.endArray();
+ qDebug() << "Tag list changed" << tagList;
+ }
+}
+
+QT_END_NAMESPACE
diff --git a/src/nfc/qnearfieldmanager_neard.h b/src/nfc/qnearfieldmanager_neard.h
new file mode 100644
index 00000000..1848d16a
--- /dev/null
+++ b/src/nfc/qnearfieldmanager_neard.h
@@ -0,0 +1,89 @@
+/***************************************************************************
+**
+** Copyright (C) 2014 BlackBerry Limited. All rights reserved.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtNfc module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QNEARFIELDMANAGER_NEARD_H
+#define QNEARFIELDMANAGER_NEARD_H
+
+#include "qnearfieldmanager_p.h"
+#include "qnearfieldmanager.h"
+#include "qnearfieldtarget.h"
+
+#include "neard/adapter_p.h"
+
+QT_BEGIN_NAMESPACE
+
+class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate
+{
+ Q_OBJECT
+
+public:
+ QNearFieldManagerPrivateImpl();
+ ~QNearFieldManagerPrivateImpl();
+
+ bool isAvailable() const;
+
+ bool startTargetDetection();
+
+ void stopTargetDetection();
+
+ int registerNdefMessageHandler(QObject *object, const QMetaMethod &method);
+
+ int registerNdefMessageHandler(const QNdefFilter &filter, QObject *object, const QMetaMethod &method);
+
+ bool unregisterNdefMessageHandler(int handlerId);
+
+ void requestAccess(QNearFieldManager::TargetAccessModes accessModes);
+
+ void releaseAccess(QNearFieldManager::TargetAccessModes accessModes);
+
+private Q_SLOTS:
+ void tagFound(const QDBusObjectPath&);
+ void propertyChanged(QString,QDBusVariant);
+
+private:
+ QString m_adapterPath;
+ OrgNeardAdapterInterface *m_adapter;
+};
+
+QT_END_NAMESPACE
+
+
+#endif // QNEARFIELDMANAGER_NEARD_H