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 Address ID: %s\n", consumer->mAddress);
\r
60 printf("NS_APP Consumer Device ID: %s\n", consumer->mDeviceId);
\r
62 NSAccept(consumer, true);
\r
65 void syncCallback(NSSyncInfo *sync)
\r
67 OIC_LOG(INFO, TAG, "sync requested");
\r
69 printf("NS_APP Sync State: %d\n", sync->state);
\r
75 pthread_t processThread;
\r
77 OIC_LOG(INFO, TAG, "NSStartProvider()");
\r
79 if (OCInit(NULL, 0, OC_CLIENT_SERVER) != OC_STACK_OK)
\r
81 OIC_LOG(INFO, TAG, "OCStack init error");
\r
85 pthread_create(&processThread, NULL, OCProcessThread, NULL);
\r
91 printf("1. NSStartProvider(Accepter: Provider) \n");
\r
92 printf("2. NSStartProvider(Accepter: Consumer) \n");
\r
93 printf("3. NSSendNotification() \n");
\r
94 printf("4. NSRead \n");
\r
95 printf("5. NSStopProvider() \n");
\r
96 printf("6. NSGetConsumerList \n");
\r
97 //printf("7. startPresence \n");
\r
98 //printf("8. stopPresence \n");
\r
99 printf("0. Exit() \n");
\r
101 printf("input : ");
\r
105 scanf("%c", &dummy);
\r
111 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Provider)");
\r
112 NSStartProvider(NS_ACCESS_ALLOW, subscribeRequestCallback, syncCallback);
\r
115 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Consumer)");
\r
116 NSStartProvider(NS_ACCESS_DENY, subscribeRequestCallback, syncCallback);
\r
119 OIC_LOG(INFO, TAG, "NSSendNotification()");
\r
124 printf("id : %d\n", ++id);
\r
125 printf("title : ");
\r
132 printf("app - mTitle : %s \n", title);
\r
133 printf("app - mContentText : %s \n", body);
\r
135 NSMessage * msg = (NSMessage *)OICMalloc(sizeof(NSMessage));
\r
137 msg->title = strdup(title);
\r
138 msg->contentText = OICStrdup(body);
\r
139 msg->sourceName = OICStrdup("OCF");
\r
141 NSSendMessage(msg);
\r
146 OIC_LOG(INFO, TAG, "NSRead");
\r
147 NSSyncInfo * sync = (NSSyncInfo*) OICMalloc(sizeof(NSSyncInfo));
\r
149 sync->messageId = OICStrdup("dev_001");
\r
158 OIC_LOG(INFO, TAG, "NSGetConsumerList");
\r
161 OIC_LOG(INFO, TAG, "NSStartPresence - not working");
\r
162 //NSTestStartPresence();
\r
165 OIC_LOG(INFO, TAG, "NSStopPresence- not working");
\r
166 //NSTestStopPresence();
\r
173 OIC_LOG(INFO, TAG, "Under Construction");
\r