Fix bug for invalid remove a context at request.
authorKIM JungYong <jyong2.kim@samsung.com>
Mon, 10 Oct 2016 08:56:18 +0000 (17:56 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 12 Oct 2016 11:27:31 +0000 (11:27 +0000)
When receive responce of getting topic information,
consumer serivce remove context manually.
But, it is the invalid way.
With this patch, consumer service does not remove manually.
Context will be removed automatically by RI layer.

Change-Id: I1278dc13bf297b95e513d364f243064b525a7083
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13025
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/consumer/NSConsumerCommon.c
service/notification/src/consumer/NSConsumerCommon.h
service/notification/src/consumer/NSConsumerCommunication.c
service/notification/src/consumer/NSConsumerDiscovery.c
service/notification/src/consumer/NSConsumerNetworkEventListener.c

index e7940ba..eb58f6b 100644 (file)
@@ -523,9 +523,11 @@ NSProvider * NSCopyProvider(NSProvider_internal * prov)
     return newProv;
 }
 
-void NSRemoveProvider_internal(NSProvider_internal * prov)
+void NSRemoveProvider_internal(void * data)
 {
-    NS_VERIFY_NOT_NULL_V(prov);
+    NS_VERIFY_NOT_NULL_V(data);
+
+    NSProvider_internal * prov = data;
 
     NSOICFree(prov->messageUri);
     NSOICFree(prov->syncUri);
@@ -548,7 +550,8 @@ void NSRemoveProvider(NSProvider * prov)
 OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
         const char * queryUrl, OCPayload * payload,
-        void * callbackFunc, void * callbackData, OCConnectivityType type)
+        void * callbackFunc, void * callbackData,
+        OCClientContextDeleter cd, OCConnectivityType type)
 {
     int mutexRet = pthread_mutex_lock(*(NSGetStackMutex()));
     NS_VERIFY_NOT_NULL(mutexRet != 0 ? NULL : (void *)1, OC_STACK_ERROR);
@@ -557,7 +560,7 @@ OCStackResult NSInvokeRequest(OCDoHandle * handle,
 
     cbdata.cb = callbackFunc;
     cbdata.context = callbackData;
-    cbdata.cd = NULL;
+    cbdata.cd = cd;
 
     OCStackResult ret = OCDoResource(handle, method, queryUrl, addr,
                                      payload, type, NS_QOS, &cbdata, NULL, 0);
index 5b5dc87..121766d 100644 (file)
@@ -126,7 +126,7 @@ void NSRemoveConnections(NSProviderConnectionInfo *);
 
 NSProvider_internal * NSCopyProvider_internal(NSProvider_internal *);
 NSProvider * NSCopyProvider(NSProvider_internal *);
-void NSRemoveProvider_internal(NSProvider_internal *);
+void NSRemoveProvider_internal(void *);
 void NSRemoveProvider(NSProvider *);
 
 NSTopicLL * NSCopyTopicNode(NSTopicLL *);
@@ -139,7 +139,8 @@ void NSRemoveTopicLL(NSTopicLL *);
 OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
         const char * queryUrl, OCPayload * payload,
-        void * callbackFunc, void * callbackData, OCConnectivityType type);
+        void * callbackFunc, void * callbackData,
+        OCClientContextDeleter cd, OCConnectivityType type);
 
 bool NSOCResultToSuccess(OCStackResult ret);
 
index c9a85f2..b4e0d8a 100644 (file)
@@ -95,7 +95,7 @@ NSResult NSConsumerSubscribeProvider(NSProvider * provider)
         NS_LOG_V(DEBUG, "subscribe query : %s", query);
         OCStackResult ret = NSInvokeRequest(&(connections->messageHandle),
                               OC_REST_OBSERVE, connections->addr, query, NULL,
-                              NSConsumerMessageListener, NULL, type);
+                              NSConsumerMessageListener, NULL, NULL, type);
         NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(NSOCResultToSuccess(ret),
                             NS_ERROR, NSUpdateObserveResult(provider_internal, query));
         NSOICFree(query);
@@ -109,7 +109,7 @@ NSResult NSConsumerSubscribeProvider(NSProvider * provider)
         NS_LOG_V(DEBUG, "subscribe query : %s", query);
         ret = NSInvokeRequest(&(connections->syncHandle),
                               OC_REST_OBSERVE, connections->addr, query, NULL,
-                              NSConsumerSyncInfoListener, NULL, type);
+                              NSConsumerSyncInfoListener, NULL, NULL, type);
         NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(NSOCResultToSuccess(ret),
                             NS_ERROR, NSUpdateObserveResult(provider_internal, query));
         NSOICFree(query);
@@ -529,7 +529,7 @@ OCStackResult NSSendSyncInfo(NSSyncInfo * syncInfo, OCDevAddr * addr)
 
     OCStackResult ret = NSInvokeRequest(NULL, OC_REST_POST, addr,
                             uri, (OCPayload*)payload,
-                            NSConsumerCheckPostResult, NULL, type);
+                            NSConsumerCheckPostResult, NULL, NULL, type);
     NSOICFree(uri);
 
     return ret;
@@ -603,10 +603,13 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
             connections->isSubscribing = false;
             connections = connections->next;
         }
