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