added cacheadapter interface and memorycache of notification.
[platform/upstream/iotivity.git] / service / notification / examples / linux / notificationconsumer.c
1 #include <stdio.h>
2
3 #include <unistd.h>
4 #include "NSCommon.h"
5 #include "NSConsumerInterface.h"
6 #include "ocstack.h"
7
8 void onNotificationPosted(NSProvider * provider, NSMessage * notification)
9 {
10     printf("Notification from : %s:%d\n", ((OCDevAddr *)provider->mUserData)->addr,
11             ((OCDevAddr *)provider->mUserData)->port);
12     printf("id : %s\n", notification->mId);
13     printf("title : %s\n", notification->mTitle);
14     printf("content : %s\n", notification->mContentText);
15 //    NSDropNSObject(notification);
16     NSConsumerReadCheck(notification);
17 }
18
19 void onDiscoverNotification(NSProvider * provider)
20 {
21     printf("notification resource discovered\n");
22     printf("subscribe result %d\n", NSSubscribe(provider));
23     printf("startSubscribing\n");
24 }
25
26 void onNotificationSync(NSProvider * provider, NSSync * sync)
27 {
28     printf("Sync from : %s:%d\n", ((OCDevAddr *)provider->mUserData)->addr,
29             ((OCDevAddr *)provider->mUserData)->port);
30     printf("Sync ID : %s\n", sync->mMessageId);
31     printf("Sync STATE : %d\n", sync->mState);
32 }
33
34 int main(void)
35 {
36
37     printf("start Iotivity\n");
38     if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
39     {
40         printf("OCInit fail\n");
41         return 0;
42     }
43
44
45
46     printf("start notification consumer service\n");
47     NSResult ret = NSStartConsumer(
48             onDiscoverNotification,
49             onNotificationPosted,
50             onNotificationSync);
51     if(ret != NS_OK)
52     {
53         printf("error discoverNoti %d\n", ret);
54     }
55
56     while (true)
57     {
58         usleep(2000);
59         if(OCProcess() != OC_STACK_OK)
60         {
61             OCStop();
62             break;
63         }
64     }
65
66     return 0;
67 }