From: Mandeep Shetty Date: Tue, 6 Oct 2015 00:02:47 +0000 (-0700) Subject: Change occlient to cancel observe on every registration. X-Git-Tag: 1.2.0+RC1~865 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c11a5b681ebd04b6d8dd423f7f6f155a7a4cb22e;p=platform%2Fupstream%2Fiotivity.git Change occlient to cancel observe on every registration. In the case when there are multiple servers, occlient sends out observer requests to all of them. On reaching 15 notifications, only one of the observation registrations were cancelled. As the handle for cancellation was maintained in a global variable, none of the others were cancelled and the client continued to get notifications and this led to some failed tests. Changed client behavior to cancel observe wit the handle present in the response. This can be cherry-picked to 1.0.0-dev Change-Id: I51d28620b140dbb4f28baef7aa3be93276f6de5f Signed-off-by: Mandeep Shetty Reviewed-on: https://gerrit.iotivity.org/gerrit/3535 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp index d1ea32e..dca270d 100644 --- a/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp +++ b/resource/csdk/stack/samples/linux/SimpleClientServer/occlient.cpp @@ -60,8 +60,6 @@ static std::string coapServerResource = "/a/light"; void StripNewLineChar(char* str); -// The handle for the observe registration -OCDoHandle gObserveDoHandle; #ifdef WITH_PRESENCE // The handle for observe registration OCDoHandle gPresenceHandle; @@ -162,10 +160,6 @@ OCStackResult InvokeOCDoResource(std::ostringstream &query, { OC_LOG_V(ERROR, TAG, "OCDoResource returns error %d with method %d", ret, method); } - else if (method == OC_REST_OBSERVE || method == OC_REST_OBSERVE_ALL) - { - gObserveDoHandle = handle; - } #ifdef WITH_PRESENCE else if (method == OC_REST_PRESENCE) { @@ -279,7 +273,7 @@ OCStackApplicationResult getReqCB(void* ctx, OCDoHandle /*handle*/, return OC_STACK_DELETE_TRANSACTION; } -OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle /*handle*/, +OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse) { if (ctx == (void*)DEFAULT_CONTEXT_VALUE) @@ -296,11 +290,12 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle /*handle*/, OC_LOG_PAYLOAD(INFO, clientResponse->payload); OC_LOG(INFO, TAG, ("=============> Obs Response")); gNumObserveNotifies++; - if (gNumObserveNotifies == 15) //large number to test observing in DELETE case. + if (gNumObserveNotifies > 15) //large number to test observing in DELETE case. { if (TestCase == TEST_OBS_REQ_NON || TestCase == TEST_OBS_REQ_CON) { - if (OCCancel (gObserveDoHandle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK) + OC_LOG(ERROR, TAG, "Cancelling with LOW QOS"); + if (OCCancel (handle, OC_LOW_QOS, NULL, 0) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "Observe cancel error"); } @@ -308,7 +303,8 @@ OCStackApplicationResult obsReqCB(void* ctx, OCDoHandle /*handle*/, } else if (TestCase == TEST_OBS_REQ_NON_CANCEL_IMM) { - if (OCCancel (gObserveDoHandle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) + OC_LOG(ERROR, TAG, "Cancelling with HIGH QOS"); + if (OCCancel (handle, OC_HIGH_QOS, NULL, 0) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "Observe cancel error"); }