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