Changed the message transmission logic about CA_DEFAULT_ADAPTER 15/6115/6
authorhyuna0213.jo <hyuna0213.jo@samsung.com>
Mon, 21 Mar 2016 04:55:36 +0000 (13:55 +0900)
committerJon A. Cruz <jon@joncruz.org>
Thu, 24 Mar 2016 23:09:31 +0000 (23:09 +0000)
if transport adapter type is set as CA_DEFAULT_ADAPTER,
CA transmit a message via all transport adapter after generating a pdu.
but CoAP over UDP and CoAP over TCP can be used to generating pdu
according to transport type. so transport type should be determined
before generating a pdu.

Change-Id: I1cd6adda7dd060239eb40d74c36a1fa69da619f5
Signed-off-by: hyuna0213.jo <hyuna0213.jo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/6115
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/src/caconnectivitymanager.c

index 2fa717a..691e2bc 100644 (file)
@@ -259,6 +259,49 @@ CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size)
     return CAGetNetworkInformationInternal(info, size);
 }
 
+static CAResult_t CASendMessageMultiAdapter(const CAEndpoint_t *object, const void *sendMsg,
+                                            CADataType_t dataType)
+{
+    OIC_LOG(DEBUG, TAG, "CASendMessageMultipleAdapter");
+
+    CATransportAdapter_t connTypes[] = {
+            CA_ADAPTER_IP
+#ifdef LE_ADAPTER
+            ,CA_ADAPTER_GATT_BTLE
+#endif
+#ifdef EDR_ADAPTER
+            ,CA_ADAPTER_RFCOMM_BTEDR
+#endif
+#ifdef NFC_ADAPTER
+            ,CA_ADAPTER_NFC
+#endif
+#ifdef RA_ADAPTER
+            ,CA_ADAPTER_REMOTE_ACCESS
+#endif
+#ifdef TCP_ADAPTER
+            ,CA_ADAPTER_TCP
+#endif
+        };
+
+    CAEndpoint_t *cloneEp = CACloneEndpoint(object);
+    if (!cloneEp)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to clone CAEndpoint");
+        return CA_MEMORY_ALLOC_FAILED;
+    }
+
+    CAResult_t ret = CA_STATUS_OK;
+    size_t numConnTypes = sizeof(connTypes) / sizeof(connTypes[0]);
+
+    for (size_t i = 0; i < numConnTypes && ret == CA_STATUS_OK; i++)
+    {
+        cloneEp->adapter = connTypes[i];
+        ret = CADetachSendMessage(cloneEp, sendMsg, dataType);
+    }
+    CAFreeEndpoint(cloneEp);
+    return ret;
+}
+
 CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
 {
     OIC_LOG(DEBUG, TAG, "CASendRequest");
@@ -268,7 +311,15 @@ CAResult_t CASendRequest(const CAEndpoint_t *object, const CARequestInfo_t *requ
         return CA_STATUS_NOT_INITIALIZED;
     }
 
-    return CADetachSendMessage(object, requestInfo, CA_REQUEST_DATA);
+    if (requestInfo && requestInfo->isMulticast &&
+            (object->adapter == CA_DEFAULT_ADAPTER || object->adapter == CA_ALL_ADAPTERS))
+    {
+        return CASendMessageMultiAdapter(object, requestInfo, CA_REQUEST_DATA);
+    }
+    else
+    {
+        return CADetachSendMessage(object, requestInfo, CA_REQUEST_DATA);
+    }
 }
 
 CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
@@ -280,7 +331,15 @@ CAResult_t CASendResponse(const CAEndpoint_t *object, const CAResponseInfo_t *re
         return CA_STATUS_NOT_INITIALIZED;
     }
 
-    return CADetachSendMessage(object, responseInfo, CA_RESPONSE_DATA);
+    if (responseInfo && responseInfo->isMulticast &&
+            (object->adapter == CA_DEFAULT_ADAPTER || object->adapter == CA_ALL_ADAPTERS))
+    {
+        return CASendMessageMultiAdapter(object, responseInfo, CA_RESPONSE_DATA);
+    }
+    else
+    {
+        return CADetachSendMessage(object, responseInfo, CA_RESPONSE_DATA);
+    }
 }
 
 CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork)