#include "pthread.h"
#include "oic_string.h"
#include "oic_malloc.h"
+#include "ocstack.h"
#define TAG "NSProviderExample"
#include "cloud_connector.h"
// Input the following values to publish resource to cloud
-char REMOTE_SERVER_ADDRESS[50];
-char AUTH_PROVIDER[50];
-char AUTH_CODE[50];
-char UID[50];
-char ACCESS_TOKEN[50];
+char REMOTE_SERVER_ADDRESS[50] = {'\0',};
+char AUTH_PROVIDER[50] = {'\0',};
+char AUTH_CODE[50] = {'\0',};
+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',};
}
}
+void input(char * buffer)
+{
+ char ch;
+ int i = 0;
+
+ while( (ch = getchar()) != '\n' && i < 100)
+ buffer[i++] = ch;
+
+ buffer[i] = '\0';
+}
+
int main()
{
int num;
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");
printf("input : ");
- scanf("%d", &num);
- fflush(stdin);
- scanf("%c", &dummy);
- fflush(stdin);
+ if(scanf("%d", &num) > 0)
+ {
+ if(scanf("%c", &dummy) > 0)
+ {
+ fflush(stdin);
+ printf("\n");
+ }
+ }
+ else
+ {
+ printf("invalid input \n");
+ num = 0;
+ }
switch (num)
{
{
printf("NSStartProvider(Accepter: Provider)");
NSProviderConfig config;
- config.policy = true;
+ config.subControllability = true;
config.subRequestCallback = subscribeRequestCallback;
config.syncInfoCallback = syncCallback;
config.userInfo = OICStrdup("OCF_NOTIFICATION");
{
printf("NSStartProvider(Accepter: Consumer)");
NSProviderConfig config;
- config.policy = false;
+ config.subControllability = false;
config.subRequestCallback = subscribeRequestCallback;
config.syncInfoCallback = syncCallback;
config.userInfo = OICStrdup("OCF_NOTIFICATION");
case 3:
{
printf("NSSendNotification()");
- char title[100];
- char body[100];
- char topic[100];
+ char title[100] = {'\0',};
+ char body[100] = {'\0',};
+ char topic[100] = {'\0',};
printf("id : %d\n", ++id);
printf("title : ");
-
- gets(title);
+ input(title);
printf("body : ");
- gets(body);
+ input(body);
printf("topic : ");
- gets(topic);
+
+ input(topic);
printf("app - mTitle : %s \n", title);
printf("app - mContentText : %s \n", body);
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;
case 5:
printf("NSProviderAddTopic\n");
- NSProivderRegisterTopic("OCF_TOPIC1");
- NSProivderRegisterTopic("OCF_TOPIC2");
- NSProivderRegisterTopic("OCF_TOPIC3");
- NSProivderRegisterTopic("OCF_TOPIC4");
+ NSProviderRegisterTopic("OCF_TOPIC1");
+ NSProviderRegisterTopic("OCF_TOPIC2");
+ NSProviderRegisterTopic("OCF_TOPIC3");
+ NSProviderRegisterTopic("OCF_TOPIC4");
break;
case 6:
break;
case 10:
- printf("NSProviderGetConsumerTopics\n");
+ printf("NSProviderGetTopics\n");
{
NSTopicLL * topics = NSProviderGetTopics();
printTopics(topics);
}
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");
+ printf("Enable Remote Service\n");
if(!IsCloudLoggedin())
{
- printf("Login required");
+ printf("Login required\n");
break;
}
- NSProviderEnableRemoteService(REMOTE_SERVER_ADDRESS);
+ NSProviderEnableRemoteService(REMOTE_SERVER_ADDRESS);
break;
case 22:
- printf("Disable Remote Service");
+ printf("Disable Remote Service\n");
if(!IsCloudLoggedin())
{
- printf("Login required");
+ printf("Login required\n");
break;
}
NSProviderDisableRemoteService(REMOTE_SERVER_ADDRESS);
case 31:
printf("Remote Server Address: ");
- gets(REMOTE_SERVER_ADDRESS);
+ input(REMOTE_SERVER_ADDRESS);
printf("Auth Provider(eg. github): ");
- gets(AUTH_PROVIDER);
+ input(AUTH_PROVIDER);
printf("Auth Code: ");
- gets(AUTH_CODE);
+ input(AUTH_CODE);
OCCloudSignup(REMOTE_SERVER_ADDRESS, OCGetServerInstanceIDString(),
AUTH_PROVIDER, AUTH_CODE, CloudSignupCallback);
break;
case 32:
printf("Remote Server Address: ");
- gets(REMOTE_SERVER_ADDRESS);
+ input(REMOTE_SERVER_ADDRESS);
printf("UID: ");
- gets(UID);
+ input(UID);
printf("ACCESS_TOKEN: ");
- gets(ACCESS_TOKEN);
+ input(ACCESS_TOKEN);
OCCloudLogin(REMOTE_SERVER_ADDRESS, UID, OCGetServerInstanceIDString(),
ACCESS_TOKEN, CloudLoginoutCallback);
- printf("OCCloudLogin requested");
+ printf("OCCloudLogin requested\n");
break;
case 33:
OCCloudLogout(REMOTE_SERVER_ADDRESS, CloudLoginoutCallback);
- printf("OCCloudLogin requested");
+ printf("OCCloudLogin requested\n");
break;
#endif
case 0: