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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains Notification service Provider representation.
27 #ifndef _NS_PROVIDER_H_
28 #define _NS_PROVIDER_H_
32 #include "NSSyncInfo.h"
33 #include "NSMessage.h"
35 #include "NSTopicsList.h"
36 #include "NSException.h"
44 * @brief This class provides a set of Notification service Provider representation APIs.
51 * Invoked when the provider state is changed
52 * @param[in] providerState NSProviderState of the notification resource
54 typedef void (* ProviderStateCallback)(NSProviderState);
57 * Consumer use this callback function to receive notification message from provider
59 * @param[in] message Notification message
61 typedef void (*MessageReceivedCallback)(NSMessage);
64 * Provider and consumer use this callback function to receive the status of the message
66 * @param[in] sync Synchronization information of the notification message
68 typedef void (*SyncInfoReceivedCallback)(NSSyncInfo);
71 * Constructor of NSProvider.
73 NSProvider(): m_topicList(std::make_shared<NSTopicsList>()), m_state(NSProviderState::DENY),
74 m_subscribedState(NSProviderSubscribedState::DENY),
75 m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
80 * Constructor of NSProvider.
82 * @param providerId - providerId of the Notification.
84 NSProvider(const std::string &providerId) : m_providerId(providerId),
85 m_topicList(std::make_shared<NSTopicsList>()), m_state(NSProviderState::DENY),
86 m_subscribedState(NSProviderSubscribedState::DENY),
87 m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
92 * Constructor of NSProvider.
94 * @param providerId - providerId of the Notification.
95 * @param topicList - NSTopicsList of interested Topics.
97 NSProvider(const std::string &providerId, std::shared_ptr<NSTopicsList> topicList) : m_providerId(
98 providerId), m_topicList(topicList), m_state(NSProviderState::DENY),
99 m_subscribedState(NSProviderSubscribedState::DENY),
100 m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
105 * Constructor of NSProvider.
107 * @param provider - of type NSProvider.
109 NSProvider(::NSProvider *provider);
112 * Copy Constructor of NSProvider.
114 * @param provider - NSProvider to initialize.
116 NSProvider(const NSProvider &provider);
119 * Copy assignment operator of NSProvider.
121 * @param provider - NSProvider to initialize.
122 * @return NSProvider object reference
124 NSProvider &operator=(const NSProvider &provider);
127 * Destructor of NSProvider.
129 ~NSProvider() = default;
132 * This method is for getting ProviderId from the Notification service provider.
134 * @return ProviderId as string.
136 std::string getProviderId() const;
139 * This method is for getting NSTopic List from the Notification service provider.
141 * @return NSTopicsList as pointer.
143 std::shared_ptr<NSTopicsList> getTopicList() const throw (NSException);
146 * Update Topic list that is wanted to be subscribed from provider
148 * @param topicList - NSTopicsList of interested Topics.
151 NSResult updateTopicList(std::shared_ptr<NSTopicsList> topicList) throw (NSException);
154 * This method is for getting ProviderState from the Notification service provider.
156 * @return ProviderState as NSProviderState.
158 NSProviderState getProviderState() const;
161 * This method is for getting SubscribedState from the Notification service provider.
163 * @return subscribedState as NSProviderSubscribedState.
165 NSProviderSubscribedState getProviderSubscribedState() const throw (NSException);
168 * This method is for requesting subscription of Notification service.
169 * This API should be called with a valid Provider object obtained from Discovery callback.
170 * The API should not be called when the Provider is in STOPPED state.
172 * Discovery APIs to discover Providers are as below.
173 * Start/rescanProvider for D2D,
174 * enableRemoteService for D2S,
176 * @return ::NS_OK or result code of NSResult
178 NSResult subscribe() throw (NSException);
181 * Request to unsubscribe in order not to receive notification message from provider
183 * This API should be called with a valid Provider object obtained from Discovery callback.
184 * The API should not be called when the Provider is in STOPPED state.
186 * @return ::NS_OK or result code of NSResult
188 NSResult unsubscribe() throw (NSException);
191 * This method is for requesting subscription status from Provider of Notification service.
194 bool isSubscribed() throw (NSException);
197 * This method is for Sending SyncInfo of Notification service.
199 * @param messageId - id of type message.
200 * @param type - NSSyncType of Notification service.
201 * @return ::NS_OK or result code of NSResult
203 NSResult sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type) throw (NSException);
206 * This method is for registering for listeners of Notification .
208 * @param stateHandle - ProviderStateCallback callback.
209 * @param messageHandle - MessageReceivedCallback callback.
210 * @param syncHandle - SyncInfoReceivedCallback callback
212 void setListener(ProviderStateCallback stateHandle,
213 MessageReceivedCallback messageHandle,
214 SyncInfoReceivedCallback syncHandle);
217 * This method is for getting the registered cb of Provider State received.
219 * @return stateCb - ProviderStateCallback .
221 ProviderStateCallback getProviderStateReceivedCb() const;
224 * This method is for getting the registered cb of Notification message received.
226 * @return messageCb - MessageReceivedCallback .
228 MessageReceivedCallback getMessageReceivedCb() const;
231 * This method is for getting the registered cb of Notification SyncInfo received.
233 * @return syncInfoCb - SyncInfoReceivedCallback .
235 SyncInfoReceivedCallback getSyncInfoReceivedCb() const;
238 * This method is for setting NSTopic List for the Notification service provider.
240 * @param topicsList as NSTopicsList pointer.
242 void setTopicList(std::shared_ptr<NSTopicsList> topicsList);
245 * This method is for setting ProviderState for the Notification service provider.
247 * @param providerState as NSProviderState.
249 void setProviderState(const NSProviderState &providerState);
252 * This method is for setting subscribedState for the Notification service provider.
254 * @param subscribedState as NSProviderSubscribedState.
256 void setProviderSubscribedState(const NSProviderSubscribedState &subscribedState);
259 ::NSProvider *getNSProvider();
260 bool isValid() const;
263 std::string m_providerId;
264 std::shared_ptr<NSTopicsList> m_topicList;
265 NSProviderState m_state;
266 NSProviderSubscribedState m_subscribedState;
268 ProviderStateCallback m_stateCb;
269 MessageReceivedCallback m_messageCb;
270 SyncInfoReceivedCallback m_syncInfoCb;
274 #endif /* _NS_PROVIDER_H_ */