+
+        NSRemoveProvider_internal(provider);
     }
     else if (task->taskType == TASK_CONSUMER_REQ_TOPIC_LIST)
     {
-        NSProvider_internal * provider = (NSProvider_internal *)task->taskData;
+        NSProvider_internal * provider = NSCopyProvider_internal(task->taskData);
+        NSRemoveProvider_internal((NSProvider_internal *)task->taskData);
 
         NSProviderConnectionInfo * connections = provider->connection;
         NS_VERIFY_NOT_NULL_V(connections);
@@ -631,7 +634,8 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
         NS_LOG_V(DEBUG, "topic query : %s", query);
 
         OCStackResult ret = NSInvokeRequest(NULL, OC_REST_GET, connections->addr,
-                                query, NULL, NSIntrospectTopic, (void *) provider, type);
+                                query, NULL, NSIntrospectTopic, (void *) provider,
+                                NSRemoveProvider_internal, type);
         NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
 
         NSOICFree(query);
@@ -713,9 +717,11 @@ void NSConsumerCommunicationTaskProcessing(NSTask * task)
         NS_LOG_V(DEBUG, "topic query : %s", query);
 
         OCStackResult ret = NSInvokeRequest(NULL, OC_REST_POST, connections->addr,
-                                query, (OCPayload*)payload, NSConsumerCheckPostResult, NULL, type);
+                                query, (OCPayload*)payload, NSConsumerCheckPostResult,
+                                NULL, NULL, type);
         NS_VERIFY_STACK_SUCCESS_V(NSOCResultToSuccess(ret));
 
+        NSRemoveProvider_internal(provider);
         NSOICFree(query);
         NSOICFree(topicUri);
     }
@@ -810,10 +816,9 @@ OCStackApplicationResult NSIntrospectTopic(
 {
     (void) handle;
 
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(clientResponse, OC_STACK_KEEP_TRANSACTION,
-            NSRemoveProvider_internal((NSProvider_internal *) ctx));
-    NS_VERIFY_STACK_SUCCESS_WITH_POST_CLEANING(NSOCResultToSuccess(clientResponse->result),
-            OC_STACK_KEEP_TRANSACTION, NSRemoveProvider_internal((NSProvider_internal *) ctx));
+    NS_VERIFY_NOT_NULL(clientResponse, OC_STACK_KEEP_TRANSACTION);
+    NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(clientResponse->result),
+                            OC_STACK_KEEP_TRANSACTION);
 
     NS_LOG_V(DEBUG, "GET response income : %s:%d",
             clientResponse->devAddr.addr, clientResponse->devAddr.port);
@@ -828,7 +833,7 @@ OCStackApplicationResult NSIntrospectTopic(
 
     NSTopicLL * newTopicLL = NSGetTopicLL(clientResponse);
 
-    NSProvider_internal * provider = (NSProvider_internal *) ctx;
+    NSProvider_internal * provider = NSCopyProvider_internal((NSProvider_internal *) ctx);
     provider->topicLL = NSCopyTopicLL(newTopicLL);
 
     NS_LOG(DEBUG, "build NSTask");
index d0d3f3f..86ce82d 100644 (file)
@@ -80,7 +80,7 @@ OCStackApplicationResult NSConsumerPresenceListener(
     {
         NS_LOG(DEBUG, "started presence or resource is created.");
         NSInvokeRequest(NULL, OC_REST_DISCOVER, clientResponse->addr,
-            NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener, NULL,
+            NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener, NULL, NULL,
             clientResponse->addr->adapter);
     }
 
@@ -133,7 +133,7 @@ OCStackApplicationResult NSProviderDiscoverListener(
 
             NSInvokeRequest(NULL, OC_REST_GET, addr,
                     resource->uri, NULL, NSIntrospectProvider, ctx,
-                    type);
+                    NULL, type);
         }
         resource = resource->next;
     }
@@ -346,7 +346,7 @@ void NSConsumerHandleRequestDiscover(OCDevAddr * address, NSConsumerDiscoverType
             NS_LOG(DEBUG, "Request discover and subscribe presence [TCP]");
             NS_LOG(DEBUG, "Subscribe presence [TCP]");
             NSInvokeRequest(NULL, OC_REST_PRESENCE, address, NS_PRESENCE_SUBSCRIBE_QUERY_TCP,
-                    NULL, NSConsumerPresenceListener, NULL, type);
+                    NULL, NSConsumerPresenceListener, NULL, NULL, type);
 
             if (rType == NS_DISCOVER_CLOUD)
             {
@@ -364,7 +364,7 @@ void NSConsumerHandleRequestDiscover(OCDevAddr * address, NSConsumerDiscoverType
     }
 
     NSInvokeRequest(NULL, OC_REST_DISCOVER, address, NS_DISCOVER_QUERY,
-            NULL, NSProviderDiscoverListener, (void *)callbackData, type);
+            NULL, NSProviderDiscoverListener, (void *)callbackData, NULL, type);
 }
 
 void NSConsumerDiscoveryTaskProcessing(NSTask * task)
index c4a2575..9772f0c 100644 (file)
@@ -56,13 +56,13 @@ NSResult NSConsumerListenerInit()
     NS_LOG(DEBUG, "Request to subscribe presence");
     OCStackResult stackResult = NSInvokeRequest(getPresenceHandle(), OC_REST_PRESENCE, NULL,
                         NS_PRESENCE_SUBSCRIBE_QUERY, NULL, NSConsumerPresenceListener,
-                        NULL, CT_DEFAULT);
+                        NULL, NULL, CT_DEFAULT);
     NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(stackResult), NS_ERROR);
 
     NS_LOG(DEBUG, "Request to discover provider");
     stackResult = NSInvokeRequest(NULL, OC_REST_DISCOVER, NULL,
                       NS_DISCOVER_QUERY, NULL, NSProviderDiscoverListener,
-                      NULL, CT_DEFAULT);
+                      NULL, NULL, CT_DEFAULT);
     NS_VERIFY_STACK_SUCCESS(NSOCResultToSuccess(stackResult), NS_ERROR);
 
     return NS_OK;