Merge branch 'master' into notification-service
[platform/upstream/iotivity.git] / resource / src / OCPlatform.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 //******************************************************************
22 // File name:
23 //     OCPlatform.cpp
24 //
25 // Description: Implementation of the OCPlatform.
26 //
27 //
28 //
29 //*********************************************************************
30 #include <OCPlatform.h>
31 namespace OC
32 {
33     namespace OCPlatform
34     {
35         void Configure(const PlatformConfig& config)
36         {
37             OCPlatform_impl::Configure(config);
38         }
39
40         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler)
41         {
42             return OCPlatform_impl::Instance().setDefaultDeviceEntityHandler(entityHandler);
43         }
44
45         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle,
46                                      QualityOfService QoS)
47         {
48             return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle, QoS);
49         }
50
51         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle)
52         {
53             return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle);
54         }
55
56         OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
57                                      ObservationIds& observationIds,
58                                      const std::shared_ptr<OCResourceResponse> pResponse)
59         {
60             return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
61                                      observationIds, pResponse);
62         }
63
64         OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
65                                      ObservationIds& observationIds,
66                                      const std::shared_ptr<OCResourceResponse> pResponse,
67                                      QualityOfService QoS)
68         {
69             return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
70                                      observationIds, pResponse, QoS);
71         }
72
73         OCResource::Ptr constructResourceObject(const std::string& host,
74                                      const std::string& uri,
75                                      OCConnectivityType connectivityType,
76                                      bool isObservable,
77                                      const std::vector<std::string>& resourceTypes,
78                                      const std::vector<std::string>& interfaces)
79         {
80             return OCPlatform_impl::Instance().constructResourceObject(host,
81                                      uri, connectivityType,
82                                      isObservable,
83                                      resourceTypes, interfaces);
84         }
85
86         OCStackResult findResource(const std::string& host,
87                                  const std::string& resourceName,
88                                  OCConnectivityType connectivityType,
89                                  FindCallback resourceHandler)
90         {
91             return OCPlatform_impl::Instance().findResource(host, resourceName,
92                                  connectivityType, resourceHandler);
93         }
94
95         OCStackResult findResource(const std::string& host,
96                                  const std::string& resourceName,
97                                  OCConnectivityType connectivityType,
98                                  FindCallback resourceHandler,
99                                  QualityOfService QoS)
100         {
101             return OCPlatform_impl::Instance().findResource(host, resourceName,
102                                  connectivityType, resourceHandler, QoS);
103         }
104
105         OCStackResult findResource(const std::string& host,
106                                             const std::string& resourceName,
107                                             OCConnectivityType connectivityType,
108                                             FindCallback resourceHandler,
109                                             FindErrorCallback errorHandler)
110         {
111             return OCPlatform_impl::Instance().findResource(host, resourceName,
112                                     connectivityType, resourceHandler, errorHandler);
113         }
114
115         OCStackResult findResource(const std::string& host,
116                                             const std::string& resourceName,
117                                             OCConnectivityType connectivityType,
118                                             FindCallback resourceHandler,
119                                             FindErrorCallback errorHandler,
120                                             QualityOfService QoS)
121         {
122             return OCPlatform_impl::Instance().findResource(host, resourceName,
123                                     connectivityType, resourceHandler, errorHandler, QoS);
124         }
125
126         OCStackResult getDeviceInfo(const std::string& host,
127                                  const std::string& deviceURI,
128                                  OCConnectivityType connectivityType,
129                                  FindDeviceCallback deviceInfoHandler)
130         {
131             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
132                                  connectivityType, deviceInfoHandler);
133         }
134
135         OCStackResult getDeviceInfo(const std::string& host,
136                                  const std::string& deviceURI,
137                                  OCConnectivityType connectivityType,
138                                  FindDeviceCallback deviceInfoHandler,
139                                  QualityOfService QoS)
140         {
141             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
142                                  deviceInfoHandler, QoS);
143         }
144
145         OCStackResult getPlatformInfo(const std::string& host,
146                                  const std::string& platformURI,
147                                  OCConnectivityType connectivityType,
148                                  FindPlatformCallback platformInfoHandler)
149         {
150             return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI,
151                                  connectivityType, platformInfoHandler);
152         }
153
154         OCStackResult getPlatformInfo(const std::string& host,
155                                  const std::string& platformURI,
156                                  OCConnectivityType connectivityType,
157                                  FindPlatformCallback platformInfoHandler,
158                                  QualityOfService QoS)
159         {
160             return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI, connectivityType,
161                                  platformInfoHandler, QoS);
162         }
163
164         OCStackResult registerResource(OCResourceHandle& resourceHandle,
165                                  std::string& resourceURI,
166                                  const std::string& resourceTypeName,
167                                  const std::string& resourceInterface,
168                                  EntityHandler entityHandler,
169                                  uint8_t resourceProperty)
170         {
171             return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
172                                  resourceTypeName, resourceInterface,
173                                  entityHandler, resourceProperty);
174         }
175
176         OCStackResult registerResource(OCResourceHandle& resourceHandle,
177                                  const std::shared_ptr< OCResource > resource)
178         {
179             return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
180         }
181
182         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo)
183         {
184             return OCPlatform_impl::Instance().registerDeviceInfo(deviceInfo);
185         }
186
187         OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo)
188         {
189             return OCPlatform_impl::Instance().registerPlatformInfo(platformInfo);
190         }
191
192         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
193         {
194             return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
195         }
196
197         OCStackResult unbindResource(OCResourceHandle collectionHandle,
198                                  OCResourceHandle resourceHandle)
199         {
200             return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
201         }
202
203         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
204                                  const std::vector<OCResourceHandle>& resourceHandles)
205         {
206             return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
207         }
208
209         OCStackResult bindResource(const OCResourceHandle collectionHandle,
210                                  const OCResourceHandle resourceHandle)
211         {
212             return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
213         }
214
215         OCStackResult bindResources(const OCResourceHandle collectionHandle,
216                                  const std::vector<OCResourceHandle>& resourceHandles
217                                  )
218         {
219             return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
220         }
221
222         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
223                                  const std::string& resourceTypeName)
224         {
225             return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
226         }
227
228         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
229                                  const std::string& resourceInterfaceName)
230         {
231             return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
232                                                              resourceInterfaceName);
233         }
234
235         OCStackResult startPresence(const unsigned int announceDurationSeconds)
236         {
237             return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
238         }
239
240         OCStackResult stopPresence()
241         {
242             return OCPlatform_impl::Instance().stopPresence();
243         }
244
245         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
246                                      const std::string& host,
247                                      OCConnectivityType connectivityType,
248                                      SubscribeCallback presenceHandler)
249         {
250             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
251                                                              connectivityType, presenceHandler);
252         }
253
254         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
255                                      const std::string& host,
256                                      const std::string& resourceType,
257                                      OCConnectivityType connectivityType,
258                                      SubscribeCallback presenceHandler)
259         {
260             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
261                                              resourceType, connectivityType, presenceHandler);
262         }
263
264         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
265         {
266             return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
267         }
268
269         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
270                                               const std::string& host,
271                                               const QueryParamsList& queryParams,
272                                               OCConnectivityType connectivityType,
273                                               ObserveCallback callback)
274         {
275             return OCPlatform_impl::Instance().subscribeDevicePresence(presenceHandle,
276                                                                        host,
277                                                                        queryParams,
278                                                                        connectivityType,
279                                                                        callback);
280         }
281
282         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
283         {
284             return OCPlatform_impl::Instance().sendResponse(pResponse);
285         }
286
287         OCStackResult findDirectPairingDevices(unsigned short waittime,
288                                          GetDirectPairedCallback directPairingHandler)
289         {
290             return OCPlatform_impl::Instance().findDirectPairingDevices(waittime,
291                                          directPairingHandler);
292         }
293
294         OCStackResult getDirectPairedDevices(GetDirectPairedCallback directPairingHandler)
295         {
296             return OCPlatform_impl::Instance().getDirectPairedDevices(directPairingHandler);
297         }
298
299         OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
300                                  const std::string& pinNumber,
301                                  DirectPairingCallback resultCallback)
302         {
303             return OCPlatform_impl::Instance().doDirectPairing(peer, pmSel,
304                                              pinNumber, resultCallback);
305         }
306 #ifdef WITH_CLOUD
307         OCStackResult signUp(const std::string& host,
308                              const std::string& authProvider,
309                              const std::string& authCode,
310                              OCConnectivityType connectivityType,
311                              PostCallback cloudConnectHandler)
312         {
313             return OCPlatform_impl::Instance().signUp(host, authProvider, authCode,
314                                                       connectivityType, cloudConnectHandler);
315         }
316
317         OCStackResult signIn(const std::string& host,
318                              const std::string& accessToken,
319                              OCConnectivityType connectivityType,
320                              PostCallback cloudConnectHandler)
321         {
322             return OCPlatform_impl::Instance().signIn(host, accessToken,
323                                                       connectivityType, cloudConnectHandler);
324         }
325
326         OCStackResult signOut(const std::string& host,
327                               const std::string& accessToken,
328                               OCConnectivityType connectivityType,
329                               PostCallback cloudConnectHandler)
330         {
331             return OCPlatform_impl::Instance().signOut(host, accessToken,
332                                                        connectivityType, cloudConnectHandler);
333         }
334
335         OCStackResult refreshAccessToken(const std::string& host,
336                                          const std::string& refreshToken,
337                                          OCConnectivityType connectivityType,
338                                          PostCallback cloudConnectHandler)
339         {
340             return OCPlatform_impl::Instance().refreshAccessToken(host, refreshToken,
341                                                        connectivityType, cloudConnectHandler);
342         }
343 #endif // WITH_CLOUD
344     } // namespace OCPlatform
345 } //namespace OC
346