Use the right way to trigger tag discovered callback 45/20945/1
authorArron Wang <arron.wang@intel.com>
Mon, 12 May 2014 08:57:15 +0000 (16:57 +0800)
committerArron Wang <arron.wang@intel.com>
Wed, 14 May 2014 06:41:45 +0000 (14:41 +0800)
Due to we need to pass the tag info to tag discovered callback
function, we need to read the tag first, to avoid invoke tag
read completed callback, we need to use a flag for tag discovered

Change-Id: I4786eb76c3cef1d681079bb3998b2d8654d15819

client/net_nfc_neard.c

index cfad3c6..25df3dc 100644 (file)
@@ -62,6 +62,7 @@ static data_s *rawNDEF;
 static net_nfc_target_info_s *target_info;
 static net_nfc_target_handle_s *target_handle;
 static net_nfc_connection_handover_info_s *handover_info;
+static bool read_flag;
 
 static net_nfc_error_e _convert_error_code(errorCode_t error_code)
 {
@@ -313,6 +314,8 @@ static void _tag_found_cb(const char *tagName, void *user_data)
                NFC_DBG("Failed to get rawNDEF");
                return;
        }
+
+       read_flag = true;
 }
 
 static void _tag_lost_cb(const char *tagName, void *user_data)
@@ -441,8 +444,12 @@ static void _read_completed_cb(GVariant *ret, void *user_data)
        result = net_nfc_util_convert_rawdata_to_ndef_message(
                                                rawNDEF, ndef);
 exit:
-       if (client_cb.tag_discovered_cb != NULL)
-               client_cb.tag_discovered_cb(target_info, client_cb.tag_discovered_ud);
+       if (client_cb.tag_discovered_cb != NULL && read_flag == true) {
+               client_cb.tag_discovered_cb(target_info,
+                                       client_cb.tag_discovered_ud);
+               read_flag = false;
+               return;
+       }
 
        if (client_cb.ndef_read_cb != NULL) {
                client_cb.ndef_read_cb(result, ndef, client_cb.ndef_read_ud);