remove previous received data from ReceiveQueue for gatt server.
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 14 Mar 2016 08:12:47 +0000 (17:12 +0900)
committerJon A. Cruz <jon@joncruz.org>
Thu, 24 Mar 2016 23:11:44 +0000 (23:11 +0000)
and modified to adjust destroy thread.

Change-Id: I39043ae19527160a4f76d808a4a8e8b70d055f8a
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5843
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
(cherry picked from commit 2a7b046b63032c419db682fa11ed2ad2bf84081e)
Reviewed-on: https://gerrit.iotivity.org/gerrit/6135
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c

index 6e9eae8..f181dd9 100644 (file)
@@ -401,6 +401,15 @@ static void CALEDataDestroyer(void *data, uint32_t size);
 static void CALERemoveSendQueueData(CAQueueingThread_t *queueHandle,
                                     ca_mutex mutex,
                                     const char* address);
+
+/**
+ * remove all received data of data list from receive queue.
+ *
+ * @param[in] dataInfoList   received data list to remove for client / server.
+ * @param[in] address        target address to remove data in queue.
+ */
+static void CALERemoveReceiveQueueData(u_arraylist_t *dataInfoList,
+                                       const char* address);
 #endif
 
 static CAResult_t CAInitLEServerQueues()
@@ -1643,13 +1652,15 @@ static CAResult_t CALEAdapterGattServerStart()
 static CAResult_t CALEAdapterGattServerStop()
 {
 #ifndef SINGLE_THREAD
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEAdapterGattServerStop");
+
+    CAResult_t result = CAStopLEGattServer();
     ca_mutex_lock(g_bleServerSendDataMutex);
-    CAResult_t result = CAQueueingThreadStop(g_bleServerSendQueueHandle);
-    ca_mutex_unlock(g_bleServerSendDataMutex);
     if (CA_STATUS_OK == result)
     {
-        result = CAStopLEGattServer();
+        result = CAQueueingThreadStop(g_bleServerSendQueueHandle);
     }
+    ca_mutex_unlock(g_bleServerSendDataMutex);
 
     return result;
 #else
@@ -1689,13 +1700,12 @@ static CAResult_t CALEAdapterGattClientStart()
 static CAResult_t CALEAdapterGattClientStop()
 {
 #ifndef SINGLE_THREAD
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEAdapterGattClientStop");
+    CAStopLEGattClient();
+
     ca_mutex_lock(g_bleClientSendDataMutex);
     CAResult_t result = CAQueueingThreadStop(g_bleClientSendQueueHandle);
     ca_mutex_unlock(g_bleClientSendDataMutex);
-    if (CA_STATUS_OK == result)
-    {
-        CAStopLEGattClient();
-    }
 
     return result;
 #else
@@ -2211,23 +2221,12 @@ static void CALEConnectionStateChangedCb(CATransportAdapter_t adapter, const cha
 #ifndef SINGLE_THREAD
         if(g_bleClientSenderInfo)
         {
-            CABLESenderInfo_t *senderInfo = NULL;
-            uint32_t senderIndex = 0;
-
-            if(CA_STATUS_OK == CALEGetSenderInfo(address, g_bleClientSenderInfo, &senderInfo,
-                                                   &senderIndex))
-            {
-                u_arraylist_remove(g_bleClientSenderInfo, senderIndex);
-                OICFree(senderInfo->defragData);
-                OICFree(senderInfo->remoteEndpoint);
-                OICFree(senderInfo);
+            CALERemoveReceiveQueueData(g_bleClientSenderInfo, address);
+        }
 
-                OIC_LOG(DEBUG, CALEADAPTER_TAG, "SenderInfo is removed for disconnection");
-            }
-            else
-            {
-                OIC_LOG(DEBUG, CALEADAPTER_TAG, "SenderInfo doesn't exist");
-            }
+        if(g_bleServerSenderInfo)
+        {
+            CALERemoveReceiveQueueData(g_bleServerSenderInfo, address);
         }
 
         // remove data of send queue.
@@ -2631,4 +2630,30 @@ static void CALERemoveSendQueueData(CAQueueingThread_t *queueHandle, ca_mutex mu
     }
     ca_mutex_unlock(mutex);
 }
+
+static void CALERemoveReceiveQueueData(u_arraylist_t *dataInfoList, const char* address)
+{
+    OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALERemoveReceiveQueueData");
+
+    VERIFY_NON_NULL_VOID(dataInfoList, CALEADAPTER_TAG, "dataInfoList");
+    VERIFY_NON_NULL_VOID(address, CALEADAPTER_TAG, "address");
+
+    CABLESenderInfo_t *senderInfo = NULL;
+    uint32_t senderIndex = 0;
+
+    if(CA_STATUS_OK == CALEGetSenderInfo(address, dataInfoList, &senderInfo,
+                                         &senderIndex))
+    {
+        u_arraylist_remove(dataInfoList, senderIndex);
+        OICFree(senderInfo->defragData);
+        OICFree(senderInfo->remoteEndpoint);
+        OICFree(senderInfo);
+
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "SenderInfo is removed for disconnection");
+    }
+    else
+    {
+        OIC_LOG(DEBUG, CALEADAPTER_TAG, "SenderInfo doesn't exist");
+    }
+}
 #endif