From 3a3631a0ddeb31bfbfdf9755c5bfe4ba9bf15a47 Mon Sep 17 00:00:00 2001 From: "sonu1.yadav" Date: Wed, 5 Aug 2015 16:17:33 +0530 Subject: [PATCH] Added significance of sequenceNumber in observe callback Change-Id: I40a9266d0cffcb09925b9dba06c60c39437e7482 Signed-off-by: sonu1.yadav Reviewed-on: https://gerrit.iotivity.org/gerrit/2117 Tested-by: jenkins-iotivity Reviewed-by: Mandeep Shetty Reviewed-by: Omkar Hegde Reviewed-by: Erich Keane --- examples/OICSensorBoard/client.cpp | 19 +++++++++++++++++-- resource/examples/simpleclient.cpp | 22 +++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/examples/OICSensorBoard/client.cpp b/examples/OICSensorBoard/client.cpp index 724735f..e76541d 100644 --- a/examples/OICSensorBoard/client.cpp +++ b/examples/OICSensorBoard/client.cpp @@ -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; + } } } diff --git a/resource/examples/simpleclient.cpp b/resource/examples/simpleclient.cpp index bb7620c..7106d9e 100644 --- a/resource/examples/simpleclient.cpp +++ b/resource/examples/simpleclient.cpp @@ -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:"<