#include "caraadapter.h"
#endif
-#define TAG "CA_INTRFC_CNTRLR"
-#ifdef RA_ADAPTER
-#include "caraadapter.h"
+#ifdef TCP_ADAPTER
+#include "catcpadapter.h"
#endif
+#define TAG "CA_INTRFC_CNTRLR"
#define CA_MEMORY_ALLOC_CHECK(arg) {if (arg == NULL) \
{OIC_LOG(ERROR, TAG, "memory error");goto memory_error_exit;} }
-#ifdef RA_ADAPTER
+#ifdef TCP_ADAPTER
+#define CA_TRANSPORT_TYPE_NUM 5
+#elif RA_ADAPTER
#define CA_TRANSPORT_TYPE_NUM 4
#else
#define CA_TRANSPORT_TYPE_NUM 3
case CA_ADAPTER_RFCOMM_BTEDR:
return 2;
- #ifdef RA_ADAPTER
+#ifdef RA_ADAPTER
case CA_ADAPTER_REMOTE_ACCESS:
return 3;
- #endif
+#endif
+
+#ifdef TCP_ADAPTER
+ case CA_ADAPTER_TCP:
+ return 4;
+#endif
default:
break;
}
#endif
-static void CAReceivedPacketCallback(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen)
+static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
+ const void *data, uint32_t dataLen)
{
OIC_LOG(DEBUG, TAG, "IN");
- // Call the callback.
if (g_networkPacketReceivedCallback != NULL)
{
- g_networkPacketReceivedCallback(endpoint, data, dataLen);
+ g_networkPacketReceivedCallback(sep, data, dataLen);
}
else
{
- OICFree(data);
-
OIC_LOG(ERROR, TAG, "network packet received callback is NULL!");
}
handle);
#endif /* RA_ADAPTER */
-
+#ifdef TCP_ADAPTER
+ CAInitializeTCP(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
+ CAAdapterErrorHandleCallback, handle);
+#endif /* TCP_ADAPTER */
}
void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback)
{
OIC_LOG(DEBUG, TAG, "IN");
- CAResult_t res = CA_STATUS_FAILED;
-
if (endpoint == NULL)
{
OIC_LOG(DEBUG, TAG, "Invalid endpoint");
return CA_STATUS_INVALID_PARAM;
}
- uint32_t sentDataLen = 0;
+ int32_t sentDataLen = 0;
if (g_adapterHandler[index].sendData != NULL)
{
sentDataLen = g_adapterHandler[index].sendData(endpoint, data, length);
}
- if (sentDataLen != -1)
+ if (sentDataLen != (int)length)
{
- res = CA_STATUS_OK;
+ OIC_LOG(ERROR, TAG, "error in sending data. Error will be reported in adapter");
+#ifdef SINGLE_THREAD
+ //in case of single thread, no error handler. Report error immediately
+ return CA_SEND_FAILED;
+#endif
}
OIC_LOG(DEBUG, TAG, "OUT");
- return res;
+ return CA_STATUS_OK;
}
CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
{
OIC_LOG(DEBUG, TAG, "IN");
- CAResult_t res = CA_SEND_FAILED;
u_arraylist_t *list = CAGetSelectedNetworkList();
-
if (!list)
{
OIC_LOG(DEBUG, TAG, "No selected network");
return CA_SEND_FAILED;
}
- int i = 0;
- for (i = 0; i < u_arraylist_length(list); i++)
+ CATransportFlags_t requestedAdapter = endpoint->adapter ? endpoint->adapter : CA_ALL_ADAPTERS;
+
+ for (uint32_t i = 0; i < u_arraylist_length(list); i++)
{
void* ptrType = u_arraylist_get(list, i);
}
CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
+ if ((connType & requestedAdapter) == 0)
+ {
+ continue;
+ }
int index = CAGetAdapterIndex(connType);
OICFree(payload);
}
- if (sentDataLen == length)
- {
- res = CA_STATUS_OK;
- }
- else
+ if (sentDataLen != length)
{
- OIC_LOG(ERROR, TAG, "sendDataToAll failed!");
+ OIC_LOG(ERROR, TAG, "sendDataToAll failed! Error will be reported from adapter");
+#ifdef SINGLE_THREAD
+ //in case of single thread, no error handler. Report error immediately
+ return CA_SEND_FAILED;
+#endif
}
}
OIC_LOG(DEBUG, TAG, "OUT");
- return res;
+ return CA_STATUS_OK;
}
CAResult_t CAStartListeningServerAdapters()
return CA_STATUS_FAILED;
}
- int i = 0;
- for (i = 0; i < u_arraylist_length(list); i++)
+ for (uint32_t i = 0; i < u_arraylist_length(list); i++)
{
void* ptrType = u_arraylist_get(list, i);
return CA_STATUS_FAILED;
}
- int i = 0;
- for (i = 0; i < u_arraylist_length(list); i++)
+ for (uint32_t i = 0; i < u_arraylist_length(list); i++)
{
void* ptrType = u_arraylist_get(list, i);