Merge notification service from master branch
[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 \r
78                 /**\r
79                       * Constructor of NSProvider.\r
80                       *\r
81                       * @param providerId - providerId of the Notification.\r
82                       */\r
83                 NSProvider(const std::string &providerId) : m_providerId(providerId),\r
84                     m_topicList(new NSTopicsList()), m_state(NSProviderState::DENY),\r
85                     m_subscribedState(NSProviderSubscribedState::DENY),\r
86                     m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)\r
87                 {\r
88                 }\r
89 \r
90                 /**\r
91                       * Constructor of NSProvider.\r
92                       *\r
93                       * @param providerId - providerId of the Notification.\r
94                       * @param topicList - NSTopicsList of interested Topics.\r
95                       */\r
96                 NSProvider(const std::string &providerId, NSTopicsList *topicList) : m_providerId(\r
97                         providerId), m_topicList(topicList), m_state(NSProviderState::DENY),\r
98                     m_subscribedState(NSProviderSubscribedState::DENY),\r
99                     m_stateCb(NULL), m_messageCb(NULL), m_syncInfoCb(NULL)\r
100                 {\r
101                 }\r
102 \r
103                 /**\r
104                       * Constructor of NSProvider.\r
105                       *\r
106                       * @param provider - of type NSProvider.\r
107                       */\r
108                 NSProvider(::NSProvider *provider);\r
109 \r
110                 /**\r
111                      * Copy Constructor of NSProvider.\r
112                      *\r
113                      * @param provider - NSProvider to initialize.\r
114                      */\r
115                 NSProvider(const NSProvider &provider);\r
116 \r
117                 /**\r
118                      * Copy assignment operator of NSProvider.\r
119                      *\r
120                      * @param provider -  NSProvider to initialize.\r
121                      * @return NSProvider object reference\r
122                      */\r
123                 NSProvider &operator=(const NSProvider &provider);\r
124 \r
125                 /**\r
126                       * Destructor of NSProvider.\r
127                       */\r
128                 ~NSProvider();\r
129 \r
130                 /**\r
131                       * This method is for getting ProviderId from the Notification service provider.\r
132                       *\r
133                       * @return ProviderId as string.\r
134                       */\r
135                 std::string getProviderId() const;\r
136 \r
137                 /**\r
138                       * This method is for getting NSTopic List from the Notification service provider.\r
139                       *\r
140                       * @return NSTopicsList  as pointer.\r
141                       */\r
142                 NSTopicsList *getTopicList() const;\r
143 \r
144                 /**\r
145                      * Update Topic list that is wanted to be subscribed from provider\r
146                      *\r
147                      * @param topicList - NSTopicsList of interested Topics.\r
148                      * @return NSResult\r
149                      */\r
150                 NSResult updateTopicList(NSTopicsList *topicList);\r
151 \r
152                 /**\r
153                       * This method is for getting ProviderState from the Notification service provider.\r
154                       *\r
155                       * @return ProviderState as NSProviderState.\r
156                       */\r
157                 NSProviderState getProviderState() const;\r
158 \r
159                 /**\r
160                       * This method is for getting SubscribedState from the Notification service provider.\r
161                       *\r
162                       * @return subscribedState as NSProviderSubscribedState.\r
163                       */\r
164                 NSProviderSubscribedState getProviderSubscribedState() const;\r
165 \r
166                 /**\r
167                       * This method is for requesting subscription of Notification service.\r
168                       *\r
169                       */\r
170                 void subscribe();\r
171 \r
172                 /**\r
173                       * This method is for requesting subscription status from Provider of Notification service.\r
174                       *\r
175                       */\r
176                 bool isSubscribed();\r
177 \r
178                 /**\r
179                       * This method is for Sending SyncInfo of Notification service.\r
180                       *\r
181                       * @param messageId - id of type message.\r
182                       * @param type - NSSyncType of Notification service.\r
183                       */\r
184                 void sendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);\r
185 \r
186                 /**\r
187                       * This method is for registering for listeners of Notification .\r
188                       *\r
189                       * @param stateHandle - ProviderStateCallback callback.\r
190                       * @param messageHandle - MessageReceivedCallback callback.\r
191                       * @param syncHandle - SyncInfoReceivedCallback callback\r
192                       */\r
193                 void setListener(ProviderStateCallback stateHandle,\r
194                                  MessageReceivedCallback messageHandle,\r
195                                  SyncInfoReceivedCallback syncHandle);\r
196 \r
197                 /**\r
198                       * This method is for getting the registered cb of Provider State received.\r
199                       *\r
200                       * @return stateCb - ProviderStateCallback .\r
201                       */\r
202                 ProviderStateCallback getProviderStateReceivedCb() const;\r
203 \r
204                 /**\r
205                       * This method is for getting the registered cb of Notification message received.\r
206                       *\r
207                       * @return messageCb - MessageReceivedCallback .\r
208                       */\r
209                 MessageReceivedCallback getMessageReceivedCb() const;\r
210 \r
211                 /**\r
212                       * This method is for getting the registered cb of Notification SyncInfo received.\r
213                       *\r
214                       * @return syncInfoCb - SyncInfoReceivedCallback .\r
215                       */\r
216                 SyncInfoReceivedCallback getSyncInfoReceivedCb() const;\r
217 \r
218                 /**\r
219                       * This method is for setting NSTopic List for the Notification service provider.\r
220                       *\r
221                       * @param topicsList  as NSTopicsList pointer.\r
222                       */\r
223                 void setTopicList(NSTopicsList *topicsList);\r
224 \r
225                 /**\r
226                      * This method is for setting ProviderState for the Notification service provider.\r
227                      *\r
228                      * @param providerState as NSProviderState.\r
229                      */\r
230                 void setProviderState(const NSProviderState &providerState);\r
231 \r
232                 /**\r
233                      * This method is for setting subscribedState for the Notification service provider.\r
234                      *\r
235                      * @param subscribedState as NSProviderSubscribedState.\r
236                      */\r
237                 void setProviderSubscribedState(const NSProviderSubscribedState &subscribedState);\r
238 \r
239             private:\r
240                 ::NSProvider *getNSProvider();\r
241 \r
242             private:\r
243                 std::string m_providerId;\r
244                 NSTopicsList *m_topicList;\r
245                 NSProviderState m_state;\r
246                 NSProviderSubscribedState m_subscribedState;\r
247 \r
248                 ProviderStateCallback m_stateCb;\r
249                 MessageReceivedCallback m_messageCb;\r
250                 SyncInfoReceivedCallback m_syncInfoCb;\r
251         };\r
252     }\r
253 }\r
254 #endif /* _NS_PROVIDER_H_ */\r