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"
43 * @brief This class provides a set of Notification service Provider representation APIs.
50 * Invoked when the provider state is changed
51 * @param[in] providerState NSProviderState of the notification resource
53 typedef void (* ProviderStateCallback)(NSProviderState);
56 * Consumer use this callback function to receive notification message from provider
58 * @param[in] message Notification message
60 typedef void (*MessageReceivedCallback)(NSMessage);
63 * Provider and consumer use this callback function to receive the status of the message
65 * @param[in] sync Synchronization information of the notification message
67 typedef void (*SyncInfoReceivedCallback)(NSSyncInfo);
70 * Constructor of NSProvider.
72 NSProvider(): m_topicList(new NSTopicsList()), m_state(NSProviderState::DENY),
73 m_subscribedState(NSProviderSubscribedState::DENY),
74 m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
79 * Constructor of NSProvider.
81 * @param providerId - providerId of the Notification.
83 NSProvider(const std::string &providerId) : m_providerId(providerId),
84 m_topicList(new NSTopicsList()), m_state(NSProviderState::DENY),
85 m_subscribedState(NSProviderSubscribedState::DENY),
86 m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
91 * Constructor of NSProvider.
93 * @param providerId - providerId of the Notification.
94 * @param topicList - NSTopicsList of interested Topics.
96 NSProvider(const std::string &providerId, NSTopicsList *topicList) : m_providerId(
97 providerId), m_topicList(topicList), m_state(NSProviderState::DENY),
98 m_subscribedState(NSProviderSubscribedState::DENY),
99 m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)
104 * Constructor of NSProvider.
106 * @param provider - of type NSProvider.
108 NSProvider(::NSProvider *provider);
111 * Copy Constructor of NSProvider.
113 * @param provider - NSProvider to initialize.
115 NSProvider(const NSProvider &provider);
118 * Copy assignment operator of NSProvider.
120 * @param provider - NSProvider to initialize.
121 * @return NSProvider object reference
123 NSProvider &operator=(const NSProvider &provider);
126 * Destructor of NSProvider.
131 * This method is for getting ProviderId from the Notification service provider.
133 * @return ProviderId as string.
135 std::string getProviderId() const;
138 * This method is for getting NSTopic List from the Notification service provider.
140 * @return NSTopicsList as pointer.
142 NSTopicsList *getTopicList() const;
145 * Update Topic list that is wanted to be subscribed from provider
147 * @param topicList - NSTopicsList of interested Topics.
150 NSResult updateTopicList(NSTopicsList *topicList);
153 * This method is for getting ProviderState from the Notification service provider.
155 * @return ProviderState as NSProviderState.
157 NSProviderState getProviderState() const;
160 * This method is for getting SubscribedState from the Notification service provider.
162 * @return subscribedState as NSProviderSubscribedState.
164 NSProviderSubscribedState getProviderSubscribedState() const;
167 * This method is for requesting subscription of Notification service.
168 * This API should be called with a valid Provider object obtained from Discovery callback.
169 * The API should not be called when the Provider is in STOPPED state.
171 * Discovery APIs to discover Providers are as below.
172 * Start/rescanProvider for D2D,
173 * enableRemoteService for D2S,
175 * @return ::NS_OK or result code of NSResult
177 NSResult subscribe();
180 * Request to unsubscribe in order not to receive notification message from provider
182 * This API should be called with a valid Provider object obtained from Discovery callback.
183 * The API should not be called when the Provider is in STOPPED state.
185 * @return ::NS_OK or result code of NSResult
187 NSResult unsubscribe();
190 * This method is for requesting subscription status from Provider of Notification service.
196 * This method is for Sending SyncInfo of Notification service.
198 * @param messageId - id of type message.
199 * @param type - NSSyncType of Notification service.
200 * @return ::NS_OK or result code of NSResult
202 NSResult sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);
205 * This method is for registering for listeners of Notification .
207 * @param stateHandle - ProviderStateCallback callback.
208 * @param messageHandle - MessageReceivedCallback callback.
209 * @param syncHandle - SyncInfoReceivedCallback callback
211 void setListener(ProviderStateCallback stateHandle,
212 MessageReceivedCallback messageHandle,
213 SyncInfoReceivedCallback syncHandle);
216 * This method is for getting the registered cb of Provider State received.
218 * @return stateCb - ProviderStateCallback .
220 ProviderStateCallback getProviderStateReceivedCb() const;
223 * This method is for getting the registered cb of Notification message received.
225 * @return messageCb - MessageReceivedCallback .
227 MessageReceivedCallback getMessageReceivedCb() const;
230 * This method is for getting the registered cb of Notification SyncInfo received.
232 * @return syncInfoCb - SyncInfoReceivedCallback .
234 SyncInfoReceivedCallback getSyncInfoReceivedCb() const;
237 * This method is for setting NSTopic List for the Notification service provider.
239 * @param topicsList as NSTopicsList pointer.
241 void setTopicList(NSTopicsList *topicsList);
244 * This method is for setting ProviderState for the Notification service provider.
246 * @param providerState as NSProviderState.
248 void setProviderState(const NSProviderState &providerState);
251 * This method is for setting subscribedState for the Notification service provider.
253 * @param subscribedState as NSProviderSubscribedState.
255 void setProviderSubscribedState(const NSProviderSubscribedState &subscribedState);
258 ::NSProvider *getNSProvider();
259 bool isValid() const;
262 std::string m_providerId;
263 NSTopicsList *m_topicList;
264 NSProviderState m_state;
265 NSProviderSubscribedState m_subscribedState;
267 ProviderStateCallback m_stateCb;
268 MessageReceivedCallback m_messageCb;
269 SyncInfoReceivedCallback m_syncInfoCb;
273 #endif /* _NS_PROVIDER_H_ */