summaryrefslogtreecommitdiff
path: root/src/nfc/qnearfieldmanager_android.cpp
diff options
context:
space:
mode:
authorStephan Binner <stephan.binner@basyskom.com>2015-03-24 15:46:55 +0100
committerStephan Binner <stephan.binner@basyskom.com>2015-04-02 11:58:09 +0000
commita6eada4aec4f029bce178845755fc64f74370c0c (patch)
tree192dd8ccbce07317e5b1b5ad19efb8f682ced79b /src/nfc/qnearfieldmanager_android.cpp
parent920542ffbb1b97c8ac22abb372d0ae042066ebd2 (diff)
downloadqtconnectivity-a6eada4aec4f029bce178845755fc64f74370c0c.tar.gz
Fix implementation of and improve NdefFilter usage
Updated QML docu: describe typeNameFormat, defaults of min/max/orderMatch Removed mention of "both minimum and maximum -1 means matches any numbers": it is unimplemented and QNdefFilter::Record uses unsigned int for min/max Adapt filter logic from QNearFieldManagerPrivateVirtualBase for Android and QNX backends to add support for orderMatch, minimum and maximum properties Adapt filters and examples to use empty type as wildcard (eg Mime records) Change-Id: Id9d51514bb593bd38c3fed89b612af54dffceff0 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/nfc/qnearfieldmanager_android.cpp')
-rw-r--r--src/nfc/qnearfieldmanager_android.cpp59
1 files changed, 49 insertions, 10 deletions
diff --git a/src/nfc/qnearfieldmanager_android.cpp b/src/nfc/qnearfieldmanager_android.cpp
index 7cb1829f..d1434840 100644
--- a/src/nfc/qnearfieldmanager_android.cpp
+++ b/src/nfc/qnearfieldmanager_android.cpp
@@ -88,6 +88,12 @@ void QNearFieldManagerPrivateImpl::handlerTargetLost(QNearFieldTarget *target)
m_idToTarget.remove(m_idToTarget.key(target));
}
+struct VerifyRecord
+{
+ QNdefFilter::Record filterRecord;
+ unsigned int count;
+};
+
void QNearFieldManagerPrivateImpl::handlerNdefMessageRead(const QNdefMessage &message, const QNearFieldTarget::RequestId &id)
{
QNearFieldTarget *target = m_idToTarget.value(id);
@@ -98,20 +104,53 @@ void QNearFieldManagerPrivateImpl::handlerNdefMessageRead(const QNdefMessage &me
//For message handlers that specified a filter
for (int i = 0; i < ndefFilterHandlers.count(); ++i) {
+ bool matched = true;
+
QNdefFilter filter = ndefFilterHandlers.at(i).second.first;
- if (filter.recordCount() > message.count())
- continue;
-
- int j;
- for (j = 0; j < filter.recordCount();) {
- if (message.at(j).typeNameFormat() != filter.recordAt(j).typeNameFormat
- || message.at(j).type() != filter.recordAt(j).type ) {
- break;
+
+ QList<VerifyRecord> filterRecords;
+ for (int j = 0; j < filter.recordCount(); ++j) {
+ VerifyRecord vr;
+ vr.count = 0;
+ vr.filterRecord = filter.recordAt(j);
+
+ filterRecords.append(vr);
+ }
+
+ foreach (const QNdefRecord &record, message) {
+ for (int j = 0; matched && (j < filterRecords.count()); ++j) {
+ VerifyRecord &vr = filterRecords[j];
+
+ if (vr.filterRecord.typeNameFormat == record.typeNameFormat() &&
+ ( vr.filterRecord.type == record.type() ||
+ vr.filterRecord.type.isEmpty()) ) {
+ ++vr.count;
+ break;
+ } else {
+ if (filter.orderMatch()) {
+ if (vr.filterRecord.minimum <= vr.count &&
+ vr.count <= vr.filterRecord.maximum) {
+ continue;
+ } else {
+ matched = false;
+ }
+ }
+ }
}
- ++j;
}
- if (j == filter.recordCount())
+
+ for (int j = 0; matched && (j < filterRecords.count()); ++j) {
+ const VerifyRecord &vr = filterRecords.at(j);
+
+ if (vr.filterRecord.minimum <= vr.count && vr.count <= vr.filterRecord.maximum)
+ continue;
+ else
+ matched = false;
+ }
+
+ if (matched) {
ndefFilterHandlers.at(i).second.second.invoke(ndefFilterHandlers.at(i).first.second, Q_ARG(QNdefMessage, message), Q_ARG(QNearFieldTarget*, target));
+ }
}
}