replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / caedradapter.c
index a905e2f..4481499 100644 (file)
@@ -93,8 +93,8 @@ void CAAdapterTerminateQueues();
 void CAAdapterDataSendHandler(void *context);
 void CAAdapterDataReceiverHandler(void *context);
 CAResult_t CAAdapterStopQueue();
-void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t dataLength,
-                       uint32_t *sentLength);
+CAResult_t CAAdapterRecvData(const char *remoteAddress, const uint8_t *data,
+                             uint32_t dataLength, uint32_t *sentLength);
 void CAEDRNotifyNetworkStatus(CANetworkStatus_t status);
 void CAEDROnNetworkStatusChanged(void *context);
 CAResult_t CAAdapterSendData(const char *remoteAddress, const char *serviceUUID,
@@ -634,19 +634,19 @@ CAResult_t CAAdapterStopQueue()
     return CA_STATUS_OK;
 }
 
-void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t dataLength,
-                       uint32_t *sentLength)
+CAResult_t CAAdapterRecvData(const char *remoteAddress, const uint8_t *data,
+                             uint32_t dataLength, uint32_t *sentLength)
 {
     if (false == g_adapterState)
     {
         OIC_LOG_V(ERROR, TAG, "Bluetooth adapter is disabled!");
         *sentLength = 0;
-        return;
+        return CA_ADAPTER_NOT_ENABLED;
     }
 
     // Input validation
-    VERIFY_NON_NULL_VOID(data, TAG, "Data is null");
-    VERIFY_NON_NULL_VOID(sentLength, TAG, "Sent data length holder is null");
+    VERIFY_NON_NULL(data, TAG, "Data is null");
+    VERIFY_NON_NULL(sentLength, TAG, "Sent data length holder is null");
 
     // Create remote endpoint
     CAEndpoint_t *remoteEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS,
@@ -655,7 +655,7 @@ void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t
     if (NULL == remoteEndpoint)
     {
         OIC_LOG(ERROR, TAG, "Failed to create remote endpoint !");
-        return;
+        return CA_STATUS_FAILED;
     }
 
     // Add message to data queue
@@ -665,6 +665,8 @@ void CAAdapterRecvData(const char *remoteAddress, const uint8_t *data, uint32_t
 
     // Free remote endpoint
     CAFreeEndpoint(remoteEndpoint);
+
+    return CA_STATUS_OK;
 }
 
 void CAEDRErrorHandler(const char *remoteAddress, const uint8_t *data,
@@ -766,6 +768,18 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status)
     else
     {
         g_adapterState = false;
+
+        CAResult_t res = CAQueueingThreadClearData(g_sendQueueHandle);
+        if (res != CA_STATUS_OK)
+        {
+            OIC_LOG_V(ERROR, TAG, "CAQueueingThreadClearData failed[%d]", res);
+        }
+
+        res = CAQueueingThreadClearData(g_recvQueueHandle);
+        if (res != CA_STATUS_OK)
+        {
+            OIC_LOG_V(ERROR, TAG, "CAQueueingThreadClearData failed[%d]", res);
+        }
     }
 
     // Notify to upper layer
@@ -776,7 +790,7 @@ void CAEDRNotifyNetworkStatus(CANetworkStatus_t status)
         if (NULL != event)
         {
             if (CA_STATUS_OK != ca_thread_pool_add_task(g_edrThreadPool,
-                                                        CAEDROnNetworkStatusChanged,event))
+                                                        CAEDROnNetworkStatusChanged, event, NULL))
             {
                 OIC_LOG(ERROR, TAG, "Failed to create threadpool!");
                 return;