4 #include "NSCommon.h"
\r
5 #include "NSProviderInterface.h"
\r
11 #define TAG "notiProviderExample"
\r
13 extern char *strdup(const char *s);
\r
15 bool isExit = false;
\r
17 pthread_t processThread;
\r
21 void OCProcessThread(void * ptr)
\r
26 if (OCProcess() != OC_STACK_OK)
\r
28 OIC_LOG(ERROR, TAG, "OCStack process error");
\r
34 void subscribeRequestCallback(NSConsumer *consumer)
\r
36 OIC_LOG(INFO, TAG, "consumer requested to subscribe");
\r
37 char *cid = consumer->mId;
\r
39 printf("NS_ Consumer ID: %s\n", cid);
\r
41 NSAccept(consumer, true);
\r
44 void syncCallback(NSSync *sync)
\r
46 OIC_LOG(INFO, TAG, "sync requested");
\r
48 printf("NS_ Sync State: %d\n", sync->mState);
\r
55 OIC_LOG(INFO, TAG, "NSStartProvider()");
\r
57 if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
\r
59 OIC_LOG(INFO, TAG, "OCStack init error");
\r
63 pthread_create(&processThread, NULL, OCProcessThread, NULL);
\r
65 NSMessage * message = (NSMessage*) OICMalloc(sizeof(NSMessage));
\r
68 OIC_LOG(ERROR, TAG, PCF("Fail to allocate memory"));
\r
76 printf("1. NSStartProvider(Accepter: Provider) \n");
\r
77 printf("2. NSStartProvider(Accepter: Consumer) \n");
\r
78 printf("3. NSSendNotification() \n");
\r
79 printf("4. NSRead \n");
\r
80 //printf("5. NSAccept \n");
\r
81 printf("6. NSGetConsumerList \n");
\r
82 //printf("7. startPresence \n");
\r
83 //printf("8. stopPresence \n");
\r
84 printf("0. Exit() \n");
\r
89 scanf("%c", &dummy);
\r
95 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Provider)");
\r
96 NSStartProvider(NS_ACCEPTER_PROVIDER, subscribeRequestCallback, syncCallback);
\r
99 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Consumer)");
\r
100 NSStartProvider(NS_ACCEPTER_CONSUMER, subscribeRequestCallback, syncCallback);
\r
103 OIC_LOG(INFO, TAG, "NSSendNotification()");
\r
109 printf("id : %d\n", ++id);
\r
111 printf("title : ");
\r
118 printf("app - mId : %s \n", charID);
\r
119 printf("app - mTitle : %s \n", title);
\r
120 printf("app - mContentText : %s \n", body);
\r
123 NSMessage * msg = (NSMessage *)malloc(sizeof(NSMessage));
\r
125 sprintf(charID, "%d", id);
\r
127 msg->mId = strdup(charID);
\r
128 msg->mTitle = strdup(title);
\r
129 msg->mContentText = strdup(body);
\r
131 NSSendNotification(msg);
\r
136 OIC_LOG(INFO, TAG, "NSRead");
\r
137 NSSync * sync = (NSSync*) malloc(sizeof(NSSync));
\r
139 sync->mMessageId = strdup("dev_001");
\r
147 OIC_LOG(INFO, TAG, "NSAccept");
\r
149 NSConsumer * consumer = (NSConsumer *)malloc(sizeof(NSConsumer));
\r
150 consumer->mId = strdup("dev_001");
\r
151 consumer->mUserData = NULL;
\r
152 bool accepted = true;
\r
154 NSAccept(consumer, accepted);
\r
159 OIC_LOG(INFO, TAG, "NSGetConsumerList");
\r
162 NSConsumer *list = NULL;
\r
165 NSGetConsumerList(list, numberOfList);
\r
169 OIC_LOG(INFO, TAG, "Consumer list");
\r
173 OIC_LOG(INFO, TAG, "No Consumer list");
\r
178 OIC_LOG(INFO, TAG, "NSStartPresence - not working");
\r
179 //NSTestStartPresence();
\r
182 OIC_LOG(INFO, TAG, "NSStopPresence- not working");
\r
183 //NSTestStopPresence();
\r
186 OIC_LOG(INFO, TAG, "Under Construction");
\r