X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fstack%2Fsrc%2Focclientcb.c;h=82f46ce401d84421bcb59d2050d9b0ca8b099c03;hb=c315c87e07c4080ecd0ef488e7a1047bc3c509b2;hp=39022c15068e7c656885a7ff17bab40ad88f5d04;hpb=8ba440a073c2b5496cfaa5e5606353dad515e3c0;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/stack/src/occlientcb.c b/resource/csdk/stack/src/occlientcb.c old mode 100644 new mode 100755 index 39022c1..82f46ce --- a/resource/csdk/stack/src/occlientcb.c +++ b/resource/csdk/stack/src/occlientcb.c @@ -18,59 +18,66 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - +#include "iotivity_config.h" #include "occlientcb.h" -#include "utlist.h" #include "logger.h" +#include "trace.h" #include "oic_malloc.h" #include -#ifdef WITH_ARDUINO -#include "Time.h" -#else +#ifdef HAVE_SYS_TIME_H #include #endif -#include "coap_time.h" +#ifdef HAVE_ARDUINO_TIME_H +#include "Time.h" +#endif #include "cacommon.h" #include "cainterface.h" +#include /// Module Name -#define TAG PCF("occlientcb") +#define TAG "OIC_RI_CLIENTCB" struct ClientCB *cbList = NULL; -static OCMulticastNode * mcPresenceNodes = NULL; OCStackResult AddClientCB (ClientCB** clientCB, OCCallbackData* cbData, CAToken_t token, uint8_t tokenLength, OCDoHandle *handle, OCMethod method, - char * requestUri, char * resourceTypeName, OCConnectivityType conType, uint32_t ttl) + OCDevAddr *devAddr, char * requestUri, + char * resourceTypeName, uint32_t ttl) { - if(!clientCB || !cbData || !handle || !requestUri || tokenLength > CA_MAX_TOKEN_LEN) + if (!clientCB || !cbData || !handle || tokenLength > CA_MAX_TOKEN_LEN) { return OC_STACK_INVALID_PARAM; } + OIC_TRACE_BEGIN(%s:AddClientCB, TAG); + ClientCB *cbNode = NULL; - #ifdef WITH_PRESENCE - if(method == OC_REST_PRESENCE) +#ifdef WITH_PRESENCE + if (method == OC_REST_PRESENCE) { // Retrieve the presence callback structure for this specific requestUri. cbNode = GetClientCB(NULL, 0, NULL, requestUri); } - #endif // WITH_PRESENCE - if(!cbNode)// If it does not already exist, create new node. + if (!cbNode)// If it does not already exist, create new node. +#endif // WITH_PRESENCE { cbNode = (ClientCB*) OICMalloc(sizeof(ClientCB)); - if(!cbNode) + if (!cbNode) { *clientCB = NULL; goto exit; } else { + OIC_LOG(INFO, TAG, "Adding client callback with token"); + OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength); + OIC_TRACE_BUFFER("OIC_RI_CLIENTCB:AddClientCB:token", + (const uint8_t *) token, tokenLength); cbNode->callBack = cbData->cb; cbNode->context = cbData->context; cbNode->deleteCallback = cbData->cd; @@ -81,12 +88,15 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData, cbNode->handle = *handle; cbNode->method = method; cbNode->sequenceNumber = 0; - #ifdef WITH_PRESENCE +#ifdef WITH_PRESENCE cbNode->presence = NULL; cbNode->filterResourceType = NULL; - #endif // WITH_PRESENCE +#endif // WITH_PRESENCE - if (method == OC_REST_PRESENCE || + if ( +#ifdef WITH_PRESENCE + method == OC_REST_PRESENCE || +#endif method == OC_REST_OBSERVE || method == OC_REST_OBSERVE_ALL) { @@ -96,12 +106,15 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData, { cbNode->TTL = ttl; } - cbNode->requestUri = requestUri; - cbNode->conType = conType; + cbNode->requestUri = requestUri; // I own it now + cbNode->devAddr = devAddr; // I own it now + OIC_LOG_V(INFO, TAG, "Added Callback for uri : %s", requestUri); + OIC_TRACE_MARK(%s:AddClientCB:uri:%s, TAG, requestUri); LL_APPEND(cbList, cbNode); *clientCB = cbNode; } } +#ifdef WITH_PRESENCE else { // Ensure that the handle the SDK hands back up to the application layer for the @@ -116,51 +129,64 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData, OICFree(token); OICFree(*handle); OICFree(requestUri); + OICFree(devAddr); *handle = cbNode->handle; } - #ifdef WITH_PRESENCE - if(method == OC_REST_PRESENCE && resourceTypeName) + if (method == OC_REST_PRESENCE && resourceTypeName) { + OIC_TRACE_END(); // Amend the found or created node by adding a new resourceType to it. return InsertResourceTypeFilter(cbNode,(char *)resourceTypeName); + // I own resourceTypName now. } else { OICFree(resourceTypeName); } - #else +#else OICFree(resourceTypeName); - #endif +#endif + OIC_TRACE_END(); return OC_STACK_OK; - exit: - return OC_STACK_NO_MEMORY; +exit: + OIC_TRACE_END(); + return OC_STACK_NO_MEMORY; } void DeleteClientCB(ClientCB * cbNode) { - if(cbNode) + OIC_TRACE_BEGIN(%s:DeleteClientCB, TAG); + if (cbNode) { LL_DELETE(cbList, cbNode); - OC_LOG(INFO, TAG, PCF("deleting tokens")); - OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)cbNode->token, cbNode->tokenLength); + OIC_LOG (INFO, TAG, "Deleting token"); + OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)cbNode->token, cbNode->tokenLength); + OIC_TRACE_BUFFER("OIC_RI_CLIENTCB:DeleteClientCB:token", + (const uint8_t *)cbNode->token, cbNode->tokenLength); CADestroyToken (cbNode->token); + OICFree(cbNode->devAddr); OICFree(cbNode->handle); - OICFree(cbNode->requestUri); - if(cbNode->deleteCallback) + if (cbNode->requestUri) + { + OIC_LOG_V (INFO, TAG, "Deleting callback with uri %s", cbNode->requestUri); + OIC_TRACE_MARK(%s:DeleteClientCB:uri:%s, TAG, cbNode->requestUri); + OICFree(cbNode->requestUri); + } + if (cbNode->deleteCallback) { cbNode->deleteCallback(cbNode->context); } - #ifdef WITH_PRESENCE - if(cbNode->presence) +#ifdef WITH_PRESENCE + if (cbNode->presence) { OICFree(cbNode->presence->timeOut); OICFree(cbNode->presence); } - if(cbNode->method == OC_REST_PRESENCE) + if (cbNode->method == OC_REST_PRESENCE) { OCResourceType * pointer = cbNode->filterResourceType; OCResourceType * next = NULL; @@ -172,10 +198,11 @@ void DeleteClientCB(ClientCB * cbNode) pointer = next; } } - #endif // WITH_PRESENCE +#endif // WITH_PRESENCE OICFree(cbNode); cbNode = NULL; } + OIC_TRACE_END(); } /* @@ -200,55 +227,61 @@ static void CheckAndDeleteTimedOutCB(ClientCB* cbNode) if (cbNode->TTL < now) { - OC_LOG(INFO, TAG, PCF("Deleting timed-out callback")); + OIC_LOG(INFO, TAG, "Deleting timed-out callback"); DeleteClientCB(cbNode); } } ClientCB* GetClientCB(const CAToken_t token, uint8_t tokenLength, - OCDoHandle handle, const char * requestUri) + OCDoHandle handle, const char * requestUri) { - ClientCB* out = NULL; - if(token && *token && tokenLength <= CA_MAX_TOKEN_LEN && tokenLength > 0) + if (token && tokenLength <= CA_MAX_TOKEN_LEN && tokenLength > 0) { + OIC_LOG (INFO, TAG, "Looking for token"); + OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength); LL_FOREACH(cbList, out) { - OC_LOG(INFO, TAG, PCF("comparing tokens")); - OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)token, tokenLength); - OC_LOG_BUFFER(INFO, TAG, (const uint8_t *)out->token, tokenLength); - - if(memcmp(out->token, token, tokenLength) == 0) + /* de-annotate below line if want to see all token in cbList */ + //OIC_LOG_BUFFER(INFO, TAG, (const uint8_t *)out->token, tokenLength); + if (memcmp(out->token, token, tokenLength) == 0) { + OIC_LOG(INFO, TAG, "Found in callback list"); return out; } CheckAndDeleteTimedOutCB(out); } } - else if(handle) + else if (handle) { + OIC_LOG (INFO, TAG, "Looking for handle"); LL_FOREACH(cbList, out) { - if(out->handle == handle) + if (out->handle == handle) { + OIC_LOG(INFO, TAG, "Found in callback list"); return out; } CheckAndDeleteTimedOutCB(out); } } - else if(requestUri) + else if (requestUri) { + OIC_LOG_V(INFO, TAG, "Looking for uri %s", requestUri); LL_FOREACH(cbList, out) { - if(out->requestUri && strcmp(out->requestUri, requestUri ) == 0) + /* de-annotate below line if want to see all uri in cbList */ + //OIC_LOG_V(INFO, TAG, "%s", out->requestUri); + if (out->requestUri && strcmp(out->requestUri, requestUri ) == 0) { + OIC_LOG(INFO, TAG, "Found in callback list"); return out; } CheckAndDeleteTimedOutCB(out); } } - OC_LOG(INFO, TAG, PCF("Callback Not found !!")); + OIC_LOG(INFO, TAG, "Callback Not found !!"); return NULL; } @@ -256,11 +289,11 @@ ClientCB* GetClientCB(const CAToken_t token, uint8_t tokenLength, OCStackResult InsertResourceTypeFilter(ClientCB * cbNode, char * resourceTypeName) { OCResourceType * newResourceType = NULL; - if(cbNode && resourceTypeName) + if (cbNode && resourceTypeName) { // Form a new resourceType member. newResourceType = (OCResourceType *) OICMalloc(sizeof(OCResourceType)); - if(!newResourceType) + if (!newResourceType) { return OC_STACK_NO_MEMORY; } @@ -289,7 +322,7 @@ void DeleteClientCBList() void FindAndDeleteClientCB(ClientCB * cbNode) { ClientCB* tmp; - if(cbNode) + if (cbNode) { LL_FOREACH(cbList, tmp) { @@ -301,45 +334,3 @@ void FindAndDeleteClientCB(ClientCB * cbNode) } } } - -OCStackResult AddMCPresenceNode(OCMulticastNode** outnode, char* uri, uint32_t nonce) -{ - if(!outnode) - { - return OC_STACK_INVALID_PARAM; - } - - OCMulticastNode *node; - - node = (OCMulticastNode*) OICMalloc(sizeof(OCMulticastNode)); - - if (node) - { - node->nonce = nonce; - node->uri = uri; - LL_APPEND(mcPresenceNodes, node); - *outnode = node; - return OC_STACK_OK; - } - *outnode = NULL; - return OC_STACK_NO_MEMORY; -} - -OCMulticastNode* GetMCPresenceNode(const char * uri) -{ - OCMulticastNode* out = NULL; - - if(uri) - { - LL_FOREACH(mcPresenceNodes, out) - { - if(out->uri && strcmp(out->uri, uri) == 0) - { - return out; - } - } - } - OC_LOG(INFO, TAG, PCF("MulticastNode Not found !!")); - return NULL; -} -