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 <cstring>\r
33 #include "oic_string.h"\r
34 #include "NSSyncInfo.h"\r
35 #include "NSConstants.h"\r
36 \r
37 namespace OIC\r
38 {\r
39     namespace Service\r
40     {\r
41         class NSMessage;\r
42         class NSSyncInfo;\r
43         /**\r
44          * @class   NSProvider\r
45          * @brief   This class provides a set of Notification service Provider representation APIs.\r
46          */\r
47         class NSProvider\r
48         {\r
49             public:\r
50                 /**\r
51                      * Consumer use this callback function to receive notification message from provider\r
52                      * synchronization\r
53                      * @param[in] message     Notification message\r
54                      */\r
55                 typedef void (*MessageReceivedCallback)(NSMessage *);\r
56 \r
57                 /**\r
58                      * Provider and consumer use this callback function to receive the status of the message\r
59                      * synchronization\r
60                      * @param[in] sync        Synchronization information of the notification message\r
61                      */\r
62                 typedef void (*SyncInfoReceivedCallback)(NSSyncInfo *);\r
63 \r
64                 /**\r
65                       * Constructor of NSProvider.\r
66                       */\r
67                 NSProvider(): m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
68 \r
69                 /**\r
70                       * Constructor of NSProvider.\r
71                       *\r
72                       * @param providerId - providerId of the Notification.\r
73                       */\r
74                 NSProvider(const std::string &providerId) : m_providerId(providerId),\r
75                     m_messageCb(NULL), m_syncInfoCb(NULL) {}\r
76 \r
77                 /**\r
78                       * Constructor of NSProvider.\r
79                       *\r
80                       * @param provider - of type NSProvider.\r
81                       */\r
82                 NSProvider(::NSProvider *provider);\r
83 \r
84 \r
85                 /**\r
86                       * Destructor of NSProvider.\r
87                       */\r
88                 ~NSProvider() = default;\r
89 \r
90                 /**\r
91                       * This method is for getting ProviderId from the Notification service provider.\r
92                       *\r
93                       * @return ProviderId as string.\r
94                       */\r
95                 std::string getProviderId() const;\r
96 \r
97                 /**\r
98                       * This method is for requesting subscription of Notification service.\r
99                       *\r
100                       */\r
101                 void subscribe();\r
102 \r
103                 /**\r
104                       * This method is for requesting unsubscription of Notification service.\r
105                       *\r
106                       */\r
107                 void unSubscribe();\r
108 \r
109                 /**\r
110                       * This method is for Sending SyncInfo of Notification service.\r
111                       *\r
112                       * @param messageId - id of type message.\r
113                       * @param type - NSSyncType of Notification service.\r
114                       */\r
115                 void SendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);\r
116 \r
117                 /**\r
118                       * This method is for registering for listeners of Notification .\r
119                       *\r
120                       * @param messageHandle - MessageReceivedCallback callback.\r
121                       * @param syncHandle - SyncInfoReceivedCallback callback\r
122                       */\r
123                 void setListener(MessageReceivedCallback messageHandle,\r
124                                  SyncInfoReceivedCallback syncHandle);\r
125 \r
126                 /**\r
127                       * This method is for getting the registered cb of Notification message received.\r
128                       *\r
129                       * @return messageCb - MessageReceivedCallback .\r
130                       */\r
131                 MessageReceivedCallback getMessageReceivedCb();\r
132 \r
133                 /**\r
134                       * This method is for getting the registered cb of Notification SyncInfo received.\r
135                       *\r
136                       * @return syncInfoCb - SyncInfoReceivedCallback .\r
137                       */\r
138                 SyncInfoReceivedCallback getSyncInfoReceivedCb();\r
139 \r
140             private:\r
141                 ::NSProvider *getNSProvider();\r
142 \r
143             private:\r
144                 std::string m_providerId;\r
145                 MessageReceivedCallback m_messageCb;\r
146                 SyncInfoReceivedCallback m_syncInfoCb;\r
147 \r
148         };\r
149     }\r
150 }\r
151 #endif /* _NS_PROVIDER_H_ */\r