Drop arduino support: SINGLE_THREAD 69/23869/4
authorMats Wichmann <mats@linux.com>
Wed, 3 Jan 2018 13:26:33 +0000 (06:26 -0700)
committerDave Thaler <dthaler@microsoft.com>
Fri, 16 Mar 2018 21:39:02 +0000 (21:39 +0000)
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: Mats Wichmann <mats@linux.com>
12 files changed:
resource/csdk/connectivity/inc/caadapterutils.h
resource/csdk/connectivity/inc/cainterfacecontroller.h
resource/csdk/connectivity/inc/caipinterface.h
resource/csdk/connectivity/inc/catcpinterface.h
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/connectivity/src/caretransmission.c
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/nfc_adapter/canfcadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/routing/include/routingtablemanager.h

index bfd5145..3f476d3 100644 (file)
@@ -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.
index 6d24968..c85eae8 100644 (file)
 #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" */
index c2bd660..bfb3d0d 100644 (file)
@@ -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.
index 53d854c..54ef47c 100644 (file)
@@ -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.
index 2d509bd..13d79f8 100644 (file)
@@ -32,9 +32,7 @@
 #ifdef __WITH_DTLS__
 #include "ca_adapter_net_ssl.h"
 #endif
-#ifndef SINGLE_THREAD
 #include "caqueueingthread.h"
-#endif
 #if defined(__TIZEN__) || defined(__ANDROID__)
 #include "caleserver.h"
 #include "caleclient.h"
@@ -187,41 +185,6 @@ static ssize_t CALESecureSendDataCB(CAEndpoint_t *endpoint,
                              const void *data, size_t dataLen);
 #endif
 
-#ifdef SINGLE_THREAD
-/**
- * Pointer to defragment received data from single threaded routine.
- */
-static CABLESenderInfo_t *g_singleThreadReceiveData = NULL;
-
-/**
- * This function will be associated with the receive for single thread.
- *
- * This function will defragment the received data from sender
- * respectively and will send it up to CA layer. Respective sender's
- * header will provide the length of the data sent.
- *
- * @param[in] data       Actual data received from the remote
- *                       device.
- * @param[in] dataLen    Length of the data received from the
- *                       remote device.
- */
-static void CALEDataReceiverHandlerSingleThread(const uint8_t *data,
-                                                uint32_t dataLen);
-
-/**
- * This function will be associated with the send for single threaded
- * GattServer.
- *
- * This function will fragment the data to the MTU of the transport
- * and send the data in fragments to the adapters. The function will
- * be blocked until all data is sent out from the adapter.
- *
- * @param[in] data       Data to be transmitted from LE.
- * @param[in] dataLen    Length of the Data being transmitted.
- */
-static CAResult_t CALEServerSendDataSingleThread(const uint8_t *data,
-                                                 uint32_t dataLen);
-#endif
 
 /**
  * Register network change notification callback.
@@ -295,7 +258,6 @@ static void CALEErrorHandler(const char *remoteAddress,
                              uint32_t dataLen,
                              CAResult_t result);
 
-#ifndef SINGLE_THREAD
 /**
  * Stop condition of Server recvhandler.
  */
@@ -526,7 +488,6 @@ static void CAFreeLEData(CALEData_t *bleData);
  */
 static void CALEDataDestroyer(void *data, uint32_t size);
 
