summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-11-13 01:47:39 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2013-11-13 02:06:44 +0100
commit4f8e947730745be87e89fc59c6682ac1a9b6ce5e (patch)
tree17a21052df95217a5fd3eb592a921f0bcdd87b61
parent8586946aeb491d1b300869dc91b6ad851eed42b2 (diff)
downloadneard-4f8e947730745be87e89fc59c6682ac1a9b6ce5e.tar.gz
neard-4f8e947730745be87e89fc59c6682ac1a9b6ce5e.tar.bz2
neard-4f8e947730745be87e89fc59c6682ac1a9b6ce5e.zip
agent: Only print matching record from NDEF agent's GetNDEF
There is no need to print all records from the NDEF. With each matching record, the record path and the NDEF raw data is pushed back to the agent.
-rw-r--r--src/agent.c32
-rwxr-xr-xtest/ndef-agent7
2 files changed, 10 insertions, 29 deletions
diff --git a/src/agent.c b/src/agent.c
index 34d9566..d5c0b79 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -101,23 +101,6 @@ static void ndef_agent_disconnect(DBusConnection *conn, void *user_data)
g_hash_table_remove(ndef_app_hash, agent->record_type);
}
-static void append_record_path(DBusMessageIter *iter, void *user_data)
-{
- GList *records = user_data, *list;
- struct near_ndef_record *record;
- char *path;
-
- for (list = records; list; list = list->next) {
- record = list->data;
-
- path = __near_ndef_record_get_path(record);
- if (!path)
- continue;
-
- dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &path);
- }
-}
-
static void append_ndef(DBusMessageIter *iter, void *user_data)
{
GList *records = user_data;
@@ -126,10 +109,12 @@ static void append_ndef(DBusMessageIter *iter, void *user_data)
}
static void ndef_agent_push_records(struct near_ndef_agent *agent,
+ struct near_ndef_record *record,
GList *records)
{
DBusMessageIter iter, dict;
DBusMessage *message;
+ char *path;
DBG("");
@@ -144,11 +129,13 @@ static void ndef_agent_push_records(struct near_ndef_agent *agent,
if (!message)
return;
+ path = __near_ndef_record_get_path(record);
+
dbus_message_iter_init_append(message, &iter);
near_dbus_dict_open(&iter, &dict);
- near_dbus_dict_append_array(&dict, "Records",
- DBUS_TYPE_STRING, append_record_path, records);
+ near_dbus_dict_append_basic(&dict, "Record",
+ DBUS_TYPE_STRING, &path);
near_dbus_dict_append_array(&dict, "NDEF",
DBUS_TYPE_BYTE, append_ndef, records);
near_dbus_dict_close(&iter, &dict);
@@ -180,13 +167,8 @@ void __near_agent_ndef_parse_records(GList *records)
agent = g_hash_table_lookup(ndef_app_hash, type);
if (agent)
- break;
+ ndef_agent_push_records(agent, record, records);
}
-
- if (!agent)
- return;
-
- ndef_agent_push_records(agent, records);
}
static int ndef_register(const char *sender, const char *path,
diff --git a/test/ndef-agent b/test/ndef-agent
index 2464c82..68bd270 100755
--- a/test/ndef-agent
+++ b/test/ndef-agent
@@ -19,11 +19,10 @@ class NDEFAgent(dbus.service.Object):
in_signature='a{sv}',
out_signature='')
def GetNDEF(self, fields):
- print "GetNDEF %s"
+ print "GetNDEF"
- if fields.has_key("Records"):
- for path in fields["Records"]:
- print "Record path %s" % (path)
+ if fields.has_key("Record"):
+ print "Record path %s" % (fields["Record"])
if fields.has_key("NDEF"):
val = "["