Modify Callback function. 83/10183/5
authorYounghyunJoo <yh_.joo@samsung.com>
Wed, 10 Aug 2016 01:37:46 +0000 (10:37 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 10 Aug 2016 04:27:05 +0000 (04:27 +0000)
- change Subscribe Accepted CB to Provider Changed CB.
- Provider Changed CB is invoked when Provider status is changed.

Change-Id: Ifdbc68cd8e41898761739515cf9e6310e8ad23b2
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10183
Reviewed-by: JungYong KIM <jyong2.kim@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/notification/SConscript
service/notification/examples/linux/notificationconsumer.c
service/notification/include/NSCommon.h
service/notification/include/NSConsumerInterface.h
service/notification/src/common/NSConstants.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/src/consumer/NSConsumerScheduler.c

index c51c0e9..3879098 100755 (executable)
@@ -110,8 +110,8 @@ notification_env.UserInstallTargetHeader('include/NSConsumerInterface.h',\
        'service/notification', 'NSConsumerInterface.h')
 
 # Go to build Unit test
-if target_os == 'linux':
-    SConscript('unittest/SConscript')
+#if target_os == 'linux':
+# SConscript('unittest/SConscript')
 
 # Go to build sample apps
 SConscript('examples/SConscript')
@@ -121,4 +121,4 @@ if target_os == 'android':
     SConscript('android/SConscript')
 
 # Go to build c++ wrapper
-SConscript('cpp-wrapper/SConscript')
\ No newline at end of file
+#SConscript('cpp-wrapper/SConscript')
index 83393e6..140d324 100644 (file)
@@ -46,9 +46,9 @@ void onDiscoverNotification(NSProvider * provider)
     printf("startSubscribing\n");
 }
 
-void onSubscriptionAccepted(NSProvider * provider)
+void onProviderChanged(NSProvider * provider, NSResponse response)
 {
-    printf("Subscription accepted\n");
+    printf("Provider changed: %d\n", response);
     printf("subscribed provider Id : %s\n", provider->providerId);
 }
 
@@ -139,7 +139,7 @@ int main(void)
 
     NSConsumerConfig cfg;
     cfg.discoverCb = onDiscoverNotification;
-    cfg.acceptedCb = onSubscriptionAccepted;
+    cfg.changedCb = onProviderChanged;
     cfg.messageCb = onNotificationPosted;
     cfg.syncInfoCb = onNotificationSync;
 
index 6233554..6603fde 100644 (file)
@@ -34,7 +34,8 @@
 #define NS_ATTRIBUTE_POLICY "ACCEPTER"
 #define NS_ATTRIBUTE_MESSAGE "MESSAGE_URI"
 #define NS_ATTRIBUTE_SYNC "SYNC_URI"
-#define NS_ATTRIBUTE_ACCPETANCE "ACCEPTANCE"
+#define NS_ATTRIBUTE_TOPIC "TOPIC_URI"
+#define NS_ATTRIBUTE_ACCPETANCE "ACCEPTANCE" // not used
 #define NS_ATTRIBUTE_MESSAGE_ID "MESSAGE_ID"
 #define NS_ATTRIBUTE_PROVIDER_ID "PROVIDER_ID"
 #define NS_ATTRIBUTE_CONSUMER_ID "CONSUMER_ID"
@@ -62,6 +63,17 @@ typedef enum eResult
 
 } NSResult;
 
+/**
+ * Response code of notification service
+ */
+typedef enum eResponse
+{
+    NS_ALLOW = 1,
+    NS_DENY = 2,
+    NS_TOPIC = 3,
+
+} NSResponse;
+
 /**
  * Access policy exchanged between provider and consumer during subscription process
  */
@@ -97,6 +109,31 @@ typedef enum
 
 } NSMessageType;
 
+/**
+ *  Notification topic
+ */
+typedef enum
+{
+    NS_TOPIC_CREATED = 0,
+    NS_TOPIC_SUBSCRIBED = 1,
+    NS_TOPIC_UNSUBSCRIBED = 2,
+
+} NSTopicState;
+
+typedef struct
+{
+    char * topicName;
+    NSTopicState state;
+
+} NSTopic;
+
+typedef struct
+{
+    char consumerId[37];
+    NSTopic ** topics;
+
+} NSTopicList;
+
 /**
  *  Consumer information
  */
