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