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
......@@ -46,7 +46,6 @@
#include <stdlib.h>
#include <string.h>
#ifndef SINGLE_THREAD
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
......@@ -59,7 +58,6 @@
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#endif
#if defined(__ANDROID__)
#include <linux/time.h>
......@@ -78,9 +76,7 @@
typedef struct
{
uint64_t timeStamp; /**< last sent time. microseconds */
#ifndef SINGLE_THREAD
uint64_t timeout; /**< timeout value. microseconds */
#endif
uint8_t triedCount; /**< retransmission count */
uint16_t messageId; /**< coap PDU message id */
CADataType_t dataType; /**< data Type (Request/Response) */
......@@ -93,7 +89,6 @@ static const uint64_t USECS_PER_SEC = 1000000;
static const uint64_t USECS_PER_MSEC = 1000;
static const uint64_t MSECS_PER_SEC = 1000;
#ifndef SINGLE_THREAD
/**
* @brief timeout value is
* between DEFAULT_ACK_TIMEOUT_SEC and
......@@ -138,7 +133,6 @@ CAResult_t CARetransmissionStart(CARetransmission_t *context)
return res;
}
#endif
/**
* @brief check timeout routine
......@@ -148,7 +142,6 @@ CAResult_t CARetransmissionStart(CARetransmission_t *context)
*/
static bool CACheckTimeout(uint64_t currentTime, CARetransmissionData_t *retData)
{
#ifndef SINGLE_THREAD
// #1. calculate timeout
uint64_t milliTimeoutValue = retData->timeout / USECS_PER_MSEC;
uint64_t timeout = (milliTimeoutValue << retData->triedCount) * USECS_PER_MSEC;
......@@ -159,17 +152,6 @@ static bool CACheckTimeout(uint64_t currentTime, CARetransmissionData_t *retData
timeout, retData->triedCount);
return true;
}
#else
// #1. calculate timeout
uint64_t timeOut = (2 << retData->triedCount) * (uint64_t) USECS_PER_SEC;
if (currentTime >= retData->timeStamp + timeOut)
{
OIC_LOG_V(DEBUG, TAG, "timeout=%d, tried cnt=%d",
(2 << retData->triedCount), retData->triedCount);
return true;
}
#endif
return false;
}
......@@ -262,14 +244,6 @@ void CARetransmissionBaseRoutine(void *threadValue)
return;
}
#ifdef SINGLE_THREAD
if (true == context->isStop)
{
OIC_LOG(DEBUG, TAG, "thread stopped");
return;
}
CACheckRetransmissionList(context);
#else
while (!context->isStop)
{
......@@ -317,7 +291,6 @@ void CARetransmissionBaseRoutine(void *threadValue)
oc_cond_signal(context->threadCond);
oc_mutex_unlock(context->threadMutex);
#endif
OIC_LOG(DEBUG, TAG, "retransmission main thread end");
}
......@@ -333,13 +306,11 @@ CAResult_t CARetransmissionInitialize(CARetransmission_t *context,
OIC_LOG(ERROR, TAG, "thread instance is empty");
return CA_STATUS_INVALID_PARAM;
}
#ifndef SINGLE_THREAD
if (NULL == handle)
{
OIC_LOG(ERROR, TAG, "thread pool handle is empty");
return CA_STATUS_INVALID_PARAM;
}
#endif
OIC_LOG(DEBUG, TAG, "thread initialize");
memset(context, 0, sizeof(CARetransmission_t));
......@@ -427,16 +398,13 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
// #2. add additional information. (time stamp, retransmission count...)
retData->timeStamp = OICGetCurrentTime(TIME_IN_US);
#ifndef SINGLE_THREAD
retData->timeout = CAGetTimeoutValue();
#endif
retData->triedCount = 0;
retData->messageId = messageId;
retData->endpoint = remoteEndpoint;
retData->pdu = pduData;
retData->size = size;
retData->dataType = dataType;
#ifndef SINGLE_THREAD
// mutex lock
oc_mutex_lock(context->threadMutex);
......@@ -476,11 +444,6 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context,
// mutex unlock
oc_mutex_unlock(context->threadMutex);
#else
u_arraylist_add(context->dataList, (void *) retData);
CACheckRetransmissionList(context);
#endif
return CA_STATUS_OK;
}
......
......@@ -44,7 +44,6 @@
*/
#define TAG "OIC_CA_IP_ADAP"
#ifndef SINGLE_THREAD
/**
* Holds inter thread ip data information.
*/
......@@ -60,7 +59,6 @@ typedef struct
* Queue handle for Send Data.
*/
static CAQueueingThread_t *g_sendQueueHandle = NULL;
#endif
/**
* List of the endpoint that has a stack-owned IP address.
......@@ -91,7 +89,6 @@ static ssize_t CAIPPacketSendCB(CAEndpoint_t *endpoint,
static void CAUpdateStoredIPAddressInfo(CANetworkStatus_t status);
#ifndef SINGLE_THREAD
static CAResult_t CAIPInitializeQueueHandles();
......@@ -162,7 +159,6 @@ void CAIPDeinitializeQueueHandles()
g_ownIpEndpointList = NULL;
}
#endif // SINGLE_THREAD
void CAIPAdapterHandler(CATransportAdapter_t adapter, CANetworkStatus_t status)
{
......@@ -328,9 +324,7 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
VERIFY_NON_NULL(registerCallback, TAG, "registerCallback");
VERIFY_NON_NULL(networkPacketCallback, TAG, "networkPacketCallback");
VERIFY_NON_NULL(netCallback, TAG, "netCallback");
#ifndef SINGLE_THREAD
VERIFY_NON_NULL(handle, TAG, "thread pool handle");
#endif
#ifdef WSA_WAIT_EVENT_0
// Windows-specific initialization.
......@@ -398,16 +392,6 @@ CAResult_t CAStartIP()
caglobals.ip.u4s.port = caglobals.ports.udp.u4s;
CAIPStartNetworkMonitor(CAIPAdapterHandler, CA_ADAPTER_IP);
#ifdef SINGLE_THREAD
uint16_t unicastPort = 55555;
// Address is hardcoded as we are using Single Interface
CAResult_t ret = CAIPStartServer();
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(DEBUG, TAG, "CAIPStartServer failed[%d]", ret);
return ret;
}
#else
if (CA_STATUS_OK != CAIPInitializeQueueHandles())
{
OIC_LOG(ERROR, TAG, "Failed to Initialize Queue Handle");
......@@ -429,7 +413,6 @@ CAResult_t CAStartIP()
return ret;
}
#endif
return CA_STATUS_OK;
}
......@@ -474,12 +457,6 @@ static int32_t CAQueueIPData(bool isMulticast, const CAEndpoint_t *endpoint,
return -1;
}
#ifdef SINGLE_THREAD
CAIPSendData(endpoint, data, dataLength, isMulticast);
return dataLength;
#else
VERIFY_NON_NULL_RET(g_sendQueueHandle, TAG, "sendQueueHandle", -1);
// Create IPData to add to queue
......@@ -492,7 +469,6 @@ static int32_t CAQueueIPData(bool isMulticast, const CAEndpoint_t *endpoint,
// Add message to send queue
CAQueueingThreadAddData(g_sendQueueHandle, ipData, sizeof(CAIPData_t));
#endif // SINGLE_THREAD
return dataLength;
}
......@@ -524,12 +500,10 @@ CAResult_t CAStopIP()
CAdeinitSslAdapter();
#endif
#ifndef SINGLE_THREAD
if (g_sendQueueHandle && g_sendQueueHandle->threadMutex)
{
CAQueueingThreadStop(g_sendQueueHandle);
}
#endif
CAIPStopNetworkMonitor(CA_ADAPTER_IP);
CAIPStopServer();
......@@ -545,9 +519,7 @@ void CATerminateIP()
CAIPSetPacketReceiveCallback(NULL);
#ifndef SINGLE_THREAD
CAIPDeinitializeQueueHandles();
#endif
#ifdef WSA_WAIT_EVENT_0
// Windows-specific clean-up.
......@@ -555,7 +527,6 @@ void CATerminateIP()
#endif
}
#ifndef SINGLE_THREAD
void CAIPSendDataThread(void *threadData)
{
......@@ -597,9 +568,7 @@ void CAIPSendDataThread(void *threadData)
}
}
#endif
#ifndef SINGLE_THREAD
CAIPData_t *CACreateIPData(const CAEndpoint_t *remoteEndpoint, const void *data,
uint32_t dataLength, bool isMulticast)
{
......@@ -650,4 +619,3 @@ void CADataDestroyer(void *data, uint32_t size)
CAFreeIPData(etdata);
}
#endif // SINGLE_THREAD
......@@ -69,7 +69,6 @@ static CAErrorHandleCallback g_errorCallback = NULL;
static void CANFCPacketReceivedCB(const CASecureEndpoint_t *endpoint, const void *data,
size_t dataLength);
#ifndef SINGLE_THREAD
static CAResult_t CANFCInitializeQueueHandles();
......@@ -128,7 +127,6 @@ void CANFCDeinitializeQueueHandles()
OIC_LOG(DEBUG, TAG, "OUT");
}
#endif // SINGLE_THREAD
void CANFCConnectionStateCB(const char *nfcAddress, CANetworkStatus_t status)
{
OIC_LOG(DEBUG, TAG, "Currently Not Supported");
......
......@@ -169,12 +169,6 @@ void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data,
OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", sep->endpoint.addr, sep->endpoint.port);
#ifdef SINGLE_THREAD
if (g_networkPacketCallback)
{
g_networkPacketCallback(sep, data, dataLength);
}
#else
unsigned char *buffer = (unsigned char*)data;
size_t bufferLen = dataLength;
......@@ -216,7 +210,6 @@ void CATCPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data,
svritem->totalLen - svritem->len);
}
}
#endif
}
#ifdef __WITH_TLS__
......@@ -285,11 +278,7 @@ void CATCPAdapterHandler(CATransportAdapter_t adapter, CANetworkStatus_t status)
OIC_LOG(DEBUG, TAG, "Network status is up, create new socket for listening");
CAResult_t ret = CA_STATUS_FAILED;
#ifndef SINGLE_THREAD
ret = CATCPStartServer((const ca_thread_pool_t)caglobals.tcp.threadpool);
#else
ret = CATCPStartServer();
#endif
if (CA_STATUS_OK != ret)
{
OIC_LOG_V(DEBUG, TAG, "CATCPStartServer failed[%d]", ret);
......@@ -337,9 +326,7 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
VERIFY_NON_NULL(registerCallback, TAG, "registerCallback");
VERIFY_NON_NULL(networkPacketCallback, TAG, "networkPacketCallback");
VERIFY_NON_NULL(netCallback, TAG, "netCallback");
#ifndef SINGLE_THREAD
VERIFY_NON_NULL(handle, TAG, "thread pool handle");
#endif
#ifdef WSA_WAIT_EVENT_0
// Windows-specific initialization.
......@@ -360,9 +347,7 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
g_errorCallback = errorCallback;
CAInitializeTCPGlobals();
#ifndef SINGLE_THREAD
caglobals.tcp.threadpool = handle;
#endif
CATCPSetConnectionChangedCallback(CATCPConnectionHandler);
CATCPSetPacketReceiveCallback(CATCPPacketReceivedCB);
......@@ -405,7 +390,6 @@ CAResult_t CAStartTCP()
// Start network monitoring to receive adapter status changes.
CAIPStartNetworkMonitor(CATCPAdapterHandler, CA_ADAPTER_TCP);
#ifndef SINGLE_THREAD
if (CA_STATUS_OK != CATCPInitializeQueueHandles())
{
OIC_LOG(ERROR, TAG, "Failed to Initialize Queue Handle");
......@@ -419,21 +403,12 @@ CAResult_t CAStartTCP()
OIC_LOG(ERROR, TAG, "Failed to Start Send Data Thread");
return CA_STATUS_FAILED;
}
#else
CAResult_t ret = CATCPStartServer();
if (CA_STATUS_OK != ret)
{