Commit db6c1199 authored by Mats Wichmann's avatar Mats Wichmann Committed by Dave Thaler

Drop arduino support: SINGLE_THREAD

After dropping the other iotivity arduino support, the
SINGLE_THREAD usage which was only for the ardunio platform
(not capable of multi-threaded) remains.  Since arduino is
gone, this may be no longer needed.

This change is a followon to https://gerrit.iotivity.org/gerrit/23723
for separate consideration.

Change-Id: Ie72873ba4ba90c10e9d8a41d638b0f7de3f76945
Signed-off-by: default avatarMats Wichmann <mats@linux.com>
parent ebee4c5d
......@@ -67,17 +67,6 @@ extern "C"
*/
#define IPV4_ADDR_ONE_OCTECT_LEN 4
#ifdef SINGLE_THREAD
/**
* Network Interface Information. Only needed for Arduino.
*/
typedef struct
{
char ipAddress[CA_IPADDR_SIZE]; /**< Address of the interface. **/
char subnetMask[CA_IPADDR_SIZE]; /**< Maintains interface subnetmask. **/
char interfaceName[CA_INTERFACE_NAME_SIZE]; /**< Interface name. **/
} CANetInfo_t;
#endif
/**
* unicast and multicast server information.
......
......@@ -31,23 +31,13 @@
#include "cainterface.h"
#include "cautilinterface.h"
#ifndef SINGLE_THREAD
#include "cathreadpool.h" /* for thread pool */
#endif
#ifdef __cplusplus
extern "C"
{
#endif
#ifdef SINGLE_THREAD
/**
* Initializes different adapters based on the compilation flags.
*
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAInitializeAdapters();
#else
/**
* Initializes different adapters based on the compilation flags.
* @param[in] handle thread pool handle created by message handler
......@@ -58,7 +48,6 @@ CAResult_t CAInitializeAdapters();
*/
CAResult_t CAInitializeAdapters(ca_thread_pool_t handle, CATransportAdapter_t transportType);
#endif
/**
* Set the received packets callback for message handler.
......@@ -106,12 +95,10 @@ CAResult_t CAStartAdapter(CATransportAdapter_t transportType);
*/
void CAStopAdapter(CATransportAdapter_t transportType);
#ifndef SINGLE_THREAD
/**
* Stop connectivity adapters all.
*/
void CAStopAdapters();
#endif //SINGLE_THREAD
#ifdef RA_ADAPTER
/**
......@@ -184,13 +171,6 @@ bool CAIsLocalEndpoint(const CAEndpoint_t *ep);
*/
void CATerminateAdapters();
#ifdef SINGLE_THREAD
/**
* Checks for available data and reads it.
* @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
*/
CAResult_t CAReadData();
#endif
#ifdef __cplusplus
} /* extern "C" */
......
......@@ -80,11 +80,7 @@ typedef void (*CAIPErrorHandleCallback)(const CAEndpoint_t *endpoint, const void
* @retval ::CA_STATUS_INVALID_PARAM Invalid input data.
* @retval ::CA_STATUS_FAILED Initialization failed.
*/
#ifdef SINGLE_THREAD
CAResult_t CAIPStartServer();
#else
CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
#endif
/**
* Close IP socket.
......
......@@ -81,34 +81,6 @@ typedef void (*CATCPConnectionHandleCallback)(const CAEndpoint_t *endpoint, bool
*/
void CATCPSetErrorHandler(CATCPErrorHandleCallback errorHandleCallback);
#ifdef SINGLE_THREAD
CAResult_t CATCPStartServer();
/**
* Pull the Received Data.
*/
void CATCPPullData();
/**
* Get TCP Header Details.
* @param[in] recvBuffer index of array list.
* @param[out] transport TCP Server address.
* @param[out] headerlen TCP Server port.
*/
void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_t *transport,
size_t *headerlen);
/**
* Get total length from CoAP over TCP header.
*
* @param[in] recvBuffer received header data.
* @param[in] size length of buffer.
* @return total data length
*/
size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t size);
#else
/**
* set keepalive callback to notify connection information in TCP adapter.
*
......@@ -128,7 +100,6 @@ void CATCPSetKeepAliveCallback(CAKeepAliveConnectionCallback keepaliveHandler);
*/
CAResult_t CATCPStartServer(const ca_thread_pool_t threadPool);
#endif
/**
* Stop TCP server.
......
......@@ -38,10 +38,8 @@
#include "cainterface.h"
#include <coap/utlist.h>
#ifndef SINGLE_THREAD
#include <assert.h>
#include "caqueueingthread.h"
#endif
#ifdef RA_ADAPTER
#include "caraadapter.h"
......@@ -70,9 +68,7 @@ static CAErrorHandleCallback g_errorHandleCallback = NULL;
static struct CANetworkCallback_t *g_networkChangeCallbackList = NULL;
#ifndef SINGLE_THREAD
static CAQueueingThread_t g_networkChangeCallbackThread;
#endif
/**
* network callback structure is handling
......@@ -92,7 +88,6 @@ typedef struct CANetworkCallback_t
} CANetworkCallback_t;
#ifndef SINGLE_THREAD
/**
* struct to wrap the network change callback info.
*/
......@@ -142,7 +137,6 @@ static void CADestroyNetworkChangeCallbackData(void *data, uint32_t size)
OICFree(info);
info = NULL;
}
#endif // SINGLE_THREAD
static CAResult_t CAGetAdapterIndex(CATransportAdapter_t cType, size_t *adapterIndex)
{
......@@ -319,7 +313,6 @@ static void CAAdapterChangedCallback(CATransportAdapter_t adapter, CANetworkStat
{
if (callback && callback->adapter)
{
#ifndef SINGLE_THREAD
CANetworkCallbackThreadInfo_t *info = (CANetworkCallbackThreadInfo_t *)
OICCalloc(1, sizeof(CANetworkCallbackThreadInfo_t));
if (!info)
......@@ -334,16 +327,6 @@ static void CAAdapterChangedCallback(CATransportAdapter_t adapter, CANetworkStat
CAQueueingThreadAddData(&g_networkChangeCallbackThread, info,
sizeof(CANetworkCallbackThreadInfo_t));
#else
if (CA_INTERFACE_UP == status)
{
callback->adapter(adapter, true);
}
else if (CA_INTERFACE_DOWN == status)
{
callback->adapter(adapter, false);
}
#endif //SINGLE_THREAD
}
}
}
......@@ -359,7 +342,6 @@ static void CAConnectionChangedCallback(const CAEndpoint_t *endpoint, bool isCon
{
if (callback && callback->conn)
{
#ifndef SINGLE_THREAD
CANetworkCallbackThreadInfo_t *info = (CANetworkCallbackThreadInfo_t *)
OICCalloc(1, sizeof(CANetworkCallbackThreadInfo_t));
if (!info)
......@@ -382,9 +364,6 @@ static void CAConnectionChangedCallback(const CAEndpoint_t *endpoint, bool isCon
CAQueueingThreadAddData(&g_networkChangeCallbackThread, info,
sizeof(CANetworkCallbackThreadInfo_t));
#else
callback->conn(endpoint, isConnected);
#endif //SINGLE_THREAD
}
}
}
......@@ -457,7 +436,6 @@ CAResult_t CAInitializeAdapters(ca_thread_pool_t handle, CATransportAdapter_t tr
}
#endif /* NFC_ADAPTER */
#ifndef SINGLE_THREAD
CAResult_t res = CA_STATUS_OK;
// Initialize & Start network-change-callback-thread.
......@@ -476,7 +454,6 @@ CAResult_t CAInitializeAdapters(ca_thread_pool_t handle, CATransportAdapter_t tr
OIC_LOG(ERROR, TAG, "thread start error(callback thread).");
return res;
}
#endif //SINGLE_THREAD
return CA_STATUS_OK;
}
......@@ -562,7 +539,6 @@ void CAStopAdapter(CATransportAdapter_t transportType)
}
}
#ifndef SINGLE_THREAD
void CAStopAdapters()
{
CATransportAdapter_t connType;
......@@ -584,7 +560,6 @@ void CAStopAdapters()
CAQueueingThreadStop(&g_networkChangeCallbackThread);
}
#endif //SINGLE_THREAD
CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, size_t *size)
{
......@@ -735,10 +710,6 @@ CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data, uin
if ((0 > sentDataLen) || ((uint32_t)sentDataLen != length))
{
OIC_LOG(ERROR, TAG, "Error sending data. The 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
}
}
......@@ -803,10 +774,6 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u
if (sentDataLen != length)
{
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
}
}
......@@ -973,50 +940,8 @@ void CATerminateAdapters()
g_adapterHandler = NULL;
g_numberOfAdapters = 0;
#ifndef SINGLE_THREAD
CAQueueingThreadDestroy(&g_networkChangeCallbackThread);
#endif //SINGLE_THREAD
RemoveAllNetworkStateChangedCallback();
}
#ifdef SINGLE_THREAD
CAResult_t CAReadData()
{
size_t index = 0;
CAResult_t res = CA_STATUS_FAILED;
u_arraylist_t *list = CAGetSelectedNetworkList();
if (!list)
{
return CA_STATUS_FAILED;
}
size_t i = 0;
for (i = 0; i < u_arraylist_length(list); i++)
{
void *ptrType = u_arraylist_get(list, i);
if (NULL == ptrType)
{
OIC_LOG(ERROR, TAG, "get list fail");
return CA_STATUS_FAILED;
}
CATransportAdapter_t connType = *(CATransportAdapter_t *) ptrType;
res = CAGetAdapterIndex(connType, &index);
if (CA_STATUS_OK != res)
{
OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
continue;
}
if (g_adapterHandler[index].readData != NULL)
{
g_adapterHandler[index].readData();
}
}
return CA_STATUS_OK;
}
#endif
......@@ -43,7 +43,6 @@
#include "cablockwisetransfer.h"
#endif
#ifndef SINGLE_THREAD
#include "uqueue.h"
#include "cathreadpool.h" /* for thread pool */
#include "caqueueingthread.h"
......@@ -61,9 +60,6 @@ static ca_thread_pool_t g_threadPoolHandle = NULL;
static CAQueueingThread_t g_sendThread;
static CAQueueingThread_t g_receiveThread;
#else
#define CA_MAX_RT_ARRAY_SIZE 3
#endif // SINGLE_THREAD
#define TAG "OIC_CA_MSG_HANDLE"
......@@ -86,9 +82,6 @@ static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info,
CAResult_t result);
#ifdef SINGLE_THREAD
static void CAProcessReceivedData(CAData_t *data);
#endif
static void CADestroyData(void *data, uint32_t size);
static void CALogPayloadInfo(CAInfo_t *info);
static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *endpoint, uint16_t id,
......@@ -143,16 +136,12 @@ static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
OIC_LOG(ERROR, TAG, "memory allocation failed");
return NULL;
}
#ifdef SINGLE_THREAD
CAEndpoint_t* ep = endpoint;
#else
CAEndpoint_t* ep = CACloneEndpoint(endpoint);
if (!ep)
{
OIC_LOG(ERROR, TAG, "endpoint clone failed");
goto exit;
}
#endif
OIC_LOG_V(DEBUG, TAG, "address : %s", ep->addr);
......@@ -255,9 +244,7 @@ static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
exit:
OICFree(cadata);
#ifndef SINGLE_THREAD
CAFreeEndpoint(ep);
#endif
return NULL;
}
......@@ -265,25 +252,19 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
{
VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
#ifdef SINGLE_THREAD
CAEndpoint_t* ep = endpoint;
#else
CAEndpoint_t* ep = CACloneEndpoint(endpoint);
if (!ep)
{
OIC_LOG(ERROR, TAG, "clone failed");
return;
}
#endif
CAResponseInfo_t* resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof(CAResponseInfo_t));
if (!resInfo)
{
OIC_LOG(ERROR, TAG, "calloc failed");
#ifndef SINGLE_THREAD
CAFreeEndpoint(ep);
#endif
return;
}
......@@ -297,9 +278,7 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
{
OIC_LOG(ERROR, TAG, "fail to get Token from retransmission list");
CADestroyResponseInfoInternal(resInfo);
#ifndef SINGLE_THREAD
CAFreeEndpoint(ep);
#endif
return;
}
......@@ -307,9 +286,7 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
if (NULL == cadata)
{
OIC_LOG(ERROR, TAG, "memory allocation failed !");
#ifndef SINGLE_THREAD
CAFreeEndpoint(ep);
#endif
CADestroyResponseInfoInternal(resInfo);
return;
}
......@@ -331,11 +308,7 @@ static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uin
}
#endif // WITH_BWT
#ifdef SINGLE_THREAD
CAProcessReceivedData(cadata);
#else
CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
#endif
}
static void CADestroyData(void *data, uint32_t size)
......@@ -352,12 +325,10 @@ static void CADestroyData(void *data, uint32_t size)
OIC_LOG(ERROR, TAG, "cadata is NULL");
return;
}
#ifndef SINGLE_THREAD
if (NULL != cadata->remoteEndpoint)
{
CAFreeEndpoint(cadata->remoteEndpoint);
}
#endif
if (NULL != cadata->requestInfo)
{
......@@ -378,46 +349,7 @@ static void CADestroyData(void *data, uint32_t size)
OIC_LOG(DEBUG, TAG, "CADestroyData OUT");
}
#ifdef SINGLE_THREAD
static void CAProcessReceivedData(CAData_t *data)
{
OIC_LOG(DEBUG, TAG, "CAProcessReceivedData IN");
if (!data)
{
OIC_LOG(ERROR, TAG, "thread data error!!");
return;
}
// parse the data and call the callbacks.
// #1 parse the data
// #2 get endpoint
CAEndpoint_t *rep = (CAEndpoint_t *)(data->remoteEndpoint);
if (!rep)
{
OIC_LOG(ERROR, TAG, "remoteEndpoint error!!");
return;
}
if (data->requestInfo && g_requestHandler)
{
g_requestHandler(rep, data->requestInfo);
}
else if (data->responseInfo && g_responseHandler)
{
g_responseHandler(rep, data->responseInfo);
}
else if (data->errorInfo && g_errorHandler)
{
g_errorHandler(rep, data->errorInfo);
}
CADestroyData(data, sizeof(CAData_t));
OIC_LOG(DEBUG, TAG, "CAProcessReceivedData OUT");
}
#endif
#ifndef SINGLE_THREAD
static void CAReceiveThreadProcess(void *threadData)
{
#ifndef SINGLE_HANDLE
......@@ -429,7 +361,6 @@ static void CAReceiveThreadProcess(void *threadData)
(void)threadData;
#endif
}
#endif // SINGLE_THREAD
static CAResult_t CAProcessMulticastData(const CAData_t *data)
{
......@@ -667,7 +598,6 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
return CA_STATUS_OK;
}
#ifndef SINGLE_THREAD
static void CASendThreadProcess(void *threadData)
{
CAData_t *data = (CAData_t *) threadData;
......@@ -675,7 +605,6 @@ static void CASendThreadProcess(void *threadData)
CAProcessSendData(data);
OIC_TRACE_END();
}
#endif
/*
* If a second message arrives with the same message ID, token and the other address
......@@ -818,9 +747,6 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
CALogPDUInfo(cadata, pdu);
#ifdef SINGLE_THREAD
CAProcessReceivedData(cadata);
#else
#ifdef WITH_BWT
if (CAIsSupportedBlockwiseTransfer(sep->endpoint.adapter))
{
......@@ -840,7 +766,6 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
{
CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
}
#endif // SINGLE_THREAD
coap_delete_pdu(pdu);
......@@ -853,10 +778,6 @@ exit:
void CAHandleRequestResponseCallbacks()
{
#ifdef SINGLE_THREAD
CAReadData();
CARetransmissionBaseRoutine((void *)&g_retransmissionContext);
#else
#ifdef SINGLE_HANDLE
// parse the data and call the callbacks.
// #1 parse the data
......@@ -896,7 +817,6 @@ void CAHandleRequestResponseCallbacks()
OICFree(item);
#endif // SINGLE_HANDLE
#endif // SINGLE_THREAD
}
static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sendData,
......@@ -913,9 +833,6 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen
if (CA_REQUEST_DATA == dataType)
{
#ifdef SINGLE_THREAD
CARequestInfo_t *request = (CARequestInfo_t *)sendData;
#else
// clone request info
CARequestInfo_t *request = CACloneRequestInfo((CARequestInfo_t *)sendData);
if (!request)
......@@ -923,15 +840,11 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen
OIC_LOG(ERROR, TAG, "CACloneRequestInfo failed");
goto exit;
}
#endif
cadata->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
cadata->requestInfo = request;
}
else if (CA_RESPONSE_DATA == dataType || CA_RESPONSE_FOR_RES == dataType)
{
#ifdef SINGLE_THREAD
CAResponseInfo_t *response = (CAResponseInfo_t *)sendData;
#else
// clone response info
CAResponseInfo_t *response = CACloneResponseInfo((CAResponseInfo_t *)sendData);
if(!response)
......@@ -939,7 +852,6 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen
OIC_LOG(ERROR, TAG, "CACloneResponseInfo failed");
goto exit;
}
#endif
cadata->type = response->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
cadata->responseInfo = response;
}
......@@ -949,26 +861,18 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen
goto exit;
}
#ifdef SINGLE_THREAD
CAEndpoint_t* ep = endpoint;
#else
CAEndpoint_t* ep = CACloneEndpoint(endpoint);
if (!ep)
{
OIC_LOG(ERROR, TAG, "endpoint clone failed");
goto exit;
}
#endif
cadata->remoteEndpoint = ep;
cadata->dataType = dataType;
return cadata;
exit:
#ifndef SINGLE_THREAD
CADestroyData(cadata, sizeof(CAData_t));
#else
OICFree(cadata);
#endif
return NULL;
}
......@@ -1000,18 +904,6 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
}
#endif
#ifdef SINGLE_THREAD
CAResult_t result = CAProcessSendData(data);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAProcessSendData failed");
OICFree(data);
return result;
}
OICFree(data);
#else
if (SEND_TYPE_UNICAST == data->type && CAIsLocalEndpoint(data->remoteEndpoint))
{
OIC_LOG(DEBUG, TAG,
......@@ -1041,7 +933,6 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
{
CAQueueingThreadAddData(&g_sendThread, data, sizeof(CAData_t));
}
#endif // SINGLE_THREAD
return CA_STATUS_OK;
}
......@@ -1064,7 +955,6 @@ CAResult_t CAInitializeMessageHandler(CATransportAdapter_t transportType)
CASetPacketReceivedCallback(CAReceivedPacketCallback);
CASetErrorHandleCallback(CAErrorHandler);
#ifndef SINGLE_THREAD
// create thread pool
CAResult_t res = ca_thread_pool_init(MAX_THREAD_POOL_SIZE, &g_threadPoolHandle);
if (CA_STATUS_OK != res)
......@@ -1143,25 +1033,12 @@ CAResult_t CAInitializeMessageHandler(CATransportAdapter_t transportType)
OIC_LOG(ERROR, TAG, "Failed to Initialize Adapters.");
return res;
}
#else
// retransmission initialize
CAResult_t res = CARetransmissionInitialize(&g_retransmissionContext, NULL, CASendUnicastData,
CATimeoutCallback, NULL);
if (CA_STATUS_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to Initialize Retransmission.");
return res;
}
CAInitializeAdapters();
#endif // SINGLE_THREAD
return CA_STATUS_OK;
}