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