1 /******************************************************************
\r
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
19 ******************************************************************/
\r
22 #include <stdbool.h>
\r
24 #include "NSCommon.h"
\r
25 #include "NSProviderInterface.h"
\r
27 #include "octypes.h"
\r
28 #include "pthread.h"
\r
29 #include "oic_string.h"
\r
30 #include "oic_malloc.h"
\r
32 #define TAG "notiProviderExample"
\r
34 extern char *strdup(const char *s);
\r
36 bool isExit = false;
\r
40 void* OCProcessThread(void * ptr)
\r
45 if (OCProcess() != OC_STACK_OK)
\r
47 OIC_LOG(ERROR, TAG, "OCStack process error");
\r
55 void subscribeRequestCallback(NSConsumer *consumer)
\r
57 OIC_LOG(INFO, TAG, "consumer requested to subscribe");
\r
59 printf("NS_APP Consumer Device ID: %s\n", consumer->consumerId);
\r
61 NSAccept(consumer, true);
\r
64 void syncCallback(NSSyncInfo *sync)
\r
66 OIC_LOG(INFO, TAG, "sync requested");
\r
68 printf("NS_APP Sync State: %d\n", sync->state);
\r
74 pthread_t processThread;
\r
76 OIC_LOG(INFO, TAG, "NSStartProvider()");
\r
78 if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
\r
80 OIC_LOG(INFO, TAG, "OCStack init error");
\r
84 pthread_create(&processThread, NULL, OCProcessThread, NULL);
\r
90 printf("1. NSStartProvider(Accepter: Provider) \n");
\r
91 printf("2. NSStartProvider(Accepter: Consumer) \n");
\r
92 printf("3. NSSendNotification() \n");
\r
93 printf("4. NSRead \n");
\r
94 printf("5. NSStopProvider() \n");
\r
95 printf("6. NSGetConsumerList \n");
\r
96 //printf("7. startPresence \n");
\r
97 //printf("8. stopPresence \n");
\r
98 printf("0. Exit() \n");
\r
100 printf("input : ");
\r
104 scanf("%c", &dummy);
\r
110 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Provider)");
\r
111 NSStartProvider(NS_ACCESS_ALLOW, subscribeRequestCallback, syncCallback);
\r
114 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Consumer)");
\r
115 NSStartProvider(NS_ACCESS_DENY, subscribeRequestCallback, syncCallback);
\r
118 OIC_LOG(INFO, TAG, "NSSendNotification()");
\r
123 printf("id : %d\n", ++id);
\r
124 printf("title : ");
\r
131 printf("app - mTitle : %s \n", title);
\r
132 printf("app - mContentText : %s \n", body);
\r
134 NSMessage * msg = NSCreateMessage();
\r
136 msg->title = OICStrdup(title);
\r
137 msg->contentText = OICStrdup(body);
\r
138 msg->sourceName = OICStrdup("OCF");
\r
140 NSSendMessage(msg);
\r
145 OIC_LOG(INFO, TAG, "NSRead");
\r
146 NSSyncInfo * sync = (NSSyncInfo*) OICMalloc(sizeof(NSSyncInfo));
\r
148 sync->messageId = OICStrdup("dev_001");
\r
157 OIC_LOG(INFO, TAG, "NSGetConsumerList");
\r
160 OIC_LOG(INFO, TAG, "NSStartPresence - not working");
\r
161 //NSTestStartPresence();
\r
164 OIC_LOG(INFO, TAG, "NSStopPresence- not working");
\r
165 //NSTestStopPresence();
\r
172 OIC_LOG(INFO, TAG, "Under Construction");
\r