tag: Implement a raw NDEF accessor 74/30774/1
authorArron Wang <arron.wang@intel.com>
Mon, 29 Sep 2014 06:23:55 +0000 (14:23 +0800)
committerArron Wang <arron.wang@intel.com>
Tue, 25 Nov 2014 07:27:37 +0000 (15:27 +0800)
Change-Id: Id7fab24395d45502e8cdde573c40f2bd99348e27

doc/tag-api.txt
src/tag.c
test/test-tag

index 768c75f..6feb90d 100644 (file)
@@ -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]
 
index 146a87a..dd9dfe3 100644 (file)
--- 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) },
        { },
 };
 
index 935ab6f..36593ab 100755 (executable)
@@ -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"):