diff options
author | Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com> | 2012-05-18 11:58:58 +0300 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2012-05-25 15:30:35 +0200 |
commit | 1e010b8b56133949b4b07546d4c7b996e2004d8a (patch) | |
tree | 06cfba5b9bf31335b33860bd56872aa83146babc /src/tag.c | |
parent | b8105b873ba270efc2b6fb24217c7794d0d0f25a (diff) | |
download | neard-1e010b8b56133949b4b07546d4c7b996e2004d8a.tar.gz neard-1e010b8b56133949b4b07546d4c7b996e2004d8a.tar.bz2 neard-1e010b8b56133949b4b07546d4c7b996e2004d8a.zip |
tag: Dbus reply to tag write request
The tag writing operation is asynchronous, and any request received while
one of them is currently running will be rejected.
Diffstat (limited to 'src/tag.c')
-rw-r--r-- | src/tag.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -68,6 +68,8 @@ struct near_tag { uint16_t max_ndef_size; uint16_t c_apdu_max_size; } t4; + + DBusMessage *write_msg; /* Pending write message */ }; static DBusConnection *connection = NULL; @@ -225,7 +227,28 @@ static DBusMessage *set_property(DBusConnection *conn, static void write_cb(uint32_t adapter_idx, uint32_t target_idx, int status) { + struct near_tag *tag; + DBusConnection *conn; + DBusMessage *reply; + DBG("Write status %d", status); + + conn = near_dbus_get_connection(); + tag = near_tag_get_tag(adapter_idx, target_idx); + + if (conn == NULL || tag == NULL) + return; + + if (status != 0) { + reply = __near_error_failed(tag->write_msg, EINVAL); + if (reply != NULL) + g_dbus_send_message(conn, reply); + } else { + g_dbus_send_reply(conn, tag->write_msg, DBUS_TYPE_INVALID); + } + + dbus_message_unref(tag->write_msg); + tag->write_msg = NULL; } static DBusMessage *write_ndef(DBusConnection *conn, @@ -237,10 +260,15 @@ static DBusMessage *write_ndef(DBusConnection *conn, DBG("conn %p", conn); + if (tag->write_msg == NULL) + return __near_error_in_progress(msg); + ndef = __ndef_build_from_message(msg); if (ndef == NULL) return __near_error_failed(msg, EINVAL); + tag->write_msg = dbus_message_ref(msg); + /* Add NDEF header information depends upon tag type */ switch (tag->type) { case NFC_PROTO_JEWEL: @@ -319,6 +347,9 @@ static DBusMessage *write_ndef(DBusConnection *conn, return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); fail: + dbus_message_unref(tag->write_msg); + tag->write_msg = NULL; + return __near_error_failed(msg, ENOMEM); } |