Merge branch 'cloud-interface'
[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 \r
36 namespace OIC\r
37 {\r
38     namespace Service\r
39     {\r
40         /**\r
41          * @class   NSProviderService\r
42          * @brief   This class provides a set of C++APIs for Notification Provider.\r
43          */\r
44         class NSProviderService\r
45         {\r
46 \r
47             public:\r
48                 /**\r
49                       * Provider uses this callback function to receive subscription request of consumer\r
50                       * @param[in] consumer        Consumer who subscribes the resource\r
51                       */\r
52                 typedef void (*ConsumerSubscribedCallback)(NSConsumer *);\r
53 \r
54                 /**\r
55                       * Provider use this callback function to receive the status of the message\r
56                       * synchronization\r
57                       * @param[in] sync        Synchronization information of the notification message\r
58                       */\r
59                 typedef void (*MessageSynchronizedCallback)(NSSyncInfo *);\r
60 \r
61 \r
62                 /**\r
63                       * @struct   ProviderConfig\r
64                       * @brief Provider sets this following configuration for registering callbacks and configs\r
65                       *\r
66                       */\r
67                 typedef struct\r
68                 {\r
69                     /** m_subscribeRequestCb - ConsumerSubscribedCallback callback listener.*/\r
70                     ConsumerSubscribedCallback m_subscribeRequestCb;\r
71                     /** m_syncInfoCb - MessageSynchronizedCallback callback listener.*/\r
72                     MessageSynchronizedCallback m_syncInfoCb;\r
73 \r
74                     /* Set the policy for notification servcie refering to following\r
75                                  * if policy is true, provider decides to allow or deny for all the subscribing consumers.\r
76                                  * Otherwise(policy is false) consumer decides to request subscription to discovered providers.\r
77                                  */\r
78                     bool policy;\r
79                     /* User Information */\r
80                     std::string userInfo;\r
81                 } ProviderConfig;\r
82 \r
83                 /**\r
84                      * Access policy exchanged between provider and consumer during subscription process\r
85                      */\r
86                 enum class NSAccessPolicy\r
87                 {\r
88                     NS_ACCESS_ALLOW = 0,\r
89                     NS_ACCESS_DENY = 1,\r
90                 };\r
91 \r
92                 /**\r
93                       * API for starting the NS Provider\r
94                       *\r
95                       * @return NSProviderService Pointer to singleton instance created\r
96                       */\r
97                 static NSProviderService *getInstance();\r
98 \r
99                 /**\r
100                       * Initialize notification service for provider\r
101                       * @param[in]  policy   Accepter\r
102                       * @param[in]  config   ProviderConfig Callback function pointers to onConsumerSubscribed,\r
103                       * and onMessageSynchronized function listeners\r
104                       * @return :: result code of Provider Service\r
105                       */\r
106                 NSResult Start(ProviderConfig config);\r
107 \r
108                 /**\r
109                       * Terminate notification service for provider\r
110                       * @return :: result code of Provider Service\r
111                       */\r
112                 NSResult Stop();\r
113 \r
114                 /**\r
115                       * Request to publish resource to cloud server\r
116                       * @param[in]  server address combined with IP address and port number using delimiter :\r
117                       * @return  result code of Provider Service\r
118                       */\r
119                 NSResult EnableRemoteService(const std::string &serverAddress);\r
120 \r
121                 /**\r
122                       * Request to cancel remote service using cloud server\r
123                       * @param[in]  server address combined with IP address and port number using delimiter :\r
124                       * @return  result code of Provider Service\r
125                       */\r
126                 NSResult DisableRemoteService(const std::string &serverAddress);\r
127 \r
128                 /**\r
129                       * Send notification message to all subscribers\r
130                       * @param[in]  msg  Notification message including id, title, contentText\r
131                       * @return :: result code of Provider Service\r
132                       */\r
133                 NSResult SendMessage(NSMessage *msg);\r
134 \r
135 \r
136                 /**\r
137                       * Send read-check to provider in order to synchronize notification status with other consumers\r
138                       * @param[in]  messageId  Notification message to synchronize the status\r
139                       * @param[in]  type  NotificationSyncType of the SyncInfo message\r
140                       */\r
141                 void SendSyncInfo(uint64_t messageId, NSSyncInfo::NSSyncType type);\r
142 \r
143                 /**\r
144                      * Initialize NSMessage class, service sets message id and provider(device) id\r
145                      * @return ::NSMessage *\r
146                      */\r
147                 NSMessage *CreateMessage();\r
148 \r
149                 /**\r
150                       *  get Provider config values\r
151                       * @return ProviderConfig callbaks set\r
152                       */\r
153                 ProviderConfig getProviderConfig();\r
154 \r
155             private :\r
156                 ProviderConfig m_config;\r
157 \r
158             private:\r
159                 NSProviderService()\r
160                 {\r
161                     m_config.m_subscribeRequestCb = NULL;\r
162                     m_config.m_syncInfoCb = NULL;\r
163                 }\r
164                 ~NSProviderService() = default;\r
165                 NSProviderService(const NSProviderService &) = delete;\r
166                 NSProviderService &operator=(const NSProviderService &) = delete;\r
167                 NSProviderService(const NSProviderService &&) = delete;\r
168                 NSProviderService &operator=(const NSProviderService && ) = delete;\r
169 \r
170                 ::NSMessage *getNSMessage(NSMessage *msg);\r
171         };\r
172     }\r
173 }\r
174 #endif /* _NS_PROVIDER_SERVICE_H_ */\r