Added C++ wrapper for the Notification Service Provider and Consumer.
[platform/upstream/iotivity.git] / service / notification / cpp-wrapper / consumer / inc / NSConsumerService.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 /**\r
23  * @file\r
24  *\r
25  * This file provides C++ Wrapper APIs of Notification Service for Consumer.\r
26  */\r
27 \r
28 #ifndef _NS_CONSUMER_SERVICE_H_\r
29 #define _NS_CONSUMER_SERVICE_H_\r
30 \r
31 #include "NSCommon.h"\r
32 #include "NSConsumerInterface.h"\r
33 #include <list>\r
34 #include <algorithm>\r
35 #include "NSConstants.h"\r
36 \r
37 \r
38 namespace OIC\r
39 {\r
40     namespace Service\r
41     {\r
42         class NSProvider;\r
43         /**\r
44          * @class   NSConsumerService\r
45          * @brief   This class provides a set of C++APIs for Notification Consumer.\r
46          */\r
47         class NSConsumerService\r
48         {\r
49 \r
50             public :\r
51                 /**\r
52                      * Consumer uses this callback function to receive the discovered providers\r
53                      * @param[in] provider        Provider who has the notification resource\r
54                      */\r
55                 typedef void (*ProviderDiscoveredCallback)(NSProvider *);\r
56 \r
57                 /**\r
58                      * Consumer uses this callback function on subscription accepted by provider\r
59                      * @param[in] provider        Provider who has the notification resource\r
60                      */\r
61                 typedef void (* AcceptedCallback)(NSProvider *);\r
62 \r
63                 /**\r
64                      * @struct   ConsumerConfig\r
65                      * @brief Consumer sets this callback function configuration for registering callbacks\r
66                      *\r
67                      */\r
68                 typedef struct\r
69                 {\r
70                     /** m_discoverCb - ProviderDiscoveredCallback callback listener.*/\r
71                     ProviderDiscoveredCallback m_discoverCb;\r
72                     /** m_acceptedCb - AcceptedCallback callback listener.*/\r
73                     AcceptedCallback m_acceptedCb;\r
74                 } ConsumerConfig;\r
75 \r
76                 /**\r
77                       * API for getting the Instance of NSConsumerService class\r
78                       *\r
79                       * @return Instance of the "NSConsumerService" class\r
80                       */\r
81                 static NSConsumerService *getInstance();\r
82 \r
83                 /**\r
84                       * Initialize notification service for consumer\r
85                       * @param[in]  config   ConsumerConfig Callback function pointers to onDiscoverd,\r
86                       * OnAccepted, OnMessageReceived and OnSyncInfoReceived functions\r
87                       */\r
88                 void Start(ConsumerConfig config);\r
89 \r
90                 /**\r
91                       * Terminate notification service for consumer\r
92                       */\r
93                 void Stop();\r
94 \r
95                 /**\r
96                      * Request to discover to remote address as parameter.\r
97                      * @param[in]  server address combined with IP address and port number using delimiter :\r
98                      * @return  result code of NSResult\r
99                      */\r
100                 NSResult EnableRemoteService(const std::string &serverAddress);\r
101 \r
102                 /**\r
103                       * Request discovery manually\r
104                       */\r
105                 void RescanProvider();\r
106 \r
107                 /**\r
108                       *  request to get NSProvider pointer\r
109                       * @param id -id as string\r
110                       *\r
111                       * @return pointer to NSProvider\r
112                       */\r
113                 NSProvider *getProvider(const std::string &id);\r
114 \r
115                 /**\r
116                       *  get consumer config values\r
117                       * @return ConsumerConfig callbaks set\r
118                       */\r
119                 ConsumerConfig getConsumerConfig();\r
120 \r
121                 /**\r
122                       *  get list of providers acceted.\r
123                       * @return m_acceptedProviders -list of accepted providers\r
124                       */\r
125                 std::list<NSProvider *> getAcceptedProviders();\r
126 \r
127             private :\r
128                 ConsumerConfig m_config;\r
129                 std::list<NSProvider *> m_acceptedProviders;\r
130 \r
131             private :\r
132                 NSConsumerService();\r
133                 ~NSConsumerService();\r
134                 NSConsumerService(const NSConsumerService & ) = delete;\r
135                 NSConsumerService &operator=(const NSConsumerService & ) = delete;\r
136                 NSConsumerService(const NSConsumerService &&) = delete;\r
137                 NSConsumerService &operator=(const NSConsumerService && ) = delete;\r
138 \r
139         };\r
140     }\r
141 }\r
142 \r
143 #endif //_NS_CONSUMER_SERVICE_H_\r