#define CLOUD_CONTEXT_VALUE 0x99
-char CLOUD_ADDRESS[50];
-char CLOUD_AUTH_PROVIDER[50];
-char CLOUD_AUTH_CODE[50];
-char CLOUD_UID[50];
-char CLOUD_ACCESS_TOKEN[50];
+char CLOUD_ADDRESS[100];
+char CLOUD_TOPIC[100];
+char CLOUD_AUTH_PROVIDER[100];
+char CLOUD_AUTH_CODE[100];
+char CLOUD_UID[100];
+char CLOUD_ACCESS_TOKEN[100];
#endif
if (response == NS_DISCOVERED)
{
printf("notification resource discovered\n");
- printf("subscribe result %d\n", NSSubscribe(provider));
+ printf("subscribe result %d\n", NSSubscribe(provider->providerId));
printf("startSubscribing\n");
}
return NULL;
}
+void input(char * buffer)
+{
+ char ch;
+ int i = 0;
+
+ while( (ch = getchar()) != '\n' && i < 100)
+ buffer[i++] = ch;
+
+ buffer[i] = '\0';
+}
+
int main(void)
{
bool isExit = false;
printf("2. Stop Consumer\n");
printf("3. Get Topics\n");
printf("4. Select Topics\n");
- printf("5. Exit\n");
+ printf("5. Cancel select Topics\n");
+ printf("0. Exit\n");
+#ifdef WITH_MQ
+ printf("11. Subscribe MQ Service\n");
+#endif
#ifdef WITH_CLOUD
printf("21. Enable Remote Service (after login)\n");
printf("31. Cloud Signup\n");
printf("Input: ");
- scanf("%d", &num);
+ if(scanf("%d", &num) == EOF)
+ {
+ printf("Fail to input num\n");
+ }
fflush(stdin);
- scanf("%c", &dummy);
+
+ if(scanf("%c", &dummy) == EOF)
+ {
+ printf("Fail to input dummy\n");
+ }
fflush(stdin);
switch (num)
if(g_provider)
{
g_topicLL = NSConsumerGetTopicList(g_provider->providerId);
+ printProviderTopicList(g_topicLL);
}
break;
case 4:
while (iter)
{
iter->state = (i++)%2;
- printf("Topic Name: %s\t Topic State: %d\n", iter->topicName, iter->state);
iter = iter->next;
}
- NSConsumerUpdateTopicList(g_provider->providerId, g_topicLL);
+ NSResult ret = NSConsumerUpdateTopicList(g_provider->providerId, g_topicLL);
+ if (ret == NS_OK)
+ {
+ printProviderTopicList(g_topicLL);
+ }
+ else
+ {
+ printf("Update fail\n");
+ }
}
break;
case 5:
- printf("5. Exit");
+ printf("5. Cancel select Topics\n");
+ NSTopicLL * iter = g_topicLL;
+ while (iter)
+ {
+ iter->state = NS_TOPIC_UNSUBSCRIBED;
+ iter = iter->next;
+ }
+
+ NSResult ret = NSConsumerUpdateTopicList(g_provider->providerId, g_topicLL);
+ if (ret != NS_OK)
+ {
+ printf("Cancel select topic fail\n");
+ }
+ break;
+ case 0:
+ printf("0. Exit");
isExit = true;
break;
+#if WITH_MQ
+ case 11:
+ printf("11. Subscribe MQ Service\n");
+
+ printf("Remote Server Address: ");
+ input(CLOUD_ADDRESS);
+
+ printf("Topic[notification]: ");
+ input(CLOUD_TOPIC);
+
+ NSConsumerSubscribeMQService(CLOUD_ADDRESS, CLOUD_TOPIC);
+ break;
+#endif
#ifdef WITH_CLOUD
case 21:
printf("Enable Remote Service");
break;
case 31:
printf("Remote Server Address: ");
- gets(CLOUD_ADDRESS);
+ input(CLOUD_ADDRESS);
printf("Auth Provider(eg. github): ");
- gets(CLOUD_AUTH_PROVIDER);
+ input(CLOUD_AUTH_PROVIDER);
printf("Auth Code: ");
- gets(CLOUD_AUTH_CODE);
+ input(CLOUD_AUTH_CODE);
OCCloudSignup(CLOUD_ADDRESS, OCGetServerInstanceIDString(),
CLOUD_AUTH_PROVIDER, CLOUD_AUTH_CODE, CloudSignupCallback);
break;
case 32:
printf("Remote Server Address: ");
- gets(CLOUD_ADDRESS);
+ input(CLOUD_ADDRESS);
printf("UID: ");
- gets(CLOUD_UID);
+ input(CLOUD_UID);
printf("ACCESS_TOKEN: ");
- gets(CLOUD_ACCESS_TOKEN);
+ input(CLOUD_ACCESS_TOKEN);
OCCloudLogin(CLOUD_ADDRESS, CLOUD_UID, OCGetServerInstanceIDString(),
CLOUD_ACCESS_TOKEN, CloudLoginoutCallback);
}
return 0;
}
+