-#ifndef SINGLE_THREAD
 /**
  * remove request or response data of send queue.
  *
@@ -577,7 +538,6 @@ static CAResult_t CALEGetSenderInfo(const char *leAddress,
 static CAResult_t CALEGetPortsFromSenderInfo(const char *leAddress,
                                             u_arraylist_t *senderInfoList,
                                             u_arraylist_t *portList);
-#endif
 
 static CAResult_t CAInitLEClientQueues()
 {
@@ -2072,305 +2032,7 @@ static void CALEDataDestroyer(void *data, uint32_t size)
 
     CAFreeLEData(ledata);
 }
-#endif
-
-#ifdef SINGLE_THREAD
-static void CALEDataReceiverHandlerSingleThread(const uint8_t *data,
-                                                uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
-
-    //packet parsing
-    CABLEPacketStart_t startFlag = CA_BLE_PACKET_NOT_START;
-    CABLEPacketSecure_t secureFlag = CA_BLE_PACKET_NON_SECURE;
-    uint16_t sourcePort = 0;
-    uint16_t destPort = 0;
-
-    CAParseHeader(data, &startFlag, &sourcePort, &secureFlag, &destPort);
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG,
-              "header info: startFlag[%X] sourcePort[%d] secureFlag[%X] destPort[%d]",
-              startFlag, sourcePort, secureFlag, destPort);
-
-    if (destPort != g_localBLESourcePort && destPort != CA_BLE_MULTICAST_PORT)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                  "this packet is not valid for this app(port mismatch[mine:%d, packet:%d])",
-                  g_localBLESourcePort, destPort);
-        return;
-    }
-
-    if (startFlag)
-    {
-        if (g_singleThreadReceiveData)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG,
-                    "This packet is start packet but exist senderInfo. Remove senderInfo");
-            OICFree(g_singleThreadReceiveData->defragData);
-            OICFree(g_singleThreadReceiveData);
-            g_singleThreadReceiveData = NULL;
-        }
-
-        uint32_t totalLength = 0;
-        CAParseHeaderPayloadLength(data, CA_BLE_LENGTH_HEADER_SIZE, &totalLength);
-
-        g_singleThreadReceiveData = OICMalloc(sizeof(CABLESenderInfo_t));
-
-        if (!g_singleThreadReceiveData)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Memory allocation failed for new sender");
-            return;
-        }
-        g_singleThreadReceiveData->recvDataLen = 0;
-        g_singleThreadReceiveData->totalDataLen = 0;
-        g_singleThreadReceiveData->defragData = NULL;
-        g_singleThreadReceiveData->remoteEndpoint = NULL;
-
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Parsing the header");
-
-        g_singleThreadReceiveData->totalDataLen = totalLength;
-
-        if (!(g_singleThreadReceiveData->totalDataLen))
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Total Data Length is parsed as 0!!!");
-            OICFree(g_singleThreadReceiveData);
-            return;
-        }
-
-        size_t dataOnlyLen = dataLen - (CA_BLE_HEADER_SIZE + CA_BLE_LENGTH_HEADER_SIZE);
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Total data to be accumulated [%u] bytes",
-                  g_singleThreadReceiveData->totalDataLen);
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "data received in the first packet [%u] bytes",
-                  dataOnlyLen);
-
-        g_singleThreadReceiveData->defragData =
-            OICCalloc(g_singleThreadReceiveData->totalDataLen + 1,
-                    sizeof(*g_singleThreadReceiveData->defragData));
-
-        if (NULL == g_singleThreadReceiveData->defragData)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "defragData is NULL!");
-            OICFree(g_singleThreadReceiveData);
-            return;
-        }
-
-        if (g_singleThreadReceiveData->recvDataLen + dataOnlyLen
-                > g_singleThreadReceiveData->totalDataLen)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "buffer is smaller than received data");
-            OICFree(g_singleThreadReceiveData->defragData);
-            OICFree(g_singleThreadReceiveData);
-            return;
-        }
-        memcpy(g_singleThreadReceiveData->defragData,
-               data + (CA_BLE_HEADER_SIZE + CA_BLE_LENGTH_HEADER_SIZE),
-               dataOnlyLen);
-        g_singleThreadReceiveData->recvDataLen += dataOnlyLen;
-    }
-    else
-    {
-        size_t dataOnlyLen = dataLen - CA_BLE_HEADER_SIZE;
-        if (g_singleThreadReceiveData->recvDataLen + dataOnlyLen
-                > g_singleThreadReceiveData->totalDataLen)
-        {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                      "Data Length exceeding error!! Receiving [%d] total length [%d]",
-                      g_singleThreadReceiveData->recvDataLen + dataOnlyLen,
-                      g_singleThreadReceiveData->totalDataLen);
-            OICFree(g_singleThreadReceiveData->defragData);
-            OICFree(g_singleThreadReceiveData);
-            return;
-        }
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Copying the data of length [%d]",
-                  dataOnlyLen);
-        memcpy(g_singleThreadReceiveData->defragData + g_singleThreadReceiveData->recvDataLen,
-               data + CA_BLE_HEADER_SIZE,
-               dataOnlyLen);
-        g_singleThreadReceiveData->recvDataLen += dataOnlyLen;
-        OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "totalDatalength  [%d] received Datalen [%d]",
-                g_singleThreadReceiveData->totalDataLen, g_singleThreadReceiveData->recvDataLen);
-    }
-}
-
-static CAResult_t CALEServerSendDataSingleThread(const uint8_t *data,
-                                                 uint32_t dataLen)
-{
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
-
-    VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
-
-    uint32_t midPacketCount = 0;
-    size_t remainingLen = 0;
-    size_t totalLength = 0;
-    CABLEPacketSecure_t secureFlag = CA_BLE_PACKET_NON_SECURE;
-
-    CAResult_t result = CAGenerateVariableForFragmentation(dataLen,
-                                                           &midPacketCount,
-                                                           &remainingLen,
-                                                           &totalLength,
-                                                           g_mtuSize);
-
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                  "CAGenerateVariableForFragmentation failed, result [%d]", result);
-        return result;
-    }
-
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG,
-              "Packet info: data size[%d] midPacketCount[%d] remainingLen[%d] totalLength[%d]",
-              dataLen, midPacketCount, remainingLen, totalLength);
-
-    OIC_LOG_V(DEBUG,
-              CALEADAPTER_TAG,
-              "Server total Data length with header is [%u]",
-              totalLength);
 
-    uint8_t dataSegment[CA_SUPPORTED_BLE_MTU_SIZE] = {0};
-    uint8_t dataHeader[CA_BLE_HEADER_SIZE] = {0};
-
-    result = CAGenerateHeader(dataHeader,
-                              CA_BLE_PACKET_START,
-                              g_localBLESourcePort,
-                              CA_BLE_PACKET_NON_SECURE,
-                              CA_BLE_MULTICAST_PORT);
-
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                  "CAGenerateHeader failed, result [%d]", result);
-        return result;
-    }
-
-    uint8_t lengthHeader[CA_BLE_LENGTH_HEADER_SIZE] = {0};
-    result = CAGenerateHeaderPayloadLength(lengthHeader,
-                                           CA_BLE_LENGTH_HEADER_SIZE,
-                                           dataLen);
-
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                  "CAGenerateHeaderPayloadLength failed, result [%d]", result);
-        return result;
-    }
-
-    uint32_t length = 0;
-    uint32_t dataOnlyLen = 0;
-    if (g_mtuSize > totalLength)
-    {
-        length = totalLength;
-        dataOnlyLen = dataLen;
-    }
-    else
-    {
-        length = g_mtuSize;
-        dataOnlyLen = g_mtuSize - CA_BLE_HEADER_SIZE - CA_BLE_LENGTH_HEADER_SIZE;
-    }
-
-    result = CAMakeFirstDataSegment(dataSegment,
-                                    data, dataOnlyLen,
-                                    dataHeader, lengthHeader);
-
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                  "Making data segment failed, result [%d]", result);
-        return result;
-    }
-
-    OIC_LOG(DEBUG, CALEADAPTER_TAG, "Server Sending Multicast data");
-    result = CAUpdateCharacteristicsToAllGattClients(dataSegment, length);
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG, "Update characteristics failed, result [%d]",
-                result);
-        return result;
-    }
-
-    CALEDoEvents();
-
-    OIC_LOG_V(DEBUG, CALEADAPTER_TAG, "Server Sent data length [%d]", length);
-
-    result = CAGenerateHeader(dataHeader,
-                              CA_BLE_PACKET_NOT_START,
-                              g_localBLESourcePort,
-                              CA_BLE_PACKET_NON_SECURE,
-                              CA_BLE_MULTICAST_PORT);
-
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                  "CAGenerateHeader failed, result [%d]", result);
-        return result;
-    }
-
-    const uint32_t dataLimit = midPacketCount;
-    for (uint32_t iter = 0; iter < dataLimit; iter++)
-    {
-        result = CAMakeRemainDataSegment(dataSegment,
-                                         g_mtuSize - CA_BLE_HEADER_SIZE,
-                                         data,
-                                         dataLen,
-                                         iter,
-                                         dataHeader,
-                                         g_mtuSize);
-
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                    "Making data segment failed, result [%d]", result);
-            return result;
-        }
-
-        result = CAUpdateCharacteristicsToAllGattClients(
-                     dataSegment,
-                     g_mtuSize);
-
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-            return result;
-        }
-
-        CALEDoEvents();
-    }
-
-    if (remainingLen && (totalLength > g_mtuSize))
-    {
-        // send the last segment of the data
-        OIC_LOG(DEBUG, CALEADAPTER_TAG, "Sending the last chunk");
-
-        result = CAMakeRemainDataSegment(dataSegment,
-                                         remainingLen,
-                                         data,
-                                         dataLen,
-                                         dataLimit,
-                                         dataHeader,
-                                         g_mtuSize);
-
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG_V(ERROR, CALEADAPTER_TAG,
-                    "Making data segment failed, result [%d]", result);
-            return result;
-        }
-
-        result = CAUpdateCharacteristicsToAllGattClients(
-                     dataSegment,
-                     remainingLen + CA_BLE_HEADER_SIZE);
-
-        if (CA_STATUS_OK != result)
-        {
-            OIC_LOG(ERROR, CALEADAPTER_TAG, "Update characteristics failed");
-            return result;
-        }
-        CALEDoEvents();
-    }
-
-    return result;
-}
-#endif
 
 static CAResult_t CAInitLEAdapterMutex()
 {
@@ -2719,7 +2381,6 @@ static CAResult_t CALEAdapterGattServerStart()
 
     CAResult_t result = CAStartLEGattServer();
 
-#ifndef SINGLE_THREAD
     /*
       Don't start the server side sending queue thread until the
       server itself has actually started.
@@ -2738,7 +2399,6 @@ static CAResult_t CALEAdapterGattServerStart()
                       result);
         }
     }
-#endif
 
     return result;
 }
@@ -2754,7 +2414,6 @@ static CAResult_t CALEAdapterGattServerStop()
         return CA_STATUS_OK;
     }
 
-#ifndef SINGLE_THREAD
 
     CAResult_t res = CAStopLEGattServer();
     if (CA_STATUS_OK != res)
@@ -2771,9 +2430,6 @@ static CAResult_t CALEAdapterGattServerStop()
     oc_mutex_unlock(g_bleServerSendDataMutex);
 
     return res;
-#else
-    return CAStopLEGattServer();
-#endif
 }
 
 static CAResult_t CALEAdapterGattClientStart()
@@ -2782,7 +2438,6 @@ static CAResult_t CALEAdapterGattClientStart()
 
     CAResult_t result = CAStartLEGattClient();
 
-#ifndef SINGLE_THREAD
     /*
       Don't start the client side sending queue thread until the
       client itself has actually started.
@@ -2800,14 +2455,12 @@ static CAResult_t CALEAdapterGattClientStart()
                     "Unable to start client queuing thread");
         }
     }
-#endif
 
     return result;
 }
 
 static CAResult_t CALEAdapterGattClientStop()
 {
-#ifndef SINGLE_THREAD
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEAdapterGattClientStop");
     CAStopLEGattClient();
 
@@ -2816,11 +2469,6 @@ static CAResult_t CALEAdapterGattClientStop()
     oc_mutex_unlock(g_bleClientSendDataMutex);
 
     return result;
-#else
-    CAStopLEGattClient();
-
-    return CA_STATUS_OK;
-#endif
 }
 
 #ifdef __WITH_DTLS__
@@ -3013,9 +2661,7 @@ static CAResult_t CAStopLE()
     CAdeinitSslAdapter();
 #endif
 
-#ifndef SINGLE_THREAD
     CAStopLEQueues();
-#endif
 
     oc_mutex_lock(g_bleIsServerMutex);
     switch (g_adapterType)
@@ -3066,9 +2712,7 @@ static void CATerminateLE()
     g_adapterType = ADAPTER_EMPTY;
     oc_mutex_unlock(g_bleIsServerMutex);
 
-#ifndef SINGLE_THREAD
     CATerminateLEQueues();
-#endif
 
 #ifdef __WITH_DTLS__
     CAsetSslAdapterCallbacks(NULL, NULL, NULL, CA_ADAPTER_GATT_BTLE);
@@ -3090,14 +2734,12 @@ static CAResult_t CAStartLEListeningServer()
 
 #ifndef ROUTING_GATEWAY
     CAResult_t result = CA_STATUS_OK;
-#ifndef SINGLE_THREAD
     result = CAInitLEServerQueues();
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitLEServerQueues failed");
         return result;
     }
-#endif // not SINGLE_THREAD
 
     oc_mutex_lock(g_bleIsServerMutex);
     switch (g_adapterType)
@@ -3147,14 +2789,12 @@ static CAResult_t CAStartLEDiscoveryServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN - CAStartLEDiscoveryServer");
     CAResult_t result = CA_STATUS_OK;
-#ifndef SINGLE_THREAD
     result = CAInitLEClientQueues();
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, CALEADAPTER_TAG, "CAInitLEClientQueues failed");
         return result;
     }
-#endif
 
     oc_mutex_lock(g_bleIsServerMutex);
     switch (g_adapterType)
@@ -3191,9 +2831,6 @@ static CAResult_t CAStartLEDiscoveryServer()
 
 static CAResult_t CAReadLEData()
 {
-#ifdef SINGLE_THREAD
-    CACheckLEData();
-#endif
     return CA_STATUS_OK;
 }
 
@@ -3498,7 +3135,6 @@ static void CALEConnectionStateChangedCb(CATransportAdapter_t adapter, const cha
 
     if(!isConnected)
     {
-#ifndef SINGLE_THREAD
         if(g_bleClientSenderInfo)
         {
             CALERemoveReceiveQueueData(g_bleClientSenderInfo, address);
@@ -3523,7 +3159,6 @@ static void CALEConnectionStateChangedCb(CATransportAdapter_t adapter, const cha
                                     g_bleServerSendDataMutex,
                                     address);
         }
-#endif
 
 #ifdef __WITH_DTLS__
         CAcloseSslConnection(&localEndpoint);
@@ -3604,7 +3239,6 @@ static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
                                             uint32_t dataLen)
 {
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
-#ifndef SINGLE_THREAD
     VERIFY_NON_NULL_RET(g_bleClientSendQueueHandle, CALEADAPTER_TAG,
                         "g_bleClientSendQueueHandle is  NULL",
                         CA_STATUS_FAILED);
@@ -3624,7 +3258,6 @@ static CAResult_t CALEAdapterClientSendData(const CAEndpoint_t *remoteEndpoint,
     oc_mutex_lock(g_bleClientSendDataMutex);
     CAQueueingThreadAddData(g_bleClientSendQueueHandle, bleData, sizeof(CALEData_t));
     oc_mutex_unlock(g_bleClientSendDataMutex);
-#endif
     return CA_STATUS_OK;
 }
 
@@ -3636,20 +3269,6 @@ static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
 
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Param data is NULL");
 
-#ifdef SINGLE_THREAD
-    if (!CAIsLEConnected())
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "le not conn");
-        return CA_STATUS_FAILED;
-    }
-
-    CAResult_t result = CALEServerSendDataSingleThread(data, dataLen);
-    if (CA_STATUS_OK != result)
-    {
-        OIC_LOG(ERROR, CALEADAPTER_TAG, "CALEServerSendDataSingleThread failed");
-        return CA_STATUS_FAILED;
-    }
-#else
     VERIFY_NON_NULL_RET(g_bleServerSendQueueHandle, CALEADAPTER_TAG,
                         "BleClientReceiverQueue is NULL",
                         CA_STATUS_FAILED);
@@ -3677,7 +3296,6 @@ static CAResult_t CALEAdapterServerSendData(const CAEndpoint_t *remoteEndpoint,
                             bleData,
                             sizeof(CALEData_t));
     oc_mutex_unlock(g_bleServerSendDataMutex);
-#endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
@@ -3693,28 +3311,6 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL(sentLength, CALEADAPTER_TAG, "Sent data length holder is null");
 
-#ifdef SINGLE_THREAD
-    CALEDataReceiverHandlerSingleThread(data, dataLength);
-
-    if (g_singleThreadReceiveData->totalDataLen == g_singleThreadReceiveData->recvDataLen)
-    {
-        if(g_networkPacketReceivedCallback)
-        {
-            // will be filled by upper layer
-            const CASecureEndpoint_t endpoint =
-                { .endpoint = { .adapter = CA_ADAPTER_GATT_BTLE } };
-
-            g_networkPacketReceivedCallback(&endpoint,
-                                            g_singleThreadReceiveData->defragData,
-                                            g_singleThreadReceiveData->recvDataLen);
-        }
-        g_singleThreadReceiveData->remoteEndpoint = NULL;
-        OICFree(g_singleThreadReceiveData->defragData);
-        g_singleThreadReceiveData->defragData = NULL;
-        OICFree(g_singleThreadReceiveData);
-        g_singleThreadReceiveData = NULL;
-    }
-#else
     VERIFY_NON_NULL_RET(g_bleServerReceiverQueue,
                         CALEADAPTER_TAG,
                         "g_bleServerReceiverQueue",
@@ -3754,7 +3350,6 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
     CAQueueingThreadAddData(g_bleServerReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
-#endif
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
@@ -3767,7 +3362,6 @@ static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
     //Input validation
     VERIFY_NON_NULL(data, CALEADAPTER_TAG, "Data is null");
     VERIFY_NON_NULL(sentLength, CALEADAPTER_TAG, "Sent data length holder is null");
-#ifndef SINGLE_THREAD
     VERIFY_NON_NULL_RET(g_bleClientReceiverQueue, CALEADAPTER_TAG,
                         "g_bleClientReceiverQueue",
                         CA_STATUS_FAILED);
@@ -3803,7 +3397,6 @@ static CAResult_t CALEAdapterClientReceivedData(const char *remoteAddress,
     CAQueueingThreadAddData(g_bleClientReceiverQueue, bleData, sizeof(CALEData_t));
 
     *sentLength = dataLength;
-#endif
     return CA_STATUS_OK;
 }
 
@@ -3843,7 +3436,6 @@ static void CALEErrorHandler(const char *remoteAddress,
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "CALEErrorHandler OUT");
 }
 
-#ifndef SINGLE_THREAD
 static void CALERemoveSendQueueData(CAQueueingThread_t *queueHandle, oc_mutex mutex,
                                     const char* address)
 {
@@ -3970,4 +3562,3 @@ static CAResult_t CALEGetPortsFromSenderInfo(const char *leAddress,
         return CA_STATUS_FAILED;
     }
 }
-#endif
index 9e6fa2d..af9c526 100644 (file)
 #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
index e0d4e17..f450756 100644 (file)
@@ -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;
 }
 
 void CATerminateMessageHandler()
 {
-#ifndef SINGLE_THREAD
     // stop adapters
     CAStopAdapters();
 
@@ -1203,14 +1080,6 @@ void CATerminateMessageHandler()
 
     // terminate interface adapters by controller
     CATerminateAdapters();
-#else
-    // terminate interface adapters by controller
-    CATerminateAdapters();
-
-    // stop retransmission
-    CARetransmissionStop(&g_retransmissionContext);
-    CARetransmissionDestroy(&g_retransmissionContext);
-#endif // SINGLE_THREAD
 }
 
 static void CALogPayloadInfo(CAInfo_t *info)
@@ -1261,7 +1130,6 @@ void CAErrorHandler(const CAEndpoint_t *endpoint,
         return;
     }
 
-#ifndef SINGLE_THREAD
     uint32_t code = CA_NOT_FOUND;
     //Do not free remoteEndpoint and data. Currently they will be freed in data thread
     //Get PDU data
@@ -1318,9 +1186,6 @@ void CAErrorHandler(const CAEndpoint_t *endpoint,
 
     CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
     coap_delete_pdu(pdu);
-#else
-    (void)result;
-#endif
 
     OIC_LOG(DEBUG, TAG, "CAErrorHandler OUT");
     return;
@@ -1329,7 +1194,6 @@ void CAErrorHandler(const CAEndpoint_t *endpoint,
 static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info, CAResult_t result)
 {
     OIC_LOG(DEBUG, TAG, "CASendErrorInfo IN");
-#ifndef SINGLE_THREAD
     CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
     if (!cadata)
     {
@@ -1370,7 +1234,6 @@ static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info,
     cadata->dataType = CA_ERROR_DATA;
 
     CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
-#endif
     OIC_LOG(DEBUG, TAG, "CASendErrorInfo OUT");
 }
 
index 0e12e8f..70f712b 100644 (file)
@@ -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;
 }
 
index 7e66e66..47ece71 100644 (file)
@@ -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
index 92cd204..c2b8cd5 100644 (file)
@@ -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");
index 5799f32..adc070e 100644 (file)
@@ -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)
-    {
-        OIC_LOG_V(DEBUG, TAG, "CATCPStartServer failed[%d]", ret);
-        return ret;
-    }
-#endif
 
     return CA_STATUS_OK;
 }
 
 CAResult_t CAStartTCPListeningServer()
 {
-#ifndef SINGLE_THREAD
     if (!caglobals.server)
     {
         caglobals.server = true;    // only needed to run CA tests
@@ -445,7 +420,6 @@ CAResult_t CAStartTCPListeningServer()
         OIC_LOG_V(ERROR, TAG, "Failed to start listening server![%d]", ret);
         return ret;
     }
-#endif
 
     return CA_STATUS_OK;
 }
@@ -508,11 +482,7 @@ int32_t CASendTCPUnicastData(const CAEndpoint_t *endpoint,
         return -1;
     }
 
-#ifndef SINGLE_THREAD
     return CAQueueTCPData(false, endpoint, data, dataLength, false);
-#else
-    return (int32_t)CATCPSendData(endpoint, data, dataLength);
-#endif
 }
 
 int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
@@ -526,9 +496,6 @@ int32_t CASendTCPMulticastData(const CAEndpoint_t *endpoint,
 CAResult_t CAReadTCPData()
 {
     OIC_LOG(DEBUG, TAG, "IN");
-#ifdef SINGLE_THREAD
-    CATCPPullData();
-#endif
     return CA_STATUS_OK;
 }
 
@@ -536,13 +503,11 @@ CAResult_t CAStopTCP()
 {
     CAIPStopNetworkMonitor(CA_ADAPTER_TCP);
 
-#ifndef SINGLE_THREAD
     if (g_sendQueueHandle && g_sendQueueHandle->threadMutex)
     {
         CAQueueingThreadStop(g_sendQueueHandle);
     }
     CATCPDeinitializeQueueHandles();
-#endif
 
     CATCPStopServer();
 
@@ -697,54 +662,3 @@ void CADataDestroyer(void *data, uint32_t size)
     CAFreeTCPData(TCPData);
 }
 
-#ifdef SINGLE_THREAD
-size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t size)
-{
-    OIC_LOG(DEBUG, TAG, "IN - CAGetTotalLengthFromHeader");
-
-    if (NULL == recvBuffer || !size)
-    {
-        OIC_LOG(ERROR, TAG, "recvBuffer is NULL");
-        return 0;
-    }
-
-    coap_transport_t transport = coap_get_tcp_header_type_from_initbyte(
-            ((unsigned char *)recvBuffer)[0] >> 4);
-    size_t optPaylaodLen = coap_get_length_from_header((unsigned char *)recvBuffer,
-                                                        transport);
-    size_t headerLen = coap_get_tcp_header_length((unsigned char *)recvBuffer);
-
-    OIC_LOG_V(DEBUG, TAG, "option/paylaod length [%d]", optPaylaodLen);
-    OIC_LOG_V(DEBUG, TAG, "header length [%d]", headerLen);
-    OIC_LOG_V(DEBUG, TAG, "total data length [%d]", headerLen + optPaylaodLen);
-
-    OIC_LOG(DEBUG, TAG, "OUT - CAGetTotalLengthFromHeader");
-    return headerLen + optPaylaodLen;
-}
-
-void CAGetTCPHeaderDetails(unsigned char* recvBuffer, coap_transport_t *transport,
-                           size_t *headerlen)
-{
-    if (NULL == recvBuffer)
-    {
-        OIC_LOG(ERROR, TAG, "recvBuffer is NULL");
-        return;
-    }
-
-    if (NULL == transport)
-    {
-        OIC_LOG(ERROR, TAG, "transport is NULL");
-        return;
-    }
-
-    if (NULL == headerlen)
-    {
-        OIC_LOG(ERROR, TAG, "headerlen is NULL");
-        return;
-    }
-
-    *transport = coap_get_tcp_header_type_from_initbyte(
-        ((unsigned char *)recvBuffer)[0] >> 4);
-    *headerlen = coap_get_tcp_header_length_for_transport(*transport);
-}
-#endif
index a27225c..17ba381 100644 (file)
 #ifndef ROUTING_TABLE_MANAGER_H_
 #define ROUTING_TABLE_MANAGER_H_
 
-#ifndef SINGLE_THREAD
 #include <unistd.h>
 #include <time.h>
 #include <sys/time.h>
-#endif
 
 #if defined(__ANDROID__)
 #include <linux/time.h>