/*************************************************************************** ** ** 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 #include "qnearfieldtarget_qnx_p.h" #include #include "qndeffilter.h" #include "qndefrecord.h" QT_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; qQNXNFCDebug() << "Nearfieldmanager created"; } QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl() { //First, remove all ndef message handlers QNXNFCManager::instance()->updateNdefFilters(QList(), this); QNXNFCManager::instance()->unregisterForInstance(); } bool QNearFieldManagerPrivateImpl::isAvailable() const { return QNXNFCManager::instance()->isAvailable(); } bool QNearFieldManagerPrivateImpl::startTargetDetection() { qQNXNFCDebug() << "Starting targetdetection in nearfieldmanager"; if (QNXNFCManager::instance()->startTargetDetection()) { connect(QNXNFCManager::instance(), SIGNAL(targetDetected(QNearFieldTarget*,QList)), this, SLOT(newTarget(QNearFieldTarget*,QList))); return true; } else { qWarning()<)), this, SLOT(newTarget(NearFieldTarget*,QList))); QNXNFCManager::instance()->unregisterTargetDetection(this); } int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(QObject *object, const QMetaMethod &method) { QList filterList; filterList += "*"; QNXNFCManager::instance()->updateNdefFilters(filterList, this); ndefMessageHandlers.append(QPair, QMetaMethod>(QPair(m_handlerID, object), method)); //Returns the handler ID and increments it afterwards return m_handlerID++; } int QNearFieldManagerPrivateImpl::registerNdefMessageHandler(const QNdefFilter &filter, QObject *object, const QMetaMethod &method) { //If no record is set in the filter, we ignore the filter if (filter.recordCount()==0) return registerNdefMessageHandler(object, method); ndefFilterHandlers.append(QPair, QPair > (QPair(m_handlerID, object), QPair(filter, method))); updateNdefFilter(); return m_handlerID++; } bool QNearFieldManagerPrivateImpl::unregisterNdefMessageHandler(int handlerId) { for (int i=0; i message.count()) continue; int j=0; for (j = 0; j < filter.recordCount();) { if (message.at(j).typeNameFormat() != filter.recordAt(j).typeNameFormat || message.at(j).type() != filter.recordAt(j).type ) { break; } j++; } if (j == filter.recordCount()) ndefFilterHandlers.at(i).second.second.invoke(ndefFilterHandlers.at(i).first.second, Q_ARG(QNdefMessage, message), Q_ARG(QNearFieldTarget*, target)); } } void QNearFieldManagerPrivateImpl::newTarget(QNearFieldTarget *target, const QList &messages) { Q_UNUSED(messages) qQNXNFCDebug() << "New Target"; emit targetDetected(target); } void QNearFieldManagerPrivateImpl::updateNdefFilter() { qQNXNFCDebug() << "Updating NDEF filter"; QList filterList; if (ndefMessageHandlers.size() > 0) { ///SUbscribe for all ndef messages filterList += "*"; QNXNFCManager::instance()->updateNdefFilters(filterList, this); } else if (ndefFilterHandlers.size() > 0){ for (int i = 0; i < ndefFilterHandlers.count(); i++) { QByteArray filter = "ndef://" + QByteArray::number(ndefFilterHandlers.at(i).second.first.recordAt(0).typeNameFormat) + "/" + ndefFilterHandlers.at(i).second.first.recordAt(0).type; if (!filterList.contains(filter)) filterList.append(filter); } QNXNFCManager::instance()->updateNdefFilters(filterList, this); } else { //Remove all ndef message handlers for this object QNXNFCManager::instance()->updateNdefFilters(filterList, this); } } QT_END_NAMESPACE