From: bg.chun Date: Wed, 19 Oct 2016 07:30:48 +0000 (+0900) Subject: Add client side logic when obs request failed. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e589beb7cefc15365f903e98ba0ef16f1cafc4dd;p=contrib%2Fiotivity.git Add client side logic when obs request failed. Add client side logic and fix example. Change-Id: Iffedfddde5906a5d27fd7cbad0176197730d89e3 Signed-off-by: bg.chun Reviewed-on: https://gerrit.iotivity.org/gerrit/13783 Tested-by: jenkins-iotivity Reviewed-by: Dan Mihai Reviewed-by: Ashok Babu Channa --- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index f8d58db..09321f2 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -304,29 +304,33 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OIC_LOG_V(INFO, TAG, "StackResult: %s", getResult(clientResponse->result)); OIC_LOG_V(INFO, TAG, "SEQUENCE NUMBER: %d", clientResponse->sequenceNumber); - OIC_LOG_V(INFO, TAG, "Callback Context for OBSERVE notification recvd successfully %d", - gNumObserveNotifies); - OIC_LOG_PAYLOAD(INFO, clientResponse->payload); - OIC_LOG(INFO, TAG, ("=============> Obs Response")); - gNumObserveNotifies++; - if (gNumObserveNotifies > 15) //large number to test observing in DELETE case. + if (clientResponse->result == OC_STACK_OK) { - if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON) + OIC_LOG_V(INFO, TAG, "Callback Context for OBSERVE notification recvd successfully %d", + gNumObserveNotifies); + OIC_LOG_PAYLOAD(INFO, clientResponse->payload); + OIC_LOG(INFO, TAG, ("=============> Obs Response")); + gNumObserveNotifies++; + + if (gNumObserveNotifies > 15) //large number to test observing in DELETE case. { - OIC_LOG(ERROR, TAG, "Cancelling with LOW QOS"); - if (OCCancel (handle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK) + if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON) { - OIC_LOG(ERROR, TAG, "Observe cancel error"); + OIC_LOG(ERROR, TAG, "Cancelling with LOW QOS"); + if (OCCancel (handle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK) + { + OIC_LOG(ERROR, TAG, "Observe cancel error"); + } + return OC_STACK_DELETE_TRANSACTION; } - return OC_STACK_DELETE_TRANSACTION; - } - else if (TestCase == TEST_OBS_REQ_NON_CANCEL_IMM) - { - OIC_LOG(ERROR, TAG, "Cancelling with HIGH QOS"); - if (OCCancel (handle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) + else if (TestCase == TEST_OBS_REQ_NON_CANCEL_IMM) { - OIC_LOG(ERROR, TAG, "Observe cancel error"); + OIC_LOG(ERROR, TAG, "Cancelling with HIGH QOS"); + if (OCCancel (handle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) + { + OIC_LOG(ERROR, TAG, "Observe cancel error"); + } } } } diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index 7ff1551..de6c911 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1228,6 +1228,11 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp if(cbNode) { OIC_LOG(INFO, TAG, "There is a cbNode associated with the response token"); + uint32_t obsHeaderOpt = OC_OBSERVE_NO_OPTION; + uint8_t tempNumOpt = responseInfo->info.numOptions; + GetObserveHeaderOption(&obsHeaderOpt, responseInfo->info.options, + &tempNumOpt); + if(responseInfo->result == CA_EMPTY) { OIC_LOG(INFO, TAG, "Receiving A ACK/RESET for this token"); @@ -1259,6 +1264,25 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp cbNode->handle, &response); FindAndDeleteClientCB(cbNode); } + else if ((cbNode->method == OC_REST_OBSERVE || cbNode->method == OC_REST_OBSERVE_ALL) + && (responseInfo->result == CA_CONTENT) + && (obsHeaderOpt == OC_OBSERVE_NO_OPTION)) + { + OCClientResponse response = + {.devAddr = {.adapter = OC_DEFAULT_ADAPTER}}; + CopyEndpointToDevAddr(endPoint, &response.devAddr); + FixUpClientResponse(&response); + response.resourceUri = responseInfo->info.resourceUri; + memcpy(response.identity.id, responseInfo->info.identity.id, + sizeof (response.identity.id)); + response.identity.id_length = responseInfo->info.identity.id_length; + response.result = OC_STACK_UNAUTHORIZED_REQ; + + cbNode->callBack(cbNode->context, + cbNode->handle, + &response); + FindAndDeleteClientCB(cbNode); + } else { OIC_LOG(INFO, TAG, "This is a regular response, A client call back is found");