Added significance of sequenceNumber in observe callback
authorsonu1.yadav <sonu1.yadav@samsung.com>
Wed, 5 Aug 2015 10:47:33 +0000 (16:17 +0530)
committerErich Keane <erich.keane@intel.com>
Thu, 6 Aug 2015 16:47:41 +0000 (16:47 +0000)
Change-Id: I40a9266d0cffcb09925b9dba06c60c39437e7482
Signed-off-by: sonu1.yadav <sonu1.yadav@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2117
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Mandeep Shetty <mandeep.shetty@intel.com>
Reviewed-by: Omkar Hegde <omkar.m.hegde@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
examples/OICSensorBoard/client.cpp
resource/examples/simpleclient.cpp

index 724735f..e76541d 100644 (file)
@@ -144,8 +144,16 @@ void TemperatureSensor::stopObserve()
 void TemperatureSensor::onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
                                   int eCode, int sequenceNumber)
 {
-    if (eCode == OC_STACK_OK)
+    if (eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION)
     {
+        if(sequenceNumber == OC_OBSERVE_REGISTER)
+        {
+            cout << "Observe registration action is successful" << endl;
+        }
+        else if(sequenceNumber == OC_OBSERVE_DEREGISTER)
+        {
+            cout << "Observe De-registration action is successful" << endl;
+        }
         double value;
         rep.getValue(TEMPERATURE_RESOURCE_KEY, value);
         cout << "Observing TemperatureSensor: Current temperature reading in Celsius is " << value << endl;
@@ -153,7 +161,14 @@ void TemperatureSensor::onObserve(const HeaderOptions headerOptions, const OCRep
     }
     else
     {
-        cerr << "TemperatureSensor: Observer response error" << endl;
+        if(sequenceNumber == OC_OBSERVE_NO_OPTION)
+        {
+            cerr << "Observe registration or de-registration action is failed" << endl;
+        }
+        else
+        {
+            cerr << "TemperatureSensor: Observer response error" << endl;
+        }
     }
 }
 
index bb7620c..7106d9e 100644 (file)
@@ -64,8 +64,17 @@ void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
 {
     try
     {
-        if(eCode == OC_STACK_OK)
+        if(eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION)
         {
+            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;
             rep.getValue("state", mylight.m_state);
@@ -89,8 +98,15 @@ void onObserve(const HeaderOptions headerOptions, const OCRepresentation& rep,
         }
         else
         {
-            std::cout << "onObserve Response error: " << eCode << std::endl;
-            std::exit(-1);
+            if(sequenceNumber == OC_OBSERVE_NO_OPTION)
+            {
+                std::cout << "Observe registration or de-registration action is failed" << std::endl;
+            }
+            else
+            {
+                std::cout << "onObserve Response error: " << eCode << std::endl;
+                std::exit(-1);
+            }
         }
     }
     catch(std::exception& e)