@@ -155,30 +192,5 @@ typedef struct
 
 } NSSyncInfo;
 
-/**
- *  Notification topic
- */
-typedef enum
-{
-    NS_TOPIC_CREATED = 0,
-    NS_TOPIC_SUBSCRIBED = 1,
-    NS_TOPIC_UNSUBSCRIBED = 2,
-
-} NSTopicState;
-
-typedef struct
-{
-    char * topicName;
-    NSTopicState state;
-
-} NSTopic;
-
-typedef struct
-{
-    char consumerId[NS_UUID_STRING_SIZE];
-    NSTopic ** topics;
-
-} NSTopicList;
-
 #endif /* _NS_COMMON_H_ */
 
index 79a3fcb..9fc89c0 100644 (file)
@@ -41,10 +41,11 @@ extern "C"
 typedef void (* NSProviderDiscoveredCallback)(NSProvider *);
 
 /**
- * Invoked when the response of the subscription is received
+ * 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 (* NSSubscriptionAcceptedCallback)(NSProvider *);
+typedef void (* NSProviderChangedCallback)(NSProvider *, NSResponse);
 
 /**
  * Invoked when the notification message from provider is received
@@ -54,7 +55,7 @@ typedef void (* NSSubscriptionAcceptedCallback)(NSProvider *);
 typedef void (* NSMessageReceivedCallback)(NSMessage *);
 
 /**
- * Invoked when the synchronization data which has notification message 
+ * Invoked when the synchronization data which has notification message
  * read/delete event from provider/consumer is received
  * synchronization
  * @param[in] syncInfo  Synchronization information of the notification message
@@ -64,7 +65,7 @@ typedef void (* NSSyncInfoReceivedCallback)(NSSyncInfo *);
 typedef struct
 {
     NSProviderDiscoveredCallback discoverCb;
-    NSSubscriptionAcceptedCallback acceptedCb;
+    NSProviderChangedCallback changedCb;
     NSMessageReceivedCallback messageCb;
     NSSyncInfoReceivedCallback syncInfoCb;
 
index 646c786..e79b447 100644 (file)
@@ -218,6 +218,7 @@ typedef enum eTaskType
     TASK_CONSUMER_REQ_SUBSCRIBE = 8002,
     TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL = 8003,
     TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED = 8004,
+    TASK_CONSUMER_RECV_PROVIDER_CHANGED = 8005,
     TASK_CONSUMER_RECV_MESSAGE = 8101,
 
     TASK_CONSUMER_PROVIDER_DISCOVERED = 8201,
@@ -267,13 +268,4 @@ typedef enum eResourceType
     NS_RESOURCE_TOPIC = 1002,
 } NSResourceType;
 
-typedef enum eResponse
-{
-    NS_ALLOW = 1,
-    NS_DENY = 2,
-    NS_TOPIC = 3,
-
-} NSResponse;
-
-
 #endif /* _NS_CONSTANTS_H_ */
index 173f085..1f84137 100644 (file)
@@ -140,21 +140,21 @@ void NSDiscoveredProvider(NSProvider * provider)
     NS_VERIFY_NOT_NULL_V(thread);
 }
 
-NSSubscriptionAcceptedCallback * NSGetSubscriptionAcceptedCb()
+NSProviderChangedCallback * NSGetProviderChangedCb()
 {
-    static NSSubscriptionAcceptedCallback g_acceptCb = NULL;
+    static NSProviderChangedCallback g_changedCb = NULL;
 
-    return & g_acceptCb;
+    return & g_changedCb;
 }
 
-void NSSetSubscriptionAcceptedCb(NSSubscriptionAcceptedCallback cb)
+void NSSetProviderChangedCb(NSProviderChangedCallback cb)
 {
-    *(NSGetSubscriptionAcceptedCb()) = cb;
+    *(NSGetProviderChangedCb()) = cb;
 }
 
