Add client side logic when obs request failed.
authorbg.chun <bg.chun@samsung.com>
Wed, 19 Oct 2016 07:30:48 +0000 (16:30 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 7 Dec 2016 04:37:01 +0000 (04:37 +0000)
Add client side logic and fix example.

Change-Id: Iffedfddde5906a5d27fd7cbad0176197730d89e3
Signed-off-by: bg.chun <bg.chun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13783
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp
resource/csdk/stack/src/ocstack.c

index f8d58db..09321f2 100644 (file)
@@ -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");
+                        }
                     }
                 }
             }
index 7ff1551..de6c911 100644 (file)
@@ -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");