5 #include "NSConsumerInterface.h"
8 void onDiscoverNotification(NSProvider * provider)
10 printf("notification resource discovered\n");
11 printf("subscribe result %d\n", NSSubscribe(provider));
12 printf("startSubscribing\n");
15 void onSubscriptionAccepted(NSProvider * provider)
17 printf("Subscription accepted\n");
18 printf("subscribed provider Id : %s\n", provider->providerId);
21 void onNotificationPosted(NSMessage * notification)
23 printf("id : %ld\n", notification->messageId);
24 printf("title : %s\n", notification->title);
25 printf("content : %s\n", notification->contentText);
26 printf("source : %s\n", notification->sourceName);
27 NSConsumerSendSyncInfo(notification->providerId, notification->messageId, NS_SYNC_READ);
30 void onNotificationSync(NSSyncInfo * sync)
32 printf("Sync ID : %ld\n", sync->messageId);
33 printf("Sync STATE : %d\n", sync->state);
39 printf("start Iotivity\n");
40 if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
42 printf("OCInit fail\n");
47 cfg.discoverCb = onDiscoverNotification;
48 cfg.acceptedCb = onSubscriptionAccepted;
49 cfg.messageCb = onNotificationPosted;
50 cfg.syncInfoCb = onNotificationSync;
53 printf("start notification consumer service\n");
54 NSResult ret = NSStartConsumer(cfg);
57 printf("error discoverNoti %d\n", ret);
63 if(OCProcess() != OC_STACK_OK)