merge the duplicated function in camessagehandler
authorjw0213.jung <jw0213.jung@samsung.com>
Mon, 11 Jan 2016 05:28:40 +0000 (14:28 +0900)
committerJon A. Cruz <jonc@osg.samsung.com>
Wed, 13 Jan 2016 07:30:58 +0000 (07:30 +0000)
There were two functions separately for sending request/response message
although they had almost same codes. So I merged it.

Change-Id: Iecaf407d765f04bbffea8b98fbe22b06fa540434
Signed-off-by: jw0213.jung <jw0213.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4781
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
resource/csdk/connectivity/inc/camessagehandler.h
resource/csdk/connectivity/src/caconnectivitymanager.c
resource/csdk/connectivity/src/camessagehandler.c

index c84836c..1bd51a0 100644 (file)
@@ -61,31 +61,15 @@ extern "C"
 #endif
 
 /**
- * Detaches control from the caller for sending unicast request.
+ * Detaches control from the caller for sending message.
  * @param[in] endpoint    endpoint information where the data has to be sent.
- * @param[in] request     request that needs to be sent.
+ * @param[in] sendMsg     message that needs to be sent.
+ * @param[in] dataType    type of the message(request/response).
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
-CAResult_t CADetachRequestMessage(const CAEndpoint_t *endpoint,
-                                  const CARequestInfo_t *request);
-
-/**
- * Detaches control from the caller for sending multicast request.
- * @param[in] object     Group endpoint information where the data has to be sent.
- * @param[in] request    request that needs to be sent.
- * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
- */
-CAResult_t CADetachRequestToAllMessage(const CAEndpoint_t *object,
-                                       const CARequestInfo_t *request);
-
-/**
- * Detaches control from the caller for sending response.
- * @param[in] endpoint    endpoint information where the data has to be sent.
- * @param[in] response    response that needs to be sent.
- * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
- */
-CAResult_t CADetachResponseMessage(const CAEndpoint_t *endpoint,
-                                   const CAResponseInfo_t *response);
+CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint,
+                               const void *sendMsg,
+                               CADataType_t dataType);
 
 /**
  * Detaches control from the caller for sending request.
index 8cf6a0d..3ecb068 100644 (file)
@@ -259,16 +259,16 @@ CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
     return CAGetNetworkInformationInternal(info, size);
 }
 
-CAResult_t CASendRequest(const CAEndpoint_t *object,const CARequestInfo_t *requestInfo)
+CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
 {
-    OIC_LOG(DEBUG, TAG, "CASendGetRequest");
+    OIC_LOG(DEBUG, TAG, "CASendRequest");
 
     if(!g_isInitialized)
     {
         return CA_STATUS_NOT_INITIALIZED;
     }
 
-    return CADetachRequestMessage(object, requestInfo);
+    return CADetachSendMessage(object, requestInfo, CA_REQUEST_DATA);
 }
 
 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
@@ -280,7 +280,7 @@ CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *re
         return CA_STATUS_NOT_INITIALIZED;
     }
 
-    return CADetachResponseMessage(object, responseInfo);
+    return CADetachSendMessage(object, responseInfo, CA_RESPONSE_DATA);
 }
 
 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork)
index b101098..5aa0f1b 100644 (file)
@@ -941,10 +941,11 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen
     return cadata;
 }
 
-CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInfo_t *request)
+CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg,
+                               CADataType_t dataType)
 {
-    VERIFY_NON_NULL(object, TAG, "object");
-    VERIFY_NON_NULL(request, TAG, "request");
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint");
+    VERIFY_NON_NULL(sendMsg, TAG, "sendMsg");
 
     if (false == CAIsSelectedNetworkAvailable())
     {
@@ -960,7 +961,7 @@ CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInf
     }
 #endif /* ARDUINO */
 
-    CAData_t *data = CAPrepareSendData(object, request, CA_REQUEST_DATA);
+    CAData_t *data = CAPrepareSendData(endpoint, sendMsg, dataType);
     if(!data)
     {
         OIC_LOG(ERROR, TAG, "CAPrepareSendData failed");
@@ -972,15 +973,16 @@ CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInf
     if(CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, TAG, "CAProcessSendData failed");
+        CADestroyData(data, sizeof(CAData_t));
         return result;
     }
 
     CADestroyData(data, sizeof(CAData_t));
 #else
 #ifdef WITH_BWT
-    if (CA_ADAPTER_GATT_BTLE != object->adapter
+    if (CA_ADAPTER_GATT_BTLE != endpoint->adapter
 #ifdef TCP_ADAPTER
-            && CA_ADAPTER_TCP != object->adapter
+            && CA_ADAPTER_TCP != endpoint->adapter
 #endif
             )
     {
@@ -1003,66 +1005,7 @@ CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInf
     {
         CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
     }
-#endif
-
-    return CA_STATUS_OK;
-}
-
-CAResult_t CADetachResponseMessage(const CAEndpoint_t *object,
-                                   const CAResponseInfo_t *response)
-{
-    VERIFY_NON_NULL(object, TAG, "object");
-    VERIFY_NON_NULL(response, TAG, "response");
-
-    if (false == CAIsSelectedNetworkAvailable())
-    {
-        return CA_STATUS_FAILED;
-    }
-
-    CAData_t *data = CAPrepareSendData(object, response, CA_RESPONSE_DATA);
-    if(!data)
-    {
-        OIC_LOG(ERROR, TAG, "CAPrepareSendData failed");
-        return CA_MEMORY_ALLOC_FAILED;
-    }
-
-#ifdef SINGLE_THREAD
-    CAResult_t result = CAProcessSendData(data);
-    if(result != CA_STATUS_OK)
-    {
-        OIC_LOG(ERROR, TAG, "CAProcessSendData failed");
-        return result;
-    }
-
-    CADestroyData(data, sizeof(CAData_t));
-#else
-#ifdef WITH_BWT
-    if (CA_ADAPTER_GATT_BTLE != object->adapter
-#ifdef TCP_ADAPTER
-            && CA_ADAPTER_TCP != object->adapter
-#endif
-            )
-    {
-        // send block data
-        CAResult_t res = CASendBlockWiseData(data);
-        if(CA_NOT_SUPPORTED == res)
-        {
-            OIC_LOG(DEBUG, TAG, "normal msg will be sent");
-            CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
-            return CA_STATUS_OK;
-        }
-        else
-        {
-            CADestroyData(data, sizeof(CAData_t));
-        }
-        return res;
-    }
-    else
-#endif
-    {
-        CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
-    }
-#endif
+#endif /* SINGLE_THREAD */
 
     return CA_STATUS_OK;
 }