Update logic of callback when provider discovered.
authorKIM JungYong <jyong2.kim@samsung.com>
Wed, 7 Sep 2016 07:38:28 +0000 (16:38 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 8 Sep 2016 08:27:58 +0000 (08:27 +0000)
When consumer discover already discovered provider as unsubscribing,
does not callback to upper layer before,
but we decide to callback to upper layer, so related logic is updated.

Change-Id: Iddeb4577f94f941473452ad035949aaf7c135914
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11499
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/src/consumer/NSConsumerInternalTaskController.c

index 84f7092..f1e5220 100644 (file)
@@ -242,9 +242,29 @@ void NSConsumerHandleProviderDiscovered(NSProvider_internal * provider)
 
     NSProvider_internal * providerCacheDataFromAddr
         = NSFindProviderFromAddr(provider->connection->addr);
 
     NSProvider_internal * providerCacheDataFromAddr
         = NSFindProviderFromAddr(provider->connection->addr);
-    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(
-        (providerCacheDataFromAddr == NULL) ? (void *)1 : NULL,
-        NSRemoveProvider_internal(providerCacheDataFromAddr));
+
+    if (providerCacheDataFromAddr)
+    {
+        if (!strcmp(providerCacheDataFromAddr->providerId, provider->providerId))
+        {
+            NSProviderConnectionInfo * infos = providerCacheDataFromAddr->connection;
+            while (infos)
+            {
+                isSubscribing |= infos->isSubscribing;
+                infos = infos->next;
+            }
+
+            if (isSubscribing == false)
+            {
+                NSProvider * providerForCb = NSCopyProvider(providerCacheDataFromAddr);
+                NSProviderChanged(providerForCb, NS_DISCOVERED);
+                NSRemoveProvider(providerForCb);
+            }
+            NSRemoveProvider_internal(providerCacheDataFromAddr);
+            return ;
+        }
+        NSRemoveProvider_internal(providerCacheDataFromAddr);
+    }
 
     NSProvider_internal * providerCacheData = NSProviderCacheFind(provider->providerId);
 
 
     NSProvider_internal * providerCacheData = NSProviderCacheFind(provider->providerId);
 
@@ -289,6 +309,7 @@ void NSConsumerHandleProviderDiscovered(NSProvider_internal * provider)
         NS_LOG(DEBUG, "accepter is NS_ACCEPTER_CONSUMER, Callback to user");
         NSProvider * providerForCb = NSCopyProvider(provider);
         NSProviderChanged(providerForCb, NS_DISCOVERED);
         NS_LOG(DEBUG, "accepter is NS_ACCEPTER_CONSUMER, Callback to user");
         NSProvider * providerForCb = NSCopyProvider(provider);
         NSProviderChanged(providerForCb, NS_DISCOVERED);
+        NSRemoveProvider(providerForCb);
     }
     else
     {
     }
     else
     {