1 //******************************************************************
\r
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
\r
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
\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 "NSProviderService.h"
\r
28 void onConsumerSubscribedCallback(::NSConsumer *consumer)
\r
30 NS_LOG(DEBUG, "onConsumerSubscribedCallback - IN");
\r
31 NSConsumer *nsConsumer = new NSConsumer(consumer);
\r
32 if (NSProviderService::getInstance()->getProviderConfig().m_subscribeRequestCb != NULL)
\r
33 NSProviderService::getInstance()->getProviderConfig().m_subscribeRequestCb(nsConsumer);
\r
35 NS_LOG(DEBUG, "onConsumerSubscribedCallback - OUT");
\r
38 void onMessageSynchronizedCallback(::NSSyncInfo *syncInfo)
\r
40 NS_LOG(DEBUG, "onMessageSynchronizedCallback - IN");
\r
41 NSSyncInfo *nsSyncInfo = new NSSyncInfo(syncInfo);
\r
42 if (NSProviderService::getInstance()->getProviderConfig().m_syncInfoCb != NULL)
\r
43 NSProviderService::getInstance()->getProviderConfig().m_syncInfoCb(nsSyncInfo);
\r
45 NS_LOG(DEBUG, "onMessageSynchronizedCallback - OUT");
\r
48 ::NSMessage *NSProviderService::getNSMessage(NSMessage *msg)
\r
50 ::NSMessage *nsMsg = new ::NSMessage;
\r
51 nsMsg->messageId = msg->getMessageId();
\r
52 OICStrcpy(nsMsg->providerId, msg->getProviderId().length(), msg->getProviderId().c_str());
\r
53 nsMsg->sourceName = OICStrdup(msg->getSourceName().c_str());
\r
54 nsMsg->type = (::NSMessageType) msg->getType();
\r
55 nsMsg->dateTime = OICStrdup(msg->getTime().c_str());
\r
56 nsMsg->ttl = msg->getTTL();
\r
57 nsMsg->title = OICStrdup(msg->getTitle().c_str());
\r
58 nsMsg->contentText = OICStrdup(msg->getContentText().c_str());
\r
60 nsMsg->mediaContents = new ::NSMediaContents;
\r
61 if (msg->getMediaContents() != nullptr)
\r
62 nsMsg->mediaContents->iconImage = OICStrdup(msg->getMediaContents()->getIconImage().c_str());
\r
64 nsMsg->mediaContents->iconImage = nullptr;
\r
68 NSProviderService *NSProviderService::getInstance()
\r
70 static NSProviderService s_instance;
\r
74 NSResult NSProviderService::Start(NSProviderService::NSAccessPolicy policy,
\r
75 NSProviderService::ProviderConfig config)
\r
77 NS_LOG(DEBUG, "Start - IN");
\r
80 NSResult result = NSStartProvider((::NSAccessPolicy)policy, onConsumerSubscribedCallback,
\r
81 onMessageSynchronizedCallback);
\r
82 NS_LOG(DEBUG, "Start - OUT");
\r
86 NSResult NSProviderService::Stop()
\r
88 NS_LOG(DEBUG, "Stop - IN");
\r
89 NSResult result = NSStopProvider();
\r
90 NS_LOG(DEBUG, "Stop - OUT");
\r
94 NSResult NSProviderService::EnableRemoteService(const std::string &serverAddress)
\r
96 NS_LOG(DEBUG, "EnableRemoteService - IN");
\r
97 NSResult result = NSProviderEnableRemoteService(OICStrdup(serverAddress.c_str()));
\r
98 NS_LOG(DEBUG, "EnableRemoteService - OUT");
\r
102 NSResult NSProviderService::DisableRemoteService(const std::string &serverAddress)
\r
104 NS_LOG(DEBUG, "DisableRemoteService - IN");
\r
105 NSResult result = NSProviderDisableRemoteService(OICStrdup(serverAddress.c_str()));
\r
106 NS_LOG(DEBUG, "DisableRemoteService - OUT");
\r
110 NSResult NSProviderService::SendMessage(NSMessage *msg)
\r
112 NS_LOG(DEBUG, "SendMessage - IN");
\r
113 NSResult result = NS_ERROR;
\r
114 if (msg != nullptr)
\r
115 result = NSSendMessage(getNSMessage(msg));
\r
117 NS_LOG(DEBUG, "Empty Message");
\r
118 NS_LOG(DEBUG, "SendMessage - OUT");
\r
122 void NSProviderService::SendSyncInfo(uint64_t messageId,
\r
123 NSSyncInfo::NSSyncType type)
\r
125 NS_LOG(DEBUG, "SendSyncInfo - IN");
\r
126 NSProviderSendSyncInfo(messageId, (NSSyncType)type);
\r
127 NS_LOG(DEBUG, "SendSyncInfo - OUT");
\r
131 NSProviderService::ProviderConfig NSProviderService::getProviderConfig()
\r