diff options
-rw-r--r-- | src/nfc/nfc.pro | 8 | ||||
-rw-r--r-- | src/nfc/qnearfieldmanager.cpp | 2 | ||||
-rw-r--r-- | src/nfc/qnearfieldmanager_qnx.cpp | 160 | ||||
-rw-r--r-- | src/nfc/qnearfieldmanager_qnx_p.h | 91 | ||||
-rw-r--r-- | src/nfc/qnx/qnxnfcmanager.cpp | 20 | ||||
-rw-r--r-- | src/nfc/qnx/qnxnfcmanager_p.h | 10 |
6 files changed, 275 insertions, 16 deletions
diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro index ce3eda06..935eb2fc 100644 --- a/src/nfc/nfc.pro +++ b/src/nfc/nfc.pro @@ -108,19 +108,19 @@ maemo6|meego { qnx { NFC_BACKEND_AVAILABLE = yes - DEFINES += QQNXNFC_DEBUG + DEFINES += QNX_NFC QQNXNFC_DEBUG PRIVATE_HEADERS += \ qllcpsocket_p.h \ qllcpserver_p.h \ - qnearfieldmanagerimpl_p.h \ - qnx/qnxnfcmanager_p.h\ + qnearfieldmanager_qnx_p.h \ + qnx/qnxnfcmanager_p.h \ qnearfieldtarget_qnx_p.h SOURCES += \ qllcpsocket_p.cpp \ qllcpserver_p.cpp \ - qnearfieldmanagerimpl_p.cpp\ + qnearfieldmanager_qnx.cpp \ qnx/qnxnfcmanager.cpp } diff --git a/src/nfc/qnearfieldmanager.cpp b/src/nfc/qnearfieldmanager.cpp index 6c6b1dd1..571c4502 100644 --- a/src/nfc/qnearfieldmanager.cpp +++ b/src/nfc/qnearfieldmanager.cpp @@ -46,6 +46,8 @@ #include "qnearfieldmanager_simulator_p.h" #elif defined(Q_WS_MAEMO_6) || defined (Q_WS_MEEGO) #include "qnearfieldmanager_maemo6_p.h" +#elif defined(QNX_NFC) +#include "qnearfieldmanager_qnx_p.h" #else #include "qnearfieldmanagerimpl_p.h" #endif diff --git a/src/nfc/qnearfieldmanager_qnx.cpp b/src/nfc/qnearfieldmanager_qnx.cpp new file mode 100644 index 00000000..c837e04c --- /dev/null +++ b/src/nfc/qnearfieldmanager_qnx.cpp @@ -0,0 +1,160 @@ +/*************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** 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_qnx_p.h" +#include <QDebug> +#include "qnearfieldtarget_qnx_p.h" +#include <QMetaMethod> +#include "qndeffilter.h" +#include "qndefrecord.h" + +QTNFC_BEGIN_NAMESPACE + +QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() : + m_handlerID(0) +{ + QNXNFCManager::instance()->registerForNewInstance(); + connect(QNXNFCManager::instance(), SIGNAL(ndefMessage(QNdefMessage, QNearFieldTarget)), this, SLOT(handleMessage(QNdefMessage, QNearFieldTarget))); + + m_requestedModes = QNearFieldManager::NdefWriteTargetAccess; +} + +QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl() +{ + //QNXNFCManager::instance()->unregisterObject(this); + QNXNFCManager::instance()->unregisterForInstance(); +} + +bool QNearFieldManagerPrivateImpl::isAvailable() const +{ + return QNXNFCManager::instance()->isAvailable(); +} + +bool QNearFieldManagerPrivateImpl::startTargetDetection(const QList<QNearFieldTarget::Type> &targetTypes) +{ + if (QNXNFCManager::instance()->startTargetDetection(targetTypes)) { + connect(QNXNFCManager::instance(), SIGNAL(targetDetected(NearFieldTarget *, const QList<QNdefMessage> &)), + this, SLOT(newTarget(NearFieldTarget *, const QList<QNdefMessage> &))); + return true; + } else { + qWarning()<<Q_FUNC_INFO<<"Could not start Target detection"; + return false; + } +} + +void QNearFieldManagerPrivateImpl::stopTargetDetection() +{ + disconnect(QNXNFCManager::instance(), SIGNAL(targetDetected(NearFieldTarget *, const QList<QNdefMessage> &)), + this, SLOT(newTarget(NearFieldTarget *, const QList<QNdefMessage> &))); + QNXNFCManager::instance()->unregisterTargetDetection(this); +} + +int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(QObject *object, const QMetaMethod &method) +{ + ndefMessageHandlers.append(QPair<QPair<int, QObject *>, QMetaMethod>(QPair<int, QObject *>(m_handlerID, object), method)); + //Wont work any more if a handler is deleted + return m_handlerID++; +} + +int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(const QNdefFilter &filter, + QObject *object, const QMetaMethod &method) +{ + ndefFilterHandlers.append(QPair<QPair<int, QObject*>, QPair<QNdefFilter, QMetaMethod> > + (QPair<int, QObject*>(m_handlerID, object), QPair<QNdefFilter, QMetaMethod>(filter, method))); + return m_handlerID++; +} + +bool QNearFieldManagerPrivateImpl::unregisterNdefMessageHandler(int handlerId) +{ + for (int i=0; i<ndefMessageHandlers.count(); i++) { + if (ndefMessageHandlers.at(i).first.first == handlerId) { + ndefMessageHandlers.removeAt(i); + return true; + } + } + for (int i=0; i<ndefFilterHandlers.count(); i++) { + if (ndefFilterHandlers.at(i).first.first == handlerId) { + ndefFilterHandlers.removeAt(i); + return true; + } + } + return false; +} + +void QNearFieldManagerPrivateImpl::requestAccess(QNearFieldManager::TargetAccessModes accessModes) +{ + Q_UNUSED(accessModes); + //Do nothing, because we dont have access modes for the target +} + +void QNearFieldManagerPrivateImpl::releaseAccess(QNearFieldManager::TargetAccessModes accessModes) +{ + Q_UNUSED(accessModes); + //Do nothing, because we dont have access modes for the target +} + +void QNearFieldManagerPrivateImpl::handleMessage(QNdefMessage message, QNearFieldTarget *target) +{ + //For message handlers without filters + for (int i = 0; i < ndefMessageHandlers.count(); i++) { + ndefMessageHandlers.at(i).second.invoke(ndefMessageHandlers.at(i).first.second, Q_ARG(QNdefMessage, message), Q_ARG(QNearFieldTarget*, target)); + } + + //For message handlers that specified a filter + for (int i = 0; i < ndefFilterHandlers.count(); i++) { + QNdefFilter filter = ndefFilterHandlers.at(i).second.first; + if (filter.recordCount() > message.count()) + continue; + for (int j = 0; j < filter.recordCount(); j++) { + if (message.at(j).typeNameFormat() != filter.recordAt(j).typeNameFormat + || message.at(j).type() != filter.recordAt(j).type ) + continue; + } + ndefMessageHandlers.at(i).second.invoke(ndefMessageHandlers.at(i).first.second, Q_ARG(QNdefMessage, message), Q_ARG(QNearFieldTarget*, target)); + } +} + +void QNearFieldManagerPrivateImpl::newTarget(NearFieldTarget<QNearFieldTarget> *target, const QList<QNdefMessage> &messages) +{ + emit targetDetected(target); +} + +QTNFC_END_NAMESPACE diff --git a/src/nfc/qnearfieldmanager_qnx_p.h b/src/nfc/qnearfieldmanager_qnx_p.h new file mode 100644 index 00000000..a61a1414 --- /dev/null +++ b/src/nfc/qnearfieldmanager_qnx_p.h @@ -0,0 +1,91 @@ +/*************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** 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_QNX_P_H +#define QNEARFIELDMANAGER_QNX_P_H + +#include "qnearfieldmanager_p.h" +#include "qnearfieldmanager.h" +#include "qnearfieldtarget.h" + +#include "qnx/qnxnfcmanager_p.h" + +QTNFC_BEGIN_NAMESPACE + +class QNearFieldManagerPrivateImpl : public QNearFieldManagerPrivate +{ + Q_OBJECT + +public: + QNearFieldManagerPrivateImpl(); + ~QNearFieldManagerPrivateImpl(); + + bool isAvailable() const; + + bool startTargetDetection(const QList<QNearFieldTarget::Type> &targetTypes); + + 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 handleMessage(QNdefMessage, QNearFieldTarget *); + void newTarget(NearFieldTarget<QNearFieldTarget> *target, const QList<QNdefMessage> &); + +private: + QList<QNearFieldTarget::Type> m_detectTargetTypes; + + int m_handlerID; + QList< QPair<QPair<int, QObject *>, QMetaMethod> > ndefMessageHandlers; + QList< QPair<QPair<int, QObject *>, QPair<QNdefFilter, QMetaMethod> > > ndefFilterHandlers; +}; + +QTNFC_END_NAMESPACE + +#endif // QNEARFIELDMANAGER_QNX_P_H diff --git a/src/nfc/qnx/qnxnfcmanager.cpp b/src/nfc/qnx/qnxnfcmanager.cpp index f5397782..92862547 100644 --- a/src/nfc/qnx/qnxnfcmanager.cpp +++ b/src/nfc/qnx/qnxnfcmanager.cpp @@ -73,6 +73,12 @@ void QNXNFCManager::unregisterForInstance() } } +void QNXNFCManager::unregisterTargetDetection(QObject *obj) +{ + //TODO another instance of the nearfieldmanager might still want to detect targets + nfc_unregister_tag_readerwriter(); +} + nfc_target_t *QNXNFCManager::getLastTarget() { return m_lastTarget; @@ -232,12 +238,11 @@ void QNXNFCManager::nfcReadWriteEvent(nfc_event_t *nfcEvent) QList<QNdefMessage> targetMessages = decodeTargetMessage(target); NearFieldTarget<QNearFieldTarget> *bbNFTarget = new NearFieldTarget<QNearFieldTarget>(this, target, targetMessages); emit targetDetected(bbNFTarget, targetMessages); -// for (int i=0; i< targetMessages.count(); i++) { -// for (int j=0; j<ndefMessageHandlers.count(); j++) { -// //ndefMessageHandlers.at(j).second.invoke(ndefMessageHandlers.at(j).first, -// // Q_ARG(const QNdefMessage&, targetMessages.at(i)), Q_ARG(NearFieldTarget*, bbNFTarget)); -// } -// } + for (int i=0; i< targetMessages.count(); i++) { + for (int j=0; j<ndefMessageHandlers.count(); j++) { + emit ndefMessage(targetMessages.at(i), reinterpret_cast<QNearFieldTarget *> (bbNFTarget)); + } + } } //void QNXNFCManager::startBTHandover() @@ -245,8 +250,9 @@ void QNXNFCManager::nfcReadWriteEvent(nfc_event_t *nfcEvent) //} -bool QNXNFCManager::startTargetDetection() +bool QNXNFCManager::startTargetDetection(const QList<QNearFieldTarget::Type> &targetTypes) { + //TODO handle the target types if (nfc_register_tag_readerwriter(TAG_TYPE_ALL) == NFC_RESULT_SUCCESS) { return true; } else { diff --git a/src/nfc/qnx/qnxnfcmanager_p.h b/src/nfc/qnx/qnxnfcmanager_p.h index 4684da56..507b6680 100644 --- a/src/nfc/qnx/qnxnfcmanager_p.h +++ b/src/nfc/qnx/qnxnfcmanager_p.h @@ -43,11 +43,10 @@ #ifndef QNXNFCMANAGER_H #define QNXNFCMANAGER_H -#include <QObject> #include "nfc/nfc_types.h" #include "nfc/nfc.h" -#include <QDebug> #include <QSocketNotifier> +#include <QDebug> #include "../qndefmessage.h" #include "../qndefrecord.h" //#include <bb/system/InvokeManager> @@ -72,6 +71,7 @@ public: static QNXNFCManager *instance(); void registerForNewInstance(); void unregisterForInstance(); + void unregisterTargetDetection(QObject *); nfc_target_t *getLastTarget(); bool isAvailable(); @@ -99,13 +99,13 @@ public Q_SLOTS: void nfcReadWriteEvent(nfc_event_t *nfcEvent); void startBTHandover(); //TODO add a parameter to only detect a special target for now we are detecting all target types - bool startTargetDetection(); + bool startTargetDetection(const QList<QNearFieldTarget::Type> &targetTypes); //void handleInvoke(const bb::system::InvokeRequest& request); Q_SIGNALS: //void llcpEvent(); - //void ndefMessage(const QNdefMessage&); - void targetDetected(QNearFieldTarget*, const QList<QNdefMessage>&); + void ndefMessage(QNdefMessage, QNearFieldTarget *); + void targetDetected(QNearFieldTarget *, const QList<QNdefMessage> &); //Not sure if this is implementable //void targetLost(); //Not available yet //void bluetoothHandover(); |