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