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 "NSConstants.h"
29 #include "NSConsumerMessageHandler.h"
30 #include "oic_malloc.h"
33 NSResult NSStartConsumer(
34 NSProviderDiscoveredCallback discoverCb,
35 NSNotificationReceivedCallback postCb,
36 NSSyncCallback syncCb)
38 if (NSIsStartedConsumer())
40 NS_LOG(DEBUG, "is already started consumer service?");
46 NS_LOG(ERROR, "discoverCb is NULL");
52 NS_LOG(ERROR, "postCb is NULL");
58 NS_LOG(ERROR, "syncCb is NULL");
62 NSSetDiscoverProviderCb(discoverCb);
63 NSSetNotificationPostedCb(postCb);
64 NSSetNotificationSyncCb(syncCb);
65 NSSetIsStartedConsumer(true);
67 if (NS_OK != NSConsumerMessageHandlerInit())
76 NSResult NSStopConsumer()
78 NSSetDiscoverProviderCb(NULL);
79 NSSetNotificationPostedCb(NULL);
80 NSSetNotificationSyncCb(NULL);
81 NSSetIsStartedConsumer(false);
83 NSConsumerMessageHandlerExit();
88 NSResult NSSubscribe(NSProvider * provider)
90 NSTask * subscribeTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE, (void *) provider);
93 NS_LOG(ERROR, "NSTask allocation fail");
97 return NSConsumerPushEvent(subscribeTask);
100 NSResult NSUnsubscribe(NSProvider * provider)
102 NSTask * unsubscribeTask = NSMakeTask(TASK_CONSUMER_REQ_SUBSCRIBE_CANCEL, (void *) provider);
103 if (!unsubscribeTask)
105 NS_LOG(ERROR, "NSTask allocation fail");
109 return NSConsumerPushEvent(unsubscribeTask);
112 NSResult NSRescanProvider()
114 NSTask * discoverTask = NSMakeTask(TASK_CONSUMER_REQ_DISCOVER, NULL);
117 NS_LOG(ERROR, "NSTask allocation fail");
121 return NSConsumerPushEvent(discoverTask);
124 NSResult NSConsumerReadCheck(NSMessage * obj)
126 NSTask * readTask = NSMakeTask(TASK_SEND_READ, (void *) obj);
129 NS_LOG(ERROR, "NSTask allocation fail");
133 return NSConsumerPushEvent(readTask);
136 NSResult NSConsumerDismissCheck(NSMessage * obj)
138 NSTask * dismissTask = NSMakeTask(TASK_SEND_DISMISS, (void *) obj);
141 NS_LOG(ERROR, "NSTask allocation fail");
145 return NSConsumerPushEvent(dismissTask);
148 NSResult NSDropNSObject(NSMessage * obj)
163 OICFree(obj->mTitle);
167 if (obj->mContentText)
169 OICFree(obj->mContentText);
170 obj->mContentText = NULL;
175 OICFree(obj->mSource);