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(NSSync *sync)
\r
67 OIC_LOG(INFO, TAG, "sync requested");
\r
69 printf("NS_APP Sync State: %d\n", sync->mState);
\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_ACCEPTER_PROVIDER, subscribeRequestCallback, syncCallback);
\r
115 OIC_LOG(INFO, TAG, "NSStartProvider(Accepter: Consumer)");
\r
116 NSStartProvider(NS_ACCEPTER_CONSUMER, subscribeRequestCallback, syncCallback);
\r
119 OIC_LOG(INFO, TAG, "NSSendNotification()");
\r
125 printf("id : %d\n", ++id);
\r
126 printf("title : ");
\r
133 printf("app - mId : %s \n", charID);
\r
134 printf("app - mTitle : %s \n", title);
\r
135 printf("app - mContentText : %s \n", body);
\r
137 NSMessage * msg = (NSMessage *)OICMalloc(sizeof(NSMessage));
\r
139 sprintf(charID, "%d", id);
\r
141 msg->mId = strdup(charID);
\r
142 msg->mTitle = strdup(title);
\r
143 msg->mContentText = OICStrdup(body);
\r
144 msg->mSource = NULL;
\r
146 NSSendMessage(msg);
\r
151 OIC_LOG(INFO, TAG, "NSRead");
\r
152 NSSync * sync = (NSSync*) OICMalloc(sizeof(NSSync));
\r
154 sync->mMessageId = OICStrdup("dev_001");
\r
163 OIC_LOG(INFO, TAG, "NSGetConsumerList");
\r
166 OIC_LOG(INFO, TAG, "NSStartPresence - not working");
\r
167 //NSTestStartPresence();
\r
170 OIC_LOG(INFO, TAG, "NSStopPresence- not working");
\r
171 //NSTestStopPresence();
\r
178 OIC_LOG(INFO, TAG, "Under Construction");
\r