Optimize stack for Arduino.
authorAbhishek Sharma <ce.abhishek@samsung.com>
Thu, 18 Aug 2016 06:06:00 +0000 (11:36 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 14 Sep 2016 13:53:33 +0000 (13:53 +0000)
In RI, headeroptions are maintained as array with default size as this macro.
A default 100 headeroptions are too high and results in a structure size of 3KB+.
Moreover any vendor will not add 100 CoAP options.
Also optimized few clonings.

Change-Id: I65860c44ec1ba0c3ef2800a88f27ecad0f483568
Signed-off-by: Abhishek Sharma <ce.abhishek@samsung.com>
Signed-off-by: Veeraj Khokale <veeraj.sk@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10585
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
(cherry picked from commit a40e07bb0634b61a810ff1b0faf2c8b51f53cca2)
Reviewed-on: https://gerrit.iotivity.org/gerrit/11777

resource/csdk/connectivity/api/cacommon.h
resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/camessagehandler.c
resource/csdk/stack/include/ocstackconfig.h
resource/csdk/stack/src/ocpayloadconvert.c
resource/csdk/stack/src/rdpayload.c

index db06c44..9fd62d1 100644 (file)
@@ -70,7 +70,11 @@ extern "C"
 /**
  * Max header options data length.
  */
+#ifdef ARDUINO
+#define CA_MAX_HEADER_OPTION_DATA_LENGTH 20
+#else
 #define CA_MAX_HEADER_OPTION_DATA_LENGTH 1024
+#endif
 
 /**
 * Max token length.
index e7706f1..1672e63 100644 (file)
@@ -90,7 +90,7 @@ void CACheckLEDataInternal()
                 return;
             }
 
-            while (CAIsLEDataAvailable())
+            while (CAIsLEDataAvailable() && g_receivedDataLen <= bufSize)
             {
                 g_coapBuffer[g_receivedDataLen++] = CALEReadData();
             }
index a32949e..b1d19be 100644 (file)
@@ -3176,6 +3176,7 @@ static CAResult_t CALEAdapterServerReceivedData(const char *remoteAddress,
                                             g_singleThreadReceiveData->recvDataLen);
         }
         g_singleThreadReceiveData->remoteEndpoint = NULL;
+        OICFree(g_singleThreadReceiveData->defragData);
         g_singleThreadReceiveData->defragData = NULL;
         OICFree(g_singleThreadReceiveData);
         g_singleThreadReceiveData = NULL;
index 8cc0858..5f21a2e 100644 (file)
@@ -130,13 +130,16 @@ 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);
 
@@ -234,7 +237,9 @@ static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
 
 exit:
     OICFree(cadata);
+#ifndef SINGLE_THREAD
     CAFreeEndpoint(ep);
+#endif
     return NULL;
 }
 
@@ -242,20 +247,25 @@ 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;
     }
 
@@ -269,7 +279,9 @@ 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;
     }
 
@@ -277,7 +289,9 @@ 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;
     }
@@ -320,11 +334,12 @@ 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)
     {
@@ -874,29 +889,33 @@ 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)
         {
             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)
         {
             OIC_LOG(ERROR, TAG, "CACloneResponseInfo failed");
             goto exit;
         }
-
+#endif
         cadata->type = response->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
         cadata->responseInfo = response;
     }
@@ -906,19 +925,26 @@ 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;
 }
 
@@ -954,11 +980,12 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
     if (CA_STATUS_OK != result)
     {
         OIC_LOG(ERROR, TAG, "CAProcessSendData failed");
-        CADestroyData(data, sizeof(CAData_t));
+        OICFree(data);
         return result;
     }
 
-    CADestroyData(data, sizeof(CAData_t));
+    OICFree(data);
+
 #else
 #ifdef WITH_BWT
     if (CAIsSupportedBlockwiseTransfer(endpoint->adapter))
index 515d601..8eed88d 100644 (file)
  * Maximum length of the URI supported by client/server while processing
  * REST requests/responses.
  */
+#ifdef ARDUINO
+#define MAX_URI_LENGTH (64)
+#else
 #define MAX_URI_LENGTH (256)
+#endif
 
 /**
  * Maximum length of the query supported by client/server while processing
  * REST requests/responses.
  */
+#ifdef ARDUINO
+#define MAX_QUERY_LENGTH (64)
+#else
 #define MAX_QUERY_LENGTH (256)
+#endif
 
 /**
  * Maximum length of the Manufacturer name supported by the server
index 2552873..e3dd927 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#ifdef ARDUINO
+#define __STDC_LIMIT_MACROS
+#endif
+
 #include "ocpayloadcbor.h"
 #include "platform_features.h"
 #include <stdlib.h>
index 0f82960..f265df2 100644 (file)
 // limitations under the License.
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+#ifdef ARDUINO
+#define __STDC_LIMIT_MACROS
+#endif
+
 #include "rdpayload.h"
 
 #include "oic_malloc.h"