Change observe option header behaviour to be in line with spec
authorZiran Sun <ziran.sun@samsung.com>
Tue, 21 Jun 2016 13:30:35 +0000 (14:30 +0100)
committerZiran Sun <ziran.sun@samsung.com>
Thu, 30 Jun 2016 09:37:56 +0000 (09:37 +0000)
at the following points:

1. If the resource can't register the client as observer,
or the resource does not support observe, then the resource
sends back normal GET Response with NO observe option field.

2. Upon successfully removing the client from observer list,
the resource sends back a normal GET response with NO observe
option field

3. This patch also reverted https://gerrit.iotivity.org/gerrit/#/c/8901/
after discussed with the author to be inline with spec.

JIRA issue: https://jira.iotivity.org/browse/IOT-1122

Change-Id: I36510baa69a8ef3be9e0d9aef3fbd40d31488b0f
Signed-off-by: Ziran Sun <ziran.sun@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8815
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Mushfiqul Islam <i.mushfiq@samsung.com>
resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocserverrequest.c
resource/csdk/stack/src/ocstack.c
resource/examples/simpleclient.cpp

index bef3e98..538c8b5 100644 (file)
@@ -66,8 +66,8 @@ extern void* defaultDeviceHandlerCallbackParameter;
 /** The coap scheme */
 #define OC_COAP_SCHEME "coap://"
 
-/** the first outgoing sequence number will be 5*/
-#define OC_OFFSET_SEQUENCE_NUMBER (4)
+/** the first outgoing sequence number will be 2*/
+#define OC_OFFSET_SEQUENCE_NUMBER (1)
 
 /**
  * This structure will be created in occoap and passed up the stack on the server side.
index c51ac9e..1e72248 100755 (executable)
@@ -1103,13 +1103,13 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
         }
         else
         {
+            result = OC_STACK_OK;
+
             // The error in observeResult for the request will be used when responding to this
             // request by omitting the observation option/sequence number.
             request->observeResult = OC_STACK_ERROR;
             OIC_LOG(ERROR, TAG, "Observer Addition failed");
             ehFlag = OC_REQUEST_FLAG;
-            FindAndDeleteServerRequest(request);
-            goto exit;
         }
 
     }
@@ -1139,10 +1139,9 @@ HandleResourceWithEntityHandler (OCServerRequest *request,
         }
         else
         {
+            result = OC_STACK_OK;
             request->observeResult = OC_STACK_ERROR;
             OIC_LOG(ERROR, TAG, "Observer Removal failed");
-            FindAndDeleteServerRequest(request);
-            goto exit;
         }
     }
     else
index 9ee0395..27ba09f 100644 (file)
@@ -555,7 +555,8 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse)
     memcpy(responseInfo.info.token, serverRequest->requestToken, serverRequest->tokenLength);
     responseInfo.info.tokenLength = serverRequest->tokenLength;
 
-    if(serverRequest->observeResult == OC_STACK_OK)
+    // De-register observe option should not be included in the response header
+    if((serverRequest->observeResult == OC_STACK_OK) && (serverRequest->observationOption != OC_OBSERVE_DEREGISTER))
     {
         responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions + 1;
     }
index 902c70b..398cad3 100644 (file)
@@ -1151,7 +1151,7 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp
 
             OCClientResponse response =
                 {.devAddr = {.adapter = OC_DEFAULT_ADAPTER}};
-            response.sequenceNumber = OC_OBSERVE_NO_OPTION;
+            response.sequenceNumber = -1;
             CopyEndpointToDevAddr(endPoint, &response.devAddr);
             FixUpClientResponse(&response);
             response.resourceUri = responseInfo->info.resourceUri;
index 07d55f0..42c0d6f 100644 (file)
@@ -65,16 +65,12 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re
 {
     try
     {
-        if(eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION)
+        if(eCode == OC_STACK_OK && sequenceNumber != -1)
         {
             if(sequenceNumber == OC_OBSERVE_REGISTER)
             {
                 std::cout << "Observe registration action is successful" << std::endl;
             }
-            else if(sequenceNumber == OC_OBSERVE_DEREGISTER)
-            {
-                std::cout << "Observe De-registration action is successful" << std::endl;
-            }
 
             std::cout << "OBSERVE RESULT:"<<std::endl;
             std::cout << "\tSequenceNumber: "<< sequenceNumber << std::endl;
@@ -99,9 +95,9 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re
         }
         else
         {
-            if(sequenceNumber == OC_OBSERVE_NO_OPTION)
+            if(eCode == OC_STACK_OK)
             {
-                std::cout << "Observe registration or de-registration action is failed" << std::endl;
+                std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl;
             }
             else
             {
@@ -469,7 +465,7 @@ int main(int argc, char* argv[]) {
         OC::ModeType::Both,
         "0.0.0.0",
         0,
-        OC::QualityOfService::LowQos,
+        OC::QualityOfService::HighQos,
         &ps
     };