Modify notification consumer example code
authorYounghyunJoo <yh_.joo@samsung.com>
Thu, 18 Aug 2016 11:42:19 +0000 (20:42 +0900)
committerUze Choi <uzchoi@samsung.com>
Fri, 19 Aug 2016 01:33:24 +0000 (01:33 +0000)
- to support topic functionality

Change-Id: I3a76d2a5eb80ddf67780ae1707e1097c3930d6a8
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/10619
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/notification/examples/linux/notificationconsumer.c

index 140d324..16aced1 100644 (file)
@@ -50,6 +50,54 @@ void onProviderChanged(NSProvider * provider, NSResponse response)
 {
     printf("Provider changed: %d\n", response);
     printf("subscribed provider Id : %s\n", provider->providerId);
+
+    if (response == NS_TOPIC)
+    {
+        printf ("Provider Topic Updated\n");
+        if (provider->topicLL)
+        {
+            NSTopicLL * iter = provider->topicLL;
+            while (iter)
+            {
+                printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
+                iter = iter->next;
+            }
+        }
+
+        printf("3. Get Topics\n");
+        printf("4. Select Topics\n");
+        printf("input: ");
+
+        int num = 0;
+        char dummy = '\0';
+        scanf("%d", &num);
+        fflush(stdin);
+        scanf("%c", &dummy);
+        fflush(stdin);
+
+        switch (num)
+        {
+            case 3:
+                printf("3. Get Topics\n");
+                NSConsumerGetInterestTopics(provider);
+                break;
+            case 4:
+                printf("4. Select Topics\n");
+                if (provider->topicLL)
+                {
+                    NSTopicLL * iter = provider->topicLL;
+                    int i = 0;
+                    while (iter)
+                    {
+                        iter->state = (i++)%2;
+                        printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
+                        iter = iter->next;
+                    }
+                }
+                NSConsumerSelectInterestTopics(provider);
+                break;
+        }
+    }
 }
 
 void onNotificationPosted(NSMessage * notification)
@@ -58,6 +106,10 @@ void onNotificationPosted(NSMessage * notification)
     printf("title : %s\n", notification->title);
     printf("content : %s\n", notification->contentText);
     printf("source : %s\n", notification->sourceName);
+    if (notification->topic)
+    {
+        printf("topic : %s\n", notification->topic);
+    }
     NSConsumerSendSyncInfo(notification->providerId, notification->messageId, NS_SYNC_READ);
 }