Merge remote-tracking branch 'origin/notification-service'
[platform/upstream/iotivity.git] / service / notification / cpp-wrapper / provider / inc / NSProviderService.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 provides C++ Wrapper APIs of Notification Service for Provider.\r
25  */\r
26 \r
27 #ifndef _NS_PROVIDER_SERVICE_H_\r
28 #define _NS_PROVIDER_SERVICE_H_\r
29 \r
30 #include <string>\r
31 #include "NSConsumer.h"\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   NSProviderService\r
43          * @brief   This class provides a set of C++APIs for Notification Provider.\r
44          */\r
45         class NSProviderService\r
46         {\r
47 \r
48             public:\r
49                 /**\r
50                       * Provider uses this callback function to receive subscription request of consumer\r
51                       * @param[in] consumer        Consumer who subscribes the resource\r
52                       */\r
53                 typedef void (*ConsumerSubscribedCallback)(NSConsumer *);\r
54 \r
55                 /**\r
56                       * Provider use this callback function to receive the status of the message\r
57                       * synchronization\r
58                       * @param[in] sync        Synchronization information of the notification message\r
59                       */\r
60                 typedef void (*MessageSynchronizedCallback)(NSSyncInfo *);\r
61 \r
62 \r
63                 /**\r
64                       * @struct   ProviderConfig\r
65                       * @brief Provider sets this following configuration for registering callbacks and configs\r
66                       *\r
67                       */\r
68                 typedef struct\r
69                 {\r
70                     /** m_subscribeRequestCb - ConsumerSubscribedCallback callback listener.*/\r
71                     ConsumerSubscribedCallback m_subscribeRequestCb;\r
72                     /** m_syncInfoCb - MessageSynchronizedCallback callback listener.*/\r
73                     MessageSynchronizedCallback m_syncInfoCb;\r
74 \r
75                     /* Set the policy for notification servcie refering to following\r
76                                  * if policy is true, provider decides to allow or deny for all the subscribing consumers.\r
77                                  * Otherwise(policy is false) consumer decides to request subscription to discovered providers.\r
78                                  */\r
79                     bool policy;\r
80                     /* User Information */\r
81                     std::string userInfo;\r
82                 } ProviderConfig;\r
83 \r
84                 /**\r
85                       * API for starting the NS Provider\r
86                       *\r
87                       * @return NSProviderService Pointer to singleton instance created\r
88                       */\r
89                 static NSProviderService *getInstance();\r
90 \r
91                 /**\r
92                       * Initialize notification service for provider\r
93                       * @param[in]  policy   Accepter\r
94                       * @param[in]  config   ProviderConfig Callback function pointers to onConsumerSubscribed,\r
95                       * and onMessageSynchronized function listeners\r
96                       * @return :: result code of Provider Service\r
97                       */\r
98                 NSResult Start(ProviderConfig config);\r
99 \r
100                 /**\r
101                       * Terminate notification service for provider\r
102                       * @return :: result code of Provider Service\r
103                       */\r
104                 NSResult Stop();\r
105 \r
106                 /**\r
107                       * Request to publish resource to cloud server\r
108                       * @param[in]  server address combined with IP address and port number using delimiter :\r
109                       * @return  result code of Provider Service\r
110                       */\r
111                 NSResult EnableRemoteService(const std::string &serverAddress);\r
112 \r
113                 /**\r
114                       * Request to cancel remote service using cloud server\r
115                       * @param[in]  server address combined with IP address and port number using delimiter :\r
116                       * @return  result code of Provider Service\r
117                       */\r
118                 NSResult DisableRemoteService(const std::string &serverAddress);\r
119 \r
120                 /**\r
121                       * Send notification message to all subscribers\r
122                       * @param[in]  msg  Notification message including id, title, contentText\r
123                       * @return :: result code of Provider Service\r
124                       */\r
125                 NSResult SendMessage(NSMessage *msg);\r
126 \r
127 \r
128                 /**\r
129                       * Send read-check to provider in order to synchronize notification status with other consumers\r
130                       * @param[in]  messageId  Notification message to synchronize the status\r
131                       * @param[in]  type  NotificationSyncType of the SyncInfo message\r
132                       */\r
133                 void SendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);\r
134 \r
135                 /**\r
136                      * Initialize NSMessage class, service sets message id and provider(device) id\r
137                      * @return ::NSMessage *\r
138                      */\r
139                 NSMessage *CreateMessage();\r
140 \r
141                 /**\r
142                       *  request to get NSConsumer pointer\r
143                       * @param id -id as string\r
144                       *\r
145                       * @return pointer to NSConsumer\r
146                       */\r
147                 NSConsumer *getConsumer(const std::string &id);\r
148 \r
149                 /**\r
150                      * Add topic to topic list which is located in provider service storage\r
151                      * @param[in]  topicName Topic name to add\r
152                      * @return :: OK or result code of NSResult\r
153                      */\r
154                 NSResult AddTopic(const std::string &topicName);\r
155 \r
156                 /**\r
157                      * Delete topic from topic list\r
158                      * @param[in]  topicName Topic name to delete\r
159                      * @return :: OK or result code of NSResult\r
160                      */\r
161                 NSResult DeleteTopic(const std::string &topicName);\r
162 \r
163                 /**\r
164                      * Request topics list already registered by provider user\r
165                      * @return :: Topic list\r
166                      */\r
167                 NSTopicsList *GetTopics();\r
168 \r
169                 /**\r
170                       *  get Provider config values\r
171                       * @return ProviderConfig callbaks set\r
172                       */\r
173                 ProviderConfig getProviderConfig();\r
174 \r
175                 /**\r
176                       *  get list of Consumers accepted.\r
177                       * @return m_acceptedConsumers -list of accepted Consumers\r
178                       */\r
179                 std::list<NSConsumer *> getAcceptedConsumers();\r
180 \r
181             private :\r
182                 ProviderConfig m_config;\r
183                 std::list<NSConsumer *> m_acceptedConsumers;\r
184 \r
185             private:\r
186                 NSProviderService()\r
187                 {\r
188                     m_config.m_subscribeRequestCb = NULL;\r
189                     m_config.m_syncInfoCb = NULL;\r
190                 }\r
191                 ~NSProviderService();\r
192                 NSProviderService(const NSProviderService &) = delete;\r
193                 NSProviderService &operator=(const NSProviderService &) = delete;\r
194                 NSProviderService(const NSProviderService &&) = delete;\r
195                 NSProviderService &operator=(const NSProviderService && ) = delete;\r
196 \r
197                 ::NSMessage *getNSMessage(NSMessage *msg);\r
198         };\r
199     }\r
200 }\r
201 #endif /* _NS_PROVIDER_SERVICE_H_ */\r