replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / examples / linux / notificationprovider.c
index 32c4f09..11c1c36 100644 (file)
@@ -45,6 +45,11 @@ char UID[50] = {'\0',};
 char ACCESS_TOKEN[50] = {'\0',};
 #endif
 
+#ifdef WITH_MQ
+char CLOUD_ADDRESS[100] = "10.113.64.52:5686";
+char CLOUD_TOPIC[100] = "/oic/ps/notification";
+#endif
+
 char mainConsumer[37] = {'\0',};
 
 extern char *strdup(const char *s);
@@ -180,7 +185,8 @@ int main()
         printf("8.  NSProviderUnselectTopic(); \n");
         printf("9.  NSProviderGetConsumerTopics(); \n");
         printf("10. NSProviderGetTopics(); \n");
-        printf("11. NSStopProvider() \n");
+        printf("11. NSProviderSubscribeMQService() \n");
+        printf("0. NSStopProvider() \n");
 #ifdef WITH_CLOUD
         printf("21. NSProviderEnableRemoteService (after login) \n");
         printf("22. NSProviderDisableRemoteService (after login) \n");
@@ -195,13 +201,17 @@ int main()
 
         if(scanf("%d", &num) > 0)
         {
-            fflush(stdin);
             if(scanf("%c", &dummy) > 0)
             {
                 fflush(stdin);
                 printf("\n");
             }
         }
+        else
+        {
+            printf("invalid input \n");
+            num = 0;
+        }
 
         switch (num)
         {
@@ -244,6 +254,7 @@ int main()
                 input(body);
 
                 printf("topic : ");
+
                 input(topic);
 
                 printf("app - mTitle : %s \n", title);
@@ -251,17 +262,20 @@ int main()
                 printf("app - topic : %s \n", topic);
 
                 NSMessage * msg = NSCreateMessage();
+                if(msg)
+                {
 
-                msg->title = OICStrdup(title);
-                msg->contentText = OICStrdup(body);
-                msg->sourceName = OICStrdup("OCF");
+                    msg->title = OICStrdup(title);
+                    msg->contentText = OICStrdup(body);
+                    msg->sourceName = OICStrdup("OCF");
 
-                if(topic[0] != '\0')
-                {
-                    msg->topic = OICStrdup(topic);
-                }
+                    if(topic[0] != '\0')
+                    {
+                        msg->topic = OICStrdup(topic);
+                    }
 
-                NSSendMessage(msg);
+                    NSSendMessage(msg);
+                }
             }
                 break;
 
@@ -305,7 +319,7 @@ int main()
                 break;
 
             case 10:
-                printf("NSProviderGetConsumerTopics\n");
+                printf("NSProviderGetTopics\n");
                 {
                     NSTopicLL * topics = NSProviderGetTopics();
                     printTopics(topics);
@@ -313,9 +327,20 @@ int main()
                 }
                 break;
 
+#if WITH_MQ
             case 11:
-                NSStopProvider();
+                printf("11. Subscribe MQ Service\n");
+
+                printf("Remote Server Address: ");
+                //input(CLOUD_ADDRESS);
+
+                printf("Topic[notificationtest]: ");
+                //input(CLOUD_TOPIC);
+
+                NSProviderSubscribeMQService(CLOUD_ADDRESS, CLOUD_TOPIC);
                 break;
+#endif
+
 #ifdef WITH_CLOUD
             case 21:
                 printf("Enable Remote Service\n");