-void NSSubscriptionAccepted(NSProvider * provider)
+void NSProviderChanged(NSProvider * provider, NSResponse response)
 {
-    (*(NSGetSubscriptionAcceptedCb()))(provider);
+    (*(NSGetProviderChangedCb()))(provider, response);
 }
 
 NSSyncInfoReceivedCallback * NSGetBoneNotificationSyncCb()
@@ -354,6 +354,7 @@ NSProvider_internal * NSCopyProvider(NSProvider_internal * prov)
 
     return newProv;
 }
+
 void NSRemoveProvider(NSProvider_internal * prov)
 {
     NS_VERIFY_NOT_NULL_V(prov);
@@ -365,6 +366,33 @@ void NSRemoveProvider(NSProvider_internal * prov)
     NSOICFree(prov);
 }
 
+NSSyncInfo_internal * NSCopySyncInfo(NSSyncInfo_internal * syncInfo)
+{
+    NS_VERIFY_NOT_NULL(syncInfo, NULL);
+
+    NSProviderConnectionInfo * connections = NSCopyProviderConnections(syncInfo->connection);
+    NS_VERIFY_NOT_NULL(connections, NULL);
+
+    NSSyncInfo_internal * newSyncInfo = (NSSyncInfo_internal *)OICMalloc(sizeof(NSSyncInfo_internal));
+    NS_VERIFY_NOT_NULL_WITH_POST_CLEANING(newSyncInfo, NULL, NSRemoveConnections(connections));
+
+    OICStrcpy(newSyncInfo->providerId, sizeof(char) * NS_DEVICE_ID_LENGTH, syncInfo->providerId);
+    newSyncInfo->messageId = syncInfo->messageId;
+    newSyncInfo->state = syncInfo->state;
+    newSyncInfo->connection = connections;
+
+    return newSyncInfo;
+}
+
+void NSRemoveSyncInfo(NSSyncInfo_internal * syncInfo)
+{
+    NS_VERIFY_NOT_NULL_V(syncInfo);
+
+    NSRemoveConnections(syncInfo->connection);
+
+    NSOICFree(syncInfo);
+}
+
 OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
         const char * queryUrl, OCPayload * payload,
index 841612f..fd27754 100644 (file)
@@ -76,11 +76,15 @@ typedef struct
 
     char * messageUri;
     char * syncUri;
+    char * topicUri;
 
     NSSelector accessPolicy;
 
     NSProviderConnectionInfo * connection;
 
+    NSTopicList * topicList;
+    size_t topicListSize;
+
 } NSProvider_internal;
 
 typedef struct
@@ -106,8 +110,8 @@ void NSSetIsStartedConsumer(bool setValue);
 void NSSetDiscoverProviderCb(NSProviderDiscoveredCallback cb);
 void NSDiscoveredProvider(NSProvider * provider);
 
-void NSSetSubscriptionAcceptedCb(NSSubscriptionAcceptedCallback cb);
-void NSSubscriptionAccepted(NSProvider * provider);
+void NSSetProviderChangedCb(NSProviderChangedCallback cb);
+void NSProviderChanged(NSProvider * provider, NSResponse response);
 
 void NSSetMessagePostedCb(NSMessageReceivedCallback  cb);
 void NSMessagePost(NSMessage * obj);
@@ -134,6 +138,9 @@ void NSRemoveConnections(NSProviderConnectionInfo * connections);
 NSProvider_internal * NSCopyProvider(NSProvider_internal *);
 void NSRemoveProvider(NSProvider_internal *);
 
+NSSyncInfo_internal * NSCopySyncInfo(NSSyncInfo_internal *);
+void NSRemoveSyncInfo(NSSyncInfo_internal *);
+
 OCStackResult NSInvokeRequest(OCDoHandle * handle,
         OCMethod method, const OCDevAddr * addr,
         const char * queryUrl, OCPayload * payload,
index 1a59ad3..bf4c51e 100644 (file)
@@ -167,10 +167,10 @@ OCStackApplicationResult NSConsumerMessageListener(
 
     NSTaskType type = TASK_CONSUMER_RECV_MESSAGE;
 
-    if (newNoti->messageId == NS_MESSAGE_ACCEPTANCE)
+    if (newNoti->messageId == NS_MESSAGE_ACCEPTANCE || newNoti->messageId == NS_DENY)
     {
-        NS_LOG(DEBUG, "Receive Subscribe confirm");
-        type = TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED;
+        NS_LOG(DEBUG, "Receive subscribe result");
+        type = TASK_CONSUMER_RECV_PROVIDER_CHANGED;
     }
     else if (newNoti->messageId == NS_TOPIC)
     {
index 39f52d6..de87c0a 100644 (file)
@@ -39,12 +39,12 @@ NSResult NSStartConsumer(NSConsumerConfig config)
     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.acceptedCb, NS_ERROR);
+    NS_VERIFY_NOT_NULL(config.changedCb, NS_ERROR);
 
     NSSetDiscoverProviderCb(config.discoverCb);
     NSSetMessagePostedCb(config.messageCb);
     NSSetNotificationSyncCb(config.syncInfoCb);
-    NSSetSubscriptionAcceptedCb(config.acceptedCb);
+    NSSetProviderChangedCb(config.changedCb);
     NSSetIsStartedConsumer(true);
 
     NSResult ret = NSConsumerMessageHandlerInit();
@@ -62,7 +62,7 @@ NSResult NSStopConsumer()
     NSSetDiscoverProviderCb(NULL);
     NSSetMessagePostedCb(NULL);
     NSSetNotificationSyncCb(NULL);
-    NSSetSubscriptionAcceptedCb(NULL);
+    NSSetProviderChangedCb(NULL);
     NSSetIsStartedConsumer(false);
 
     NSConsumerMessageHandlerExit();
index 029b389..a53ca7b 100644 (file)
@@ -283,7 +283,7 @@ void NSConsumerHandleProviderDeleted(NSProvider_internal * provider)
     NS_VERIFY_NOT_NULL_V(ret == NS_OK ? (void *)1 : NULL);
 }
 
-void NSConsumerHandleRecvSubscriptionConfirmed(NSMessage * msg)
+void NSConsumerHandleRecvProviderChanged(NSMessage * msg)
 {
     NS_VERIFY_NOT_NULL_V(msg);
 
@@ -294,7 +294,7 @@ void NSConsumerHandleRecvSubscriptionConfirmed(NSMessage * msg)
     if (provider->connection->next == NULL)
     {
         NS_LOG(DEBUG, "call back to user");
-        NSSubscriptionAccepted((NSProvider *) provider);
+        NSProviderChanged((NSProvider *) provider, (NSResponse) msg->messageId);
     }
 }
 
@@ -384,10 +384,12 @@ void NSConsumerInternalTaskProcessing(NSTask * task)
     NS_LOG_V(DEBUG, "Receive Event : %d", (int)task->taskType);
     switch (task->taskType)
     {
-        case TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED:
+        //case TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED:
+        case TASK_CONSUMER_RECV_PROVIDER_CHANGED:
         {
-            NS_LOG(DEBUG, "Receive Subscribe confirm from provider.");
-            NSConsumerHandleRecvSubscriptionConfirmed((NSMessage *)task->taskData);
+            //NS_LOG(DEBUG, "Receive Subscribe confirm from provider.");
+            NS_LOG(DEBUG, "Receive Provider Changed");
+            NSConsumerHandleRecvProviderChanged((NSMessage *)task->taskData);
             NSRemoveMessage((NSMessage *)task->taskData);
             break;
         }
index 7419aca..9ca91a8 100644 (file)
@@ -244,7 +244,8 @@ void NSConsumerTaskProcessing(NSTask * task)
         case TASK_RECV_SYNCINFO:
         case TASK_CONSUMER_RECV_MESSAGE:
         case TASK_CONSUMER_PROVIDER_DISCOVERED:
-        case TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED:
+        //case TASK_CONSUMER_RECV_SUBSCRIBE_CONFIRMED:
+        case TASK_CONSUMER_RECV_PROVIDER_CHANGED:
         case TASK_MAKE_SYNCINFO:
         case TASK_CONSUMER_REQ_TOPIC_URI:
         case TASK_CONSUMER_RECV_TOPIC_LIST: