Remove consumer callback for discovered provider. 73/10973/5
authorKIM JungYong <jyong2.kim@samsung.com>
Fri, 26 Aug 2016 09:47:25 +0000 (18:47 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 30 Aug 2016 07:23:00 +0000 (07:23 +0000)
Consumer service has two type of callback within parameter as provider object.
One of callback is called when the provider discovered,
and others is called the provider changed.
But, discovered callback is imprecise called owing to provider policy.
So, discovered event is added in provider changed callback.
Two of callback is united as changed name of ProviderStateCallback
and removed discovered callback.

Change-Id: I60eebaf78aaae78a61b3772138b582df3748910c
Signed-off-by: KIM JungYong <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10973
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/notification/examples/linux/notificationconsumer.c
service/notification/include/NSCommon.h
service/notification/include/NSConsumerInterface.h
service/notification/src/consumer/NSConsumerCommon.c
service/notification/src/consumer/NSConsumerCommon.h
service/notification/src/consumer/NSConsumerCommunication.c
service/notification/src/consumer/NSConsumerInterface.c
service/notification/src/consumer/NSConsumerInternalTaskController.c
service/notification/unittest/NSConsumerTest.cpp

index 9d44402..a92ad70 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#include <string.h>
 #include "pthread.h"
 
 #include "ocstack.h"
@@ -138,7 +139,6 @@ int main(void)
     }
 
     NSConsumerConfig cfg;
-    cfg.discoverCb = onDiscoverNotification;
     cfg.changedCb = onProviderChanged;
     cfg.messageCb = onNotificationPosted;
     cfg.syncInfoCb = onNotificationSync;
index 42a4a4a..1c550ed 100644 (file)
@@ -67,6 +67,7 @@ typedef enum eResult
  */
 typedef enum eResponse
 {
+    NS_DISCOVERED = 0,
     NS_ALLOW = 1,
     NS_DENY = 2,
     NS_TOPIC = 3,
index 798b733..35f516c 100644 (file)
@@ -34,18 +34,12 @@ extern "C"
 
 #include "NSCommon.h"
 
-/**
- * Invoked when the discovered provider is received
- * @param[in] provider  Provider who has the notification resource
- */
-typedef void (* NSProviderDiscoveredCallback)(NSProvider *);
-
 /**
  * Invoked when the provider state is changed
  * @param[in] provider  Provider which has the notification resource
  * @param[in] response  Response which has the provider state
  */
-typedef void (* NSProviderChangedCallback)(NSProvider *, NSResponse);
+typedef void (* NSProviderStateCallback)(NSProvider *, NSResponse);
 
 /**
  * Invoked when the notification message from provider is received
@@ -64,8 +58,7 @@ typedef void (* NSSyncInfoReceivedCallback)(NSSyncInfo *);
 
 typedef struct
 {
-    NSProviderDiscoveredCallback discoverCb;
-    NSProviderChangedCallback changedCb;
+    NSProviderStateCallback changedCb;
     NSMessageReceivedCallback messageCb;
     NSSyncInfoReceivedCallback syncInfoCb;
 
index f5af451..51fbaf3 100644 (file)
@@ -105,46 +105,14 @@ bool NSIsStartedConsumer()
     return * NSGetBoneIsStartedConsumer();
 }
 
-NSProviderDiscoveredCallback * NSGetBoneDiscoverCb()
+NSProviderStateCallback * NSGetProviderChangedCb()
 {
-    static NSProviderDiscoveredCallback g_discoverCb = NULL;
-
-    return & g_discoverCb;
-}
-
-void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb)
-{
-    * NSGetBoneDiscoverCb() = cb;
-}
-
-NSProviderDiscoveredCallback NSGetDiscoverCb()
-{
-    return * NSGetBoneDiscoverCb();
-}
-
-void * NSDiscoveredProviderFunc(void * provider)
-{
-    NSGetDiscoverCb()((NSProvider *) provider);
-
-    return NULL;
-}
-
-void NSDiscoveredProvider(NSProvider * provider)
-{
-    NS_VERIFY_NOT_NULL_V(provider);
-
-    NSConsumerThread * thread = NSThreadInit(NSDiscoveredProviderFunc, (void *) provider);
-    NS_VERIFY_NOT_NULL_V(thread);
-}
-
-NSProviderChangedCallback * NSGetProviderChangedCb()
-{
-    static NSProviderChangedCallback g_changedCb = NULL;
+    static NSProviderStateCallback g_changedCb = NULL;
 
     return & g_changedCb;
 }
 
-void NSSetProviderChangedCb(NSProviderChangedCallback cb)
+void NSSetProviderChangedCb(NSProviderStateCallback cb)
 {
     *(NSGetProviderChangedCb()) = cb;
 }
@@ -398,7 +366,7 @@ void NSRemoveTopicLL(NSTopicLL * topicHead)
 
     while (iter)
     {
-        following = (NSTopicLL *) iter->next;
+        following = iter->next;
 
         NSRemoveTopicNode(iter);
 
index 9c02e8d..db60ea0 100644 (file)
@@ -106,10 +106,7 @@ typedef struct
 bool NSIsStartedConsumer();
 void NSSetIsStartedConsumer(bool setValue);
 
-void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
-void NSDiscoveredProvider(NSProvider * provider);
-
-void NSSetProviderChangedCb(NSProviderChangedCallback cb);
+void NSSetProviderChangedCb(NSProviderStateCallback cb);
 void NSProviderChanged(NSProvider * provider, NSResponse response);
 
 void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
index f9ca253..1e15e21 100644 (file)
@@ -29,8 +29,6 @@
 
 #define NS_SYNC_URI "/notification/sync"
 
-static unsigned long NS_MESSAGE_ACCEPTANCE = 1;
-
 NSMessage * NSCreateMessage_internal(uint64_t msgId, const char * providerId);
 NSSyncInfo * NSCreateSyncInfo_consumer(uint64_t msgId, const char * providerId, NSSyncType state);
 
@@ -191,7 +189,7 @@ OCStackApplicationResult NSConsumerMessageListener(
 
     NSTaskType type = TASK_CONSUMER_RECV_MESSAGE;
 
-    if (newNoti->messageId == NS_MESSAGE_ACCEPTANCE || newNoti->messageId == NS_DENY)
+    if (newNoti->messageId == NS_ALLOW || newNoti->messageId == NS_DENY)
     {
         NS_LOG(DEBUG, "Receive subscribe result");
         type = TASK_CONSUMER_RECV_PROVIDER_CHANGED;
index a6d4828..e4a5328 100644 (file)
@@ -36,12 +36,10 @@ NSResult NSStartConsumer(NSConsumerConfig config)
     bool isStartedConsumer = NSIsStartedConsumer();
     NS_VERIFY_NOT_NULL(isStartedConsumer == false ? (void *) 1 : NULL, NS_OK);
 
-    NS_VERIFY_NOT_NULL(config.discoverCb, NS_ERROR);
     NS_VERIFY_NOT_NULL(config.messageCb, NS_ERROR);
     NS_VERIFY_NOT_NULL(config.syncInfoCb, NS_ERROR);
     NS_VERIFY_NOT_NULL(config.changedCb, NS_ERROR);
 
-    NSSetDiscoverProviderCb(config.discoverCb);
     NSSetMessagePostedCb(config.messageCb);
     NSSetNotificationSyncCb(config.syncInfoCb);
     NSSetProviderChangedCb(config.changedCb);
@@ -59,7 +57,6 @@ NSResult NSStopConsumer()
     bool isStartedConsumer = NSIsStartedConsumer();
     NS_VERIFY_NOT_NULL(isStartedConsumer == true ? (void *) 1 : NULL, NS_ERROR);
 
-    NSSetDiscoverProviderCb(NULL);
     NSSetMessagePostedCb(NULL);
     NSSetNotificationSyncCb(NULL);
     NSSetProviderChangedCb(NULL);
index 505d414..9174aec 100644 (file)
@@ -222,7 +222,11 @@ void NSCancelAllSubscription()
     while ((obj = NSPopProviderCacheList(ProviderCache)))
     {
         NS_LOG(DEBUG, "build NSTask");
-        NSTask * task = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, (void *) obj->data);
+        NSProvider * prov = NSCopyProvider((NSProvider_internal *) obj->data);
+        NS_VERIFY_NOT_NULL_WITH_POST_CLEANING_V(prov,
+                    NSRemoveProvider_internal((NSProvider_internal *) obj->data));
+
+        NSTask * task = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, prov);
         NS_VERIFY_NOT_NULL_V(task);
 
         NSConsumerPushEvent(task);
@@ -284,7 +288,7 @@ void NSConsumerHandleProviderDiscovered(NSProvider_internal * provider)
     {
         NS_LOG(DEBUG, "accepter is NS_ACCEPTER_CONSUMER, Callback to user");
         NSProvider * providerForCb = NSCopyProvider(provider);
-        NSDiscoveredProvider(providerForCb);
+        NSProviderChanged(providerForCb, NS_DISCOVERED);
     }
     else
     {
index d60d7d8..aaaa683 100644 (file)
@@ -51,6 +51,7 @@ namespace
         NS_SELECTION_PROVIDER = 1
     };
 
+    NSConsumerConfig cfg;
 }
 
 class TestWithMock: public testing::Test
@@ -84,11 +85,6 @@ public:
     NotificationConsumerTest() = default;
     ~NotificationConsumerTest() = default;
 
-    static void NSProviderDiscoveredCallbackEmpty(NSProvider *)
-    {
-        std::cout << __func__ << std::endl;
-    }
-
     static void NSNotificationReceivedCallbackEmpty(NSMessage *)
     {
         std::cout << __func__ << std::endl;
@@ -117,7 +113,7 @@ protected:
 
         if (g_isStartedStack == false)
         {
-            OC::PlatformConfig cfg
+            OC::PlatformConfig occfg
             {
                 OC::ServiceType::InProc,
                 OC::ModeType::Both,
@@ -125,7 +121,7 @@ protected:
                 0,
                 OC::QualityOfService::LowQos
             };
-            OC::OCPlatform::Configure(cfg);
+            OC::OCPlatform::Configure(occfg);
 
             try
             {
@@ -137,6 +133,10 @@ protected:
             }
 
             g_isStartedStack = true;
+
+            cfg.changedCb = NSProviderChangedCallback;
+            cfg.messageCb = NSNotificationReceivedCallbackEmpty;
+            cfg.syncInfoCb = NSSyncCallbackEmpty;
         }
 
     }
@@ -150,11 +150,6 @@ protected:
 
 TEST_F(NotificationConsumerTest, StartConsumerPositive)
 {
-    NSConsumerConfig cfg;
-    cfg.discoverCb = NSProviderDiscoveredCallbackEmpty;
-    cfg.changedCb = NSProviderChangedCallback;
-    cfg.messageCb = NSNotificationReceivedCallbackEmpty;
-    cfg.syncInfoCb = NSSyncCallbackEmpty;
     EXPECT_EQ(NS_OK, NSStartConsumer(cfg));
 }
 
@@ -165,18 +160,13 @@ TEST_F(NotificationConsumerTest, StopConsumerPositive)
 
 TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsumerFirst)
 {
-    mocks.ExpectCallFunc(NSProviderDiscoveredCallbackEmpty).Do(
-            [this](NSProvider *)
+    mocks.ExpectCallFunc(NSProviderChangedCallback).Do(
+            [this](NSProvider *, NSResponse)
             {
                 std::cout << "Call Discovered" << std::endl;
                 responseCon.notify_all();
             });
 
-    NSConsumerConfig cfg;
-    cfg.discoverCb = NSProviderDiscoveredCallbackEmpty;
-    cfg.changedCb = NSProviderChangedCallback;
-    cfg.messageCb = NSNotificationReceivedCallbackEmpty;
-    cfg.syncInfoCb = NSSyncCallbackEmpty;
     NSStartConsumer(cfg);
 
     g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
@@ -198,19 +188,14 @@ TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsu
         responseCon.wait_for(lock, g_waitForResponse);
     }
 
-    mocks.ExpectCallFunc(NSProviderDiscoveredCallbackEmpty).Do(
-            [this](NSProvider * provider)
+    mocks.ExpectCallFunc(NSProviderChangedCallback).Do(
+            [this](NSProvider * provider, NSResponse)
             {
                 std::cout << "Call Discovered" << std::endl;
                 g_provider = provider;
                 responseCon.notify_all();
             });
 
-    NSConsumerConfig cfg;
-    cfg.discoverCb = NSProviderDiscoveredCallbackEmpty;
-    cfg.changedCb = NSProviderChangedCallback;
-    cfg.messageCb = NSNotificationReceivedCallbackEmpty;
-    cfg.syncInfoCb = NSSyncCallbackEmpty;
     NSStartConsumer(cfg);
 
     std::unique_lock< std::mutex > lock{ mutexForCondition };
@@ -221,8 +206,8 @@ TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenStartedConsu
 TEST_F(NotificationConsumerTest, DiscoverProviderWithNonAccepterWhenRescan)
 {
     g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_CONSUMER);
-    mocks.ExpectCallFunc(NSProviderDiscoveredCallbackEmpty).Do(
-            [this](NSProvider * provider)
+    mocks.ExpectCallFunc(NSProviderChangedCallback).Do(
+            [this](NSProvider * provider, NSResponse)
             {
                 std::cout << "Call Discovered" << std::endl;
                 g_provider = provider;
@@ -281,11 +266,6 @@ TEST_F(NotificationConsumerTest, ExpectReceiveNotificationWithAccepterisProvider
 
     g_providerSimul.setAccepter((int)NSSelector::NS_SELECTION_PROVIDER);
 
-    NSConsumerConfig cfg;
-    cfg.discoverCb = NSProviderDiscoveredCallbackEmpty;
-    cfg.changedCb = NSProviderChangedCallback;
-    cfg.messageCb = NSNotificationReceivedCallbackEmpty;
-    cfg.syncInfoCb = NSSyncCallbackEmpty;
     NSStartConsumer(cfg);
     {
         std::unique_lock< std::mutex > lock{ mutexForCondition };