added struct, enum and modified struct, enum
[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->messageId);
13     printf("title : %s\n", notification->title);
14     printf("content : %s\n", notification->contentText);
15     printf("source : %s\n", notification->sourceName);
16 //    NSDropNSObject(notification);
17     NSConsumerReadCheck(notification);
18 }
19
20 void onDiscoverNotification(NSProvider * provider)
21 {
22     printf("notification resource discovered\n");
23     printf("subscribe result %d\n", NSSubscribe(provider));
24     printf("startSubscribing\n");
25 }
26
27 void onNotificationSync(NSProvider * provider, NSSyncInfo * sync)
28 {
29     printf("Sync from : %s:%d\n", ((OCDevAddr *)provider->mUserData)->addr,
30             ((OCDevAddr *)provider->mUserData)->port);
31     printf("Sync ID : %s\n", sync->messageId);
32     printf("Sync STATE : %d\n", sync->state);
33 }
34
35 int main(void)
36 {
37
38     printf("start Iotivity\n");
39     if (OCInit1(OC_CLIENT, OC_DEFAULT_FLAGS, OC_DEFAULT_FLAGS) != OC_STACK_OK)
40     {
41         printf("OCInit fail\n");
42         return 0;
43     }
44
45
46
47     printf("start notification consumer service\n");
48     NSResult ret = NSStartConsumer(
49             onDiscoverNotification,
50             onNotificationPosted,
51             onNotificationSync);
52     if(ret != NS_OK)
53     {
54         printf("error discoverNoti %d\n", ret);
55     }
56
57     while (true)
58     {
59         usleep(2000);
60         if(OCProcess() != OC_STACK_OK)
61         {
62             OCStop();
63             break;
64         }
65     }
66
67     return 0;
68 }