X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fnotification%2Fexamples%2Flinux%2Fnotificationconsumer.c;h=d538b074d6cc26c9a0ddacfa27ed8b2c37fa8ac7;hb=635caf567eb8eb7341291c4b635fb2360feb8e44;hp=83393e6c971600c2abb38902b0cf52cad5fda066;hpb=a7c3eeca4a2f4482d6c0879b29f4f4e9130b1874;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/notification/examples/linux/notificationconsumer.c b/service/notification/examples/linux/notificationconsumer.c index 83393e6..d538b07 100644 --- a/service/notification/examples/linux/notificationconsumer.c +++ b/service/notification/examples/linux/notificationconsumer.c @@ -29,7 +29,6 @@ #ifdef WITH_CLOUD #include "NSConstants.h" #include "NSConsumerCommon.h" -#include "cloud_connector.h" #include "oic_malloc.h" #define CLOUD_CONTEXT_VALUE 0x99 @@ -39,6 +38,8 @@ #define CLOUD_IOTIVITYNS_SESSION "" // refer to IoTivity Cloud Module Sample #endif +NSProvider * g_provider = NULL; + void onDiscoverNotification(NSProvider * provider) { printf("notification resource discovered\n"); @@ -46,10 +47,32 @@ void onDiscoverNotification(NSProvider * provider) printf("startSubscribing\n"); } -void onSubscriptionAccepted(NSProvider * provider) +void printProviderTopicList(NSProvider *provider) { - printf("Subscription accepted\n"); + printf("printProviderTopicList\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; + } + } +} + +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"); + + printProviderTopicList(provider); + g_provider = provider; + } } void onNotificationPosted(NSMessage * notification) @@ -58,6 +81,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 && strlen(notification->topic) > 0) + { + printf("topic : %s\n", notification->topic); + } NSConsumerSendSyncInfo(notification->providerId, notification->messageId, NS_SYNC_READ); } @@ -67,7 +94,6 @@ void onNotificationSync(NSSyncInfo * sync) printf("Sync STATE : %d\n", sync->state); } - #ifdef WITH_CLOUD OCStackApplicationResult handleLoginoutCB(void *ctx, OCDoHandle handle, @@ -139,13 +165,12 @@ int main(void) NSConsumerConfig cfg; cfg.discoverCb = onDiscoverNotification; - cfg.acceptedCb = onSubscriptionAccepted; + cfg.changedCb = onProviderChanged; cfg.messageCb = onNotificationPosted; cfg.syncInfoCb = onNotificationSync; #ifdef WITH_CLOUD NS_LOG(DEBUG, "process OCCloudLogin..."); - OCCloudLogin(CLOUD_HOST_ADDRESS, CLOUD_IOTIVITYNS_SESSION, handleLoginoutCB); NS_LOG(DEBUG, "OCCloudLogin return"); #endif @@ -159,6 +184,8 @@ int main(void) printf("1. Start Consumer\n"); printf("2. Stop Consumer\n"); + printf("3. Get Topics\n"); + printf("4. Select Topics\n"); printf("5. Exit\n"); printf("Input: "); @@ -178,6 +205,29 @@ int main(void) printf("2. Stop Consumer"); NSStopConsumer(); break; + case 3: + printf("3. Get Topics\n"); + if(g_provider) + { + NSConsumerGetInterestTopics(g_provider); + } + break; + case 4: + printf("4. Select Topics\n"); + + if (g_provider && g_provider->topicLL) + { + NSTopicLL * iter = g_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(g_provider); + } + break; case 5: printf("5. Exit"); isExit = true; @@ -186,6 +236,5 @@ int main(void) break; } } - return 0; }