replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / service / notification / cpp-wrapper / consumer / inc / NSProvider.h
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /**
22  * @file
23  *
24  * This file contains Notification service Provider representation.
25  */
26
27 #ifndef _NS_PROVIDER_H_
28 #define _NS_PROVIDER_H_
29
30
31 #include <string>
32 #include "NSSyncInfo.h"
33 #include "NSMessage.h"
34 #include "NSUtils.h"
35 #include "NSTopicsList.h"
36 #include "NSException.h"
37
38 namespace OIC
39 {
40     namespace Service
41     {
42         /**
43          * @class   NSProvider
44          * @brief   This class provides a set of Notification service Provider representation APIs.
45          */
46         class NSProvider
47         {
48             public:
49
50                 /**
51                      * Invoked when the provider state is changed
52                      * @param[in] providerState  NSProviderState of the notification resource
53                      */
54                 typedef void (* ProviderStateCallback)(NSProviderState);
55
56                 /**
57                      * Consumer use this callback function to receive notification message from provider
58                      * synchronization
59                      * @param[in] message     Notification message
60                      */
61                 typedef void (*MessageReceivedCallback)(NSMessage);
62
63                 /**
64                      * Provider and consumer use this callback function to receive the status of the message
65                      * synchronization
66                      * @param[in] sync        Synchronization information of the notification message
67                      */
68                 typedef void (*SyncInfoReceivedCallback)(NSSyncInfo);
69
70                 /**
71                       * Constructor of NSProvider.
72                       */
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)
76                 {
77                 }
78
79                 /**
80                       * Constructor of NSProvider.
81                       *
82                       * @param providerId - providerId of the Notification.
83                       */
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)
88                 {
89                 }
90
91                 /**
92                       * Constructor of NSProvider.
93                       *
94                       * @param providerId - providerId of the Notification.
95                       * @param topicList - NSTopicsList of interested Topics.
96                       */
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)
101                 {
102                 }
103
104                 /**
105                       * Constructor of NSProvider.
106                       *
107                       * @param provider - of type NSProvider.
108                       */
109                 NSProvider(::NSProvider *provider);
110
111                 /**
112                      * Copy Constructor of NSProvider.
113                      *
114                      * @param provider - NSProvider to initialize.
115                      */
116                 NSProvider(const NSProvider &provider);
117
118                 /**
119                      * Copy assignment operator of NSProvider.
120                      *
121                      * @param provider -  NSProvider to initialize.
122                      * @return NSProvider object reference
123                      */
124                 NSProvider &operator=(const NSProvider &provider);
125
126                 /**
127                       * Destructor of NSProvider.
128                       */
129                 ~NSProvider() = default;
130
131                 /**
132                       * This method is for getting ProviderId from the Notification service provider.
133                       *
134                       * @return ProviderId as string.
135                       */
136                 std::string getProviderId() const;
137
138                 /**
139                       * This method is for getting NSTopic List from the Notification service provider.
140                       *
141                       * @return NSTopicsList  as pointer.
142                       */
143                 std::shared_ptr<NSTopicsList> getTopicList() const  throw (NSException);
144
145                 /**
146                      * Update Topic list that is wanted to be subscribed from provider
147                      *
148                      * @param topicList - NSTopicsList of interested Topics.
149                      * @return NSResult
150                      */
151                 NSResult updateTopicList(std::shared_ptr<NSTopicsList> topicList)  throw (NSException);
152
153                 /**
154                       * This method is for getting ProviderState from the Notification service provider.
155                       *
156                       * @return ProviderState as NSProviderState.
157                       */
158                 NSProviderState getProviderState() const;
159
160                 /**
161                       * This method is for getting SubscribedState from the Notification service provider.
162                       *
163                       * @return subscribedState as NSProviderSubscribedState.
164                       */
165                 NSProviderSubscribedState getProviderSubscribedState() const  throw (NSException);
166
167                 /**
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.
171                       *
172                       * Discovery APIs to discover Providers are as below.
173                       * Start/rescanProvider for D2D,
174                       * enableRemoteService for D2S,
175                       *
176                       * @return ::NS_OK or result code of NSResult
177                       */
178                 NSResult subscribe()  throw (NSException);
179
180                 /**
181                       * Request to unsubscribe in order not to receive notification message from provider
182                       *
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.
185                       *
186                       * @return ::NS_OK or result code of NSResult
187                      */
188                 NSResult unsubscribe()  throw (NSException);
189
190                 /**
191                       * This method is for requesting subscription status from Provider of Notification service.
192                       *
193                       */
194                 bool isSubscribed()  throw (NSException);
195
196                 /**
197                       * This method is for Sending SyncInfo of Notification service.
198                       *
199                       * @param messageId - id of type message.
200                       * @param type - NSSyncType of Notification service.
201                       * @return ::NS_OK or result code of NSResult
202                       */
203                 NSResult sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type)  throw (NSException);
204
205                 /**
206                       * This method is for registering for listeners of Notification .
207                       *
208                       * @param stateHandle - ProviderStateCallback callback.
209                       * @param messageHandle - MessageReceivedCallback callback.
210                       * @param syncHandle - SyncInfoReceivedCallback callback
211                       */
212                 void setListener(ProviderStateCallback stateHandle,
213                                  MessageReceivedCallback messageHandle,
214                                  SyncInfoReceivedCallback syncHandle);
215
216                 /**
217                       * This method is for getting the registered cb of Provider State received.
218                       *
219                       * @return stateCb - ProviderStateCallback .
220                       */
221                 ProviderStateCallback getProviderStateReceivedCb() const;
222
223                 /**
224                       * This method is for getting the registered cb of Notification message received.
225                       *
226                       * @return messageCb - MessageReceivedCallback .
227                       */
228                 MessageReceivedCallback getMessageReceivedCb() const;
229
230                 /**
231                       * This method is for getting the registered cb of Notification SyncInfo received.
232                       *
233                       * @return syncInfoCb - SyncInfoReceivedCallback .
234                       */
235                 SyncInfoReceivedCallback getSyncInfoReceivedCb() const;
236
237                 /**
238                       * This method is for setting NSTopic List for the Notification service provider.
239                       *
240                       * @param topicsList  as NSTopicsList pointer.
241                       */
242                 void setTopicList(std::shared_ptr<NSTopicsList> topicsList);
243
244                 /**
245                      * This method is for setting ProviderState for the Notification service provider.
246                      *
247                      * @param providerState as NSProviderState.
248                      */
249                 void setProviderState(const NSProviderState &providerState);
250
251                 /**
252                      * This method is for setting subscribedState for the Notification service provider.
253                      *
254                      * @param subscribedState as NSProviderSubscribedState.
255                      */
256                 void setProviderSubscribedState(const NSProviderSubscribedState &subscribedState);
257
258             private:
259                 ::NSProvider *getNSProvider();
260                 bool isValid() const;
261
262             private:
263                 std::string m_providerId;
264                 std::shared_ptr<NSTopicsList> m_topicList;
265                 NSProviderState m_state;
266                 NSProviderSubscribedState m_subscribedState;
267
268                 ProviderStateCallback m_stateCb;
269                 MessageReceivedCallback m_messageCb;
270                 SyncInfoReceivedCallback m_syncInfoCb;
271         };
272     }
273 }
274 #endif /* _NS_PROVIDER_H_ */