From: Ziran Sun Date: Mon, 12 Sep 2016 12:42:45 +0000 (+0100) Subject: Correct observe callback function in occlient. X-Git-Tag: 1.2.0+RC4~68 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c6f62d42f0e4377ef03cf29162845f24352224d6;p=platform%2Fupstream%2Fiotivity.git Correct observe callback function in occlient. 1. For observe register request, Sequence number received in client response falls in range 0 - MAX_SEQUENCE_NUMBER. 2. For observe deregister request and or any failed requests, the client sequence number value is MAX_SEQUENCE_NUMBER + 1. Change-Id: Idcc0775179e17ce6df85fb93f127336fede9a42a Signed-off-by: Ziran Sun Reviewed-on: https://gerrit.iotivity.org/gerrit/11695 Reviewed-by: Habib Virji Reviewed-by: Phil Coval Tested-by: jenkins-iotivity (cherry picked from commit 7ed91f143c91ce4d7522faad5f772e55a41ac0da) Reviewed-on: https://gerrit.iotivity.org/gerrit/12789 --- diff --git a/cloud/samples/client/airconditioner/aircon_controller.cpp b/cloud/samples/client/airconditioner/aircon_controller.cpp index 2ae86a4..344ac22 100644 --- a/cloud/samples/client/airconditioner/aircon_controller.cpp +++ b/cloud/samples/client/airconditioner/aircon_controller.cpp @@ -13,8 +13,6 @@ #include #include -#define maxSequenceNumber 0xFFFFFF - using namespace OC; using namespace std; @@ -118,7 +116,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation &re { try { - if (eCode == OC_STACK_OK && sequenceNumber != maxSequenceNumber + 1) + if (eCode == OC_STACK_OK && sequenceNumber <= MAX_SEQUENCE_NUMBER) { if (sequenceNumber == OC_OBSERVE_REGISTER) { diff --git a/cloud/samples/client/group_invite/group_invite.cpp b/cloud/samples/client/group_invite/group_invite.cpp index 812e76e..ec85e5e 100644 --- a/cloud/samples/client/group_invite/group_invite.cpp +++ b/cloud/samples/client/group_invite/group_invite.cpp @@ -37,8 +37,6 @@ using namespace std; using namespace OC; -#define maxSequenceNumber 0xFFFFFF - void printRepresentation(OCRepresentation rep) { for (auto itr = rep.begin(); itr != rep.end(); ++itr) @@ -102,7 +100,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation &re { try { - if (eCode == OC_STACK_OK && sequenceNumber != maxSequenceNumber + 1) + if (eCode == OC_STACK_OK && sequenceNumber <= MAX_SEQUENCE_NUMBER) { if (sequenceNumber == OC_OBSERVE_REGISTER) { @@ -392,4 +390,4 @@ int main(int argc, char *argv[]) exit: return 0; -} \ No newline at end of file +} diff --git a/cloud/samples/client/messagequeue/mq_subscriber.cpp b/cloud/samples/client/messagequeue/mq_subscriber.cpp index 4263760..fbebe6e 100644 --- a/cloud/samples/client/messagequeue/mq_subscriber.cpp +++ b/cloud/samples/client/messagequeue/mq_subscriber.cpp @@ -41,7 +41,6 @@ using namespace OC; using namespace std; #define DEFAULT_MQ_BROKER_URI "/oic/ps" -#define maxSequenceNumber 0xFFFFFF OC::OCResource::Ptr g_mqBrokerResource = nullptr; OC::OCResource::Ptr g_mqSelectedTopicResource = nullptr; @@ -96,7 +95,7 @@ void subscribeCB(const HeaderOptions &, { try { - if (eCode == OC_STACK_OK && sequenceNumber != maxSequenceNumber + 1) + if (eCode == OC_STACK_OK && sequenceNumber <= MAX_SEQUENCE_NUMBER) { if (sequenceNumber == OC_OBSERVE_REGISTER) { @@ -307,4 +306,4 @@ int main(int argc, char *argv[]) exit: return 0; -} \ No newline at end of file +} diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index 3c5470f..91e445a 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -289,45 +289,46 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, if (clientResponse) { - 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->sequenceNumber <= MAX_SEQUENCE_NUMBER) { - if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON) + if (clientResponse->sequenceNumber == OC_OBSERVE_REGISTER) { - 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; + OIC_LOG(INFO, TAG, "This also serves as a registration confirmation."); } - else if (TestCase == TEST_OBS_REQ_NON_CANCEL_IMM) + + 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. { - OIC_LOG(ERROR, TAG, "Cancelling with HIGH QOS"); - if (OCCancel (handle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) + if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON) + { + 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; + } + 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"); + } } } } - if (clientResponse->sequenceNumber == OC_OBSERVE_REGISTER) - { - OIC_LOG(INFO, TAG, "This also serves as a registration confirmation"); - } - else if (clientResponse->sequenceNumber == OC_OBSERVE_DEREGISTER) - { - OIC_LOG(INFO, TAG, "This also serves as a deregistration confirmation"); - return OC_STACK_DELETE_TRANSACTION; - } - else if (clientResponse->sequenceNumber == OC_OBSERVE_NO_OPTION) + else { - OIC_LOG(INFO, TAG, "This also tells you that registration/deregistration failed"); + OIC_LOG(INFO, TAG, "No observe option header is returned in the response."); + OIC_LOG(INFO, TAG, "For a registration request, it means the registration failed"); return OC_STACK_DELETE_TRANSACTION; } } diff --git a/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp index 8b3d86e..fe1f95f 100644 --- a/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/tizen/SimpleClientServer/occlient.cpp @@ -289,41 +289,42 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle /*handle*/, if (clientResponse) { - cout << "\nStackResult: " << getResult(clientResponse->result); - cout << "\nSEQUENCE NUMBER: " << clientResponse->sequenceNumber; - cout << "\nCallback Context for OBSERVE notification recvd successfully "; - //OIC_LOG_PAYLOAD(INFO, clientResponse->payload); - gNumObserveNotifies++; - if (gNumObserveNotifies == 15) //large number to test observing in DELETE case. + if (clientResponse->sequenceNumber <= MAX_SEQUENCE_NUMBER) { - if (g_testCase == TEST_OBS_REQ_NON || g_testCase == TEST_OBS_REQ_CON) + if (clientResponse->sequenceNumber == OC_OBSERVE_REGISTER) { - if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK) - { - cout << "\nObserve cancel error"; - } - return OC_STACK_DELETE_TRANSACTION; + cout << "This also serves as a registration confirmation" << endl; } - else if (g_testCase == TEST_OBS_REQ_NON_CANCEL_IMM) + + cout << "\nStackResult: " << getResult(clientResponse->result); + cout << "\nSEQUENCE NUMBER: " << clientResponse->sequenceNumber; + cout << "\nCallback Context for OBSERVE notification recvd successfully "; + //OIC_LOG_PAYLOAD(INFO, clientResponse->payload); + gNumObserveNotifies++; + + if (gNumObserveNotifies == 15) //large number to test observing in DELETE case. { - if (OCCancel (gObserveDoHandle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) + if (g_testCase == TEST_OBS_REQ_NON || g_testCase == TEST_OBS_REQ_CON) + { + if (OCCancel(gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK) + { + cout << "Observe cancel error" << endl; + } + return OC_STACK_DELETE_TRANSACTION; + } + else if (g_testCase == TEST_OBS_REQ_NON_CANCEL_IMM) { - cout << "\nObserve cancel error"; + if (OCCancel(gObserveDoHandle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) + { + cout << "\nObserve cancel error"; + } } } } - if (clientResponse->sequenceNumber == OC_OBSERVE_REGISTER) - { - cout << "\nThis also serves as a registration confirmation"; - } - else if (clientResponse->sequenceNumber == OC_OBSERVE_DEREGISTER) - { - cout << "\nThis also serves as a deregistration confirmation"; - return OC_STACK_DELETE_TRANSACTION; - } - else if (clientResponse->sequenceNumber == OC_OBSERVE_NO_OPTION) + else { - cout << "\nThis also tells you that registration/deregistration failed"; + OIC_LOG(INFO, TAG, "No observe option header is returned in the response."); + OIC_LOG(INFO, TAG, "For a registration request, it means the registration failed"); return OC_STACK_DELETE_TRANSACTION; } } diff --git a/resource/examples/simpleclient.cpp b/resource/examples/simpleclient.cpp index a2997bc..924e88c 100644 --- a/resource/examples/simpleclient.cpp +++ b/resource/examples/simpleclient.cpp @@ -38,8 +38,6 @@ #include "OCPlatform.h" #include "OCApi.h" -#define maxSequenceNumber 0xFFFFFF - using namespace OC; static const char* SVR_DB_FILE_NAME = "./oic_svr_db_client.dat"; @@ -77,7 +75,7 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re { try { - if(eCode == OC_STACK_OK && sequenceNumber != maxSequenceNumber + 1) + if(eCode == OC_STACK_OK && sequenceNumber <= MAX_SEQUENCE_NUMBER) { if(sequenceNumber == OC_OBSERVE_REGISTER) { @@ -109,7 +107,9 @@ void onObserve(const HeaderOptions /*headerOptions*/, const OCRepresentation& re { if(eCode == OC_STACK_OK) { - std::cout << "Observe registration failed or de-registration action failed/succeeded" << std::endl; + std::cout << "No observe option header is returned in the response." << std::endl; + std::cout << "For a registration request, it means the registration failed" + << std::endl; } else { diff --git a/resource/examples/winuiclient.cpp b/resource/examples/winuiclient.cpp index 87a7b6a..1b892cd 100644 --- a/resource/examples/winuiclient.cpp +++ b/resource/examples/winuiclient.cpp @@ -189,7 +189,7 @@ void WinUIClientApp::onGet(const HeaderOptions& /*headerOptions*/, const OCRepre { try { - if (eCode == OC_STACK_OK) + if (OC_STACK_OK == eCode) { std::cout << "GET request was successful" << std::endl; std::cout << "Resource URI: " << rep.getUri() << std::endl; @@ -241,7 +241,7 @@ void WinUIClientApp::onPut(const HeaderOptions& /*headerOptions*/, const OCRepre { try { - if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CHANGED) + if (OC_STACK_OK == eCode || OC_STACK_RESOURCE_CHANGED == eCode) { std::cout << "PUT request was successful" << std::endl; @@ -288,8 +288,8 @@ void WinUIClientApp::onPost(const HeaderOptions& /*headerOptions*/, { try { - if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED - || OC_STACK_RESOURCE_CHANGED) + if (OC_STACK_OK == eCode || (OC_STACK_RESOURCE_CREATED == eCode + || OC_STACK_RESOURCE_CHANGED == eCode)) { std::cout << "POST request was successful" << std::endl; @@ -327,7 +327,7 @@ void WinUIClientApp::onPost2(const HeaderOptions& /*headerOptions*/, { try { - if (eCode == OC_STACK_OK || eCode == OC_STACK_RESOURCE_CREATED) + if (OC_STACK_OK == eCode || OC_STACK_RESOURCE_CREATED == eCode) { std::cout << "POST request was successful" << std::endl; @@ -366,16 +366,12 @@ void WinUIClientApp::onObserve(const HeaderOptions /*headerOptions*/, const OCRe { try { - if (eCode == OC_STACK_OK && sequenceNumber != OC_OBSERVE_NO_OPTION) + if (OC_STACK_OK == eCode && sequenceNumber <= MAX_SEQUENCE_NUMBER) { 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:"<