summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArron Wang <arron.wang@intel.com>2014-09-29 14:23:55 +0800
committerArron Wang <arron.wang@intel.com>2014-11-25 15:27:37 +0800
commitebc4849a0c25ebdbd4aa71e130754ee2668f365c (patch)
tree5c6cce5bade270f8878414f13d94457e1aab0406
parent947a28f4000b4638316f30f88f124d87fbdda218 (diff)
downloadneard-ebc4849a0c25ebdbd4aa71e130754ee2668f365c.tar.gz
neard-ebc4849a0c25ebdbd4aa71e130754ee2668f365c.tar.bz2
neard-ebc4849a0c25ebdbd4aa71e130754ee2668f365c.zip
tag: Implement a raw NDEF accessor
Change-Id: Id7fab24395d45502e8cdde573c40f2bd99348e27
-rw-r--r--doc/tag-api.txt3
-rw-r--r--src/tag.c29
-rwxr-xr-xtest/test-tag8
3 files changed, 38 insertions, 2 deletions
diff --git a/doc/tag-api.txt b/doc/tag-api.txt
index 768c75f..6feb90d 100644
--- a/doc/tag-api.txt
+++ b/doc/tag-api.txt
@@ -20,6 +20,9 @@ Method void Write(dict attributes)
org.neard.Error.InvalidArguments
org.neard.Error.InProgress
+ array{byte} GetRawNDEF()
+
+ Return the tag's NDEF as a raw bytes stream.
Properties string Type [readonly]
diff --git a/src/tag.c b/src/tag.c
index 146a87a..dd9dfe3 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -461,9 +461,38 @@ fail:
return __near_error_failed(msg, ENOMEM);
}
+static DBusMessage *get_raw_ndef(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct near_tag *tag = data;
+ DBusMessage *reply;
+ DBusMessageIter iter, array;
+
+ DBG("");
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_BYTE_AS_STRING,
+ &array);
+
+ __near_ndef_append_records(&array, tag->records);
+
+ dbus_message_iter_close_container(&iter, &array);
+
+ return reply;
+}
+
static const GDBusMethodTable tag_methods[] = {
{ GDBUS_ASYNC_METHOD("Write", GDBUS_ARGS({"attributes", "a{sv}"}),
NULL, write_ndef) },
+ { GDBUS_METHOD("GetRawNDEF",
+ NULL, GDBUS_ARGS({"NDEF", "ay"}),
+ get_raw_ndef) },
{ },
};
diff --git a/test/test-tag b/test/test-tag
index 935ab6f..36593ab 100755
--- a/test/test-tag
+++ b/test/test-tag
@@ -6,10 +6,10 @@ import neardutils
bus = dbus.SystemBus()
-def extract_list(list):
+def extract_ndef(list):
val = "["
for i in list:
- val += " " + str(i)
+ val += " 0x%x" % i
val += " ]"
return val
@@ -86,6 +86,10 @@ if (sys.argv[1] == "dump"):
else:
neardutils.dump_all_records(sys.argv[2])
+ tag = neardutils.find_tag(sys.argv[2])
+ raw_ndef = tag.GetRawNDEF()
+ print " Raw NDEF = %s" % (extract_ndef(raw_ndef))
+
sys.exit(0)
if (sys.argv[1] == "write"):