From: Abhishek Sharma Date: Thu, 18 Aug 2016 06:06:00 +0000 (+0530) Subject: Optimize stack for Arduino. X-Git-Tag: 1.3.0~1057^2~154 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a40e07bb0634b61a810ff1b0faf2c8b51f53cca2;p=platform%2Fupstream%2Fiotivity.git Optimize stack for Arduino. 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 Signed-off-by: Veeraj Khokale Reviewed-on: https://gerrit.iotivity.org/gerrit/10585 Tested-by: jenkins-iotivity Reviewed-by: Ashok Babu Channa --- diff --git a/resource/csdk/connectivity/api/cacommon.h b/resource/csdk/connectivity/api/cacommon.h index db06c44..9fd62d1 100644 --- a/resource/csdk/connectivity/api/cacommon.h +++ b/resource/csdk/connectivity/api/cacommon.h @@ -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. diff --git a/resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp b/resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp index e7706f1..1672e63 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp +++ b/resource/csdk/connectivity/src/bt_le_adapter/arduino/cableserver.cpp @@ -90,7 +90,7 @@ void CACheckLEDataInternal() return; } - while (CAIsLEDataAvailable()) + while (CAIsLEDataAvailable() && g_receivedDataLen <= bufSize) { g_coapBuffer[g_receivedDataLen++] = CALEReadData(); } diff --git a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c index a32949e..b1d19be 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c @@ -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; diff --git a/resource/csdk/connectivity/src/camessagehandler.c b/resource/csdk/connectivity/src/camessagehandler.c index 8cc0858..5f21a2e 100644 --- a/resource/csdk/connectivity/src/camessagehandler.c +++ b/resource/csdk/connectivity/src/camessagehandler.c @@ -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)) diff --git a/resource/csdk/stack/include/ocstackconfig.h b/resource/csdk/stack/include/ocstackconfig.h index 515d601..8eed88d 100644 --- a/resource/csdk/stack/include/ocstackconfig.h +++ b/resource/csdk/stack/include/ocstackconfig.h @@ -33,13 +33,21 @@ * 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 diff --git a/resource/csdk/stack/src/ocpayloadconvert.c b/resource/csdk/stack/src/ocpayloadconvert.c index 2552873..e3dd927 100644 --- a/resource/csdk/stack/src/ocpayloadconvert.c +++ b/resource/csdk/stack/src/ocpayloadconvert.c @@ -18,6 +18,10 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#ifdef ARDUINO +#define __STDC_LIMIT_MACROS +#endif + #include "ocpayloadcbor.h" #include "platform_features.h" #include diff --git a/resource/csdk/stack/src/rdpayload.c b/resource/csdk/stack/src/rdpayload.c index 0f82960..f265df2 100644 --- a/resource/csdk/stack/src/rdpayload.c +++ b/resource/csdk/stack/src/rdpayload.c @@ -17,6 +17,10 @@ // limitations under the License. // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#ifdef ARDUINO +#define __STDC_LIMIT_MACROS +#endif + #include "rdpayload.h" #include "oic_malloc.h"