1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "NSConsumerInterface.h"
27 #include "NSConsumerCommon.h"
28 #include "NSConsumerMessageHandler.h"
29 #include "oic_malloc.h"
32 NSResult NSStartConsumer(
33 NSProviderDiscoveredCallback discoverCb,
34 NSNotificationReceivedCallback postCb,
35 NSSyncCallback syncCb)
37 if (NSIsStartedConsumer())
39 printf("is already started consumer service?\n");
43 NSSetDiscoverProviderCb(discoverCb);
44 NSSetNotificationPostedCb(postCb);
45 NSSetNotificationSyncCb(syncCb);
46 NSSetIsStartedConsumer(true);
48 if (NS_OK != NSConsumerMessageHandlerInit())
56 NSResult NSStopConsumer()
58 NSSetDiscoverProviderCb(NULL);
59 NSSetNotificationPostedCb(NULL);
60 NSSetNotificationSyncCb(NULL);
61 NSSetIsStartedConsumer(false);
66 NSResult NSSubscribeProvider(NSProvider * provider)
68 NSTask * subscribeTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE, (void *) provider);
71 NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
75 return NSConsumerPushEvent(subscribeTask);
78 NSResult NSUnsubscribeProvider(NSProvider * provider)
80 NSTask * unsubscribeTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, (void *) provider);
83 NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
87 return NSConsumerPushEvent(unsubscribeTask);
90 NSResult NSRescanProvider()
92 NSTask * discoverTask = NSMakeTask(TASK_CONSUMER_REQ_DISCOVER, NULL);
95 NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
99 return NSConsumerPushEvent(discoverTask);
102 NSResult NSRead(NSMessage * obj)
104 NSTask * readTask = NSMakeTask(TASK_SEND_READ, (void *) obj);
107 NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
111 return NSConsumerPushEvent(readTask);
114 NSResult NSDismiss(NSMessage * obj)
116 NSTask * dismissTask = NSMakeTask(TASK_SEND_DISMISS, (void *) obj);
119 NS_CONSUMER_LOG(ERROR, "NSTask allocation fail");
123 return NSConsumerPushEvent(dismissTask);
126 NSResult NSDropNSObject(NSMessage * obj)
141 OICFree(obj->mTitle);
145 if (obj->mContentText)
147 OICFree(obj->mContentText);
148 obj->mContentText = NULL;