[IOT-1440] findResource() to return list of discovered resources.
[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 findResourceList(const std::string& host, const std::string& resourceURI,
127                     OCConnectivityType connectivityType, FindResListCallback resourceHandler,
128                     QualityOfService QoS)
129         {
130             return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
131                                     connectivityType, resourceHandler, QoS);
132         }
133
134         OCStackResult getDeviceInfo(const std::string& host,
135                                  const std::string& deviceURI,
136                                  OCConnectivityType connectivityType,
137                                  FindDeviceCallback deviceInfoHandler)
138         {
139             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
140                                  connectivityType, deviceInfoHandler);
141         }
142
143         OCStackResult getDeviceInfo(const std::string& host,
144                                  const std::string& deviceURI,
145                                  OCConnectivityType connectivityType,
146                                  FindDeviceCallback deviceInfoHandler,
147                                  QualityOfService QoS)
148         {
149             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
150                                  deviceInfoHandler, QoS);
151         }
152
153         OCStackResult getPlatformInfo(const std::string& host,
154                                  const std::string& platformURI,
155                                  OCConnectivityType connectivityType,
156                                  FindPlatformCallback platformInfoHandler)
157         {
158             return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI,
159                                  connectivityType, platformInfoHandler);
160         }
161
162         OCStackResult getPlatformInfo(const std::string& host,
163                                  const std::string& platformURI,
164                                  OCConnectivityType connectivityType,
165                                  FindPlatformCallback platformInfoHandler,
166                                  QualityOfService QoS)
167         {
168             return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI, connectivityType,
169                                  platformInfoHandler, QoS);
170         }
171
172         OCStackResult registerResource(OCResourceHandle& resourceHandle,
173                                  std::string& resourceURI,
174                                  const std::string& resourceTypeName,
175                                  const std::string& resourceInterface,
176                                  EntityHandler entityHandler,
177                                  uint8_t resourceProperty)
178         {
179             return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
180                                  resourceTypeName, resourceInterface,
181                                  entityHandler, resourceProperty);
182         }
183
184         OCStackResult registerResource(OCResourceHandle& resourceHandle,
185                                  const std::shared_ptr< OCResource > resource)
186         {
187             return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
188         }
189
190         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo)
191         {
192             return OCPlatform_impl::Instance().registerDeviceInfo(deviceInfo);
193         }
194
195         OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo)
196         {
197             return OCPlatform_impl::Instance().registerPlatformInfo(platformInfo);
198         }
199
200         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
201         {
202             return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
203         }
204
205         OCStackResult unbindResource(OCResourceHandle collectionHandle,
206                                  OCResourceHandle resourceHandle)
207         {
208             return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
209         }
210
211         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
212                                  const std::vector<OCResourceHandle>& resourceHandles)
213         {
214             return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
215         }
216
217         OCStackResult bindResource(const OCResourceHandle collectionHandle,
218                                  const OCResourceHandle resourceHandle)
219         {
220             return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
221         }
222
223         OCStackResult bindResources(const OCResourceHandle collectionHandle,
224                                  const std::vector<OCResourceHandle>& resourceHandles
225                                  )
226         {
227             return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
228         }
229
230         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
231                                  const std::string& resourceTypeName)
232         {
233             return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
234         }
235
236         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
237                                  const std::string& resourceInterfaceName)
238         {
239             return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
240                                                              resourceInterfaceName);
241         }
242
243         OCStackResult startPresence(const unsigned int announceDurationSeconds)
244         {
245             return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
246         }
247
248         OCStackResult stopPresence()
249         {
250             return OCPlatform_impl::Instance().stopPresence();
251         }
252
253         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
254                                      const std::string& host,
255                                      OCConnectivityType connectivityType,
256                                      SubscribeCallback presenceHandler)
257         {
258             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
259                                                              connectivityType, presenceHandler);
260         }
261
262         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
263                                      const std::string& host,
264                                      const std::string& resourceType,
265                                      OCConnectivityType connectivityType,
266                                      SubscribeCallback presenceHandler)
267         {
268             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
269                                              resourceType, connectivityType, presenceHandler);
270         }
271
272         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
273         {
274             return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
275         }
276
277 #ifdef WITH_CLOUD
278         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
279                                               const std::string& host,
280                                               const std::vector<std::string>& di,
281                                               OCConnectivityType connectivityType,
282                                               ObserveCallback callback)
283         {
284             return OCPlatform_impl::Instance().subscribeDevicePresence(presenceHandle,
285                                                                        host,
286                                                                        di,
287                                                                        connectivityType,
288                                                                        callback);
289         }
290 #endif
291
292         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
293         {
294             return OCPlatform_impl::Instance().sendResponse(pResponse);
295         }
296
297         OCStackResult findDirectPairingDevices(unsigned short waittime,
298                                          GetDirectPairedCallback directPairingHandler)
299         {
300             return OCPlatform_impl::Instance().findDirectPairingDevices(waittime,
301                                          directPairingHandler);
302         }
303
304         OCStackResult getDirectPairedDevices(GetDirectPairedCallback directPairingHandler)
305         {
306             return OCPlatform_impl::Instance().getDirectPairedDevices(directPairingHandler);
307         }
308
309         OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
310                                  const std::string& pinNumber,
311                                  DirectPairingCallback resultCallback)
312         {
313             return OCPlatform_impl::Instance().doDirectPairing(peer, pmSel,
314                                              pinNumber, resultCallback);
315         }
316 #ifdef WITH_CLOUD
317         OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
318                                                             OCConnectivityType connectivityType)
319         {
320             return OCPlatform_impl::Instance().constructAccountManagerObject(host,
321                                                                              connectivityType);
322         }
323 #endif // WITH_CLOUD
324 #ifdef RD_CLIENT
325         OCStackResult publishResourceToRD(const std::string& host,
326                                           OCConnectivityType connectivityType,
327                                           PublishResourceCallback callback)
328         {
329             ResourceHandles resourceHandles;
330             return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
331                                                                    resourceHandles,
332                                                                    callback);
333         }
334
335         OCStackResult publishResourceToRD(const std::string& host,
336                                           OCConnectivityType connectivityType,
337                                           PublishResourceCallback callback,
338                                           QualityOfService QoS)
339         {
340             ResourceHandles resourceHandles;
341             return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
342                                                                    resourceHandles,
343                                                                    callback, QoS);
344         }
345
346         OCStackResult publishResourceToRD(const std::string& host,
347                                           OCConnectivityType connectivityType,
348                                           ResourceHandles& resourceHandles,
349                                           PublishResourceCallback callback)
350         {
351             return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
352                                                                    resourceHandles,
353                                                                    callback);
354         }
355
356         OCStackResult publishResourceToRD(const std::string& host,
357                                           OCConnectivityType connectivityType,
358                                           ResourceHandles& resourceHandles,
359                                           PublishResourceCallback callback, QualityOfService QoS)
360         {
361             return OCPlatform_impl::Instance().publishResourceToRD(host, connectivityType,
362                                                                    resourceHandles,
363                                                                    callback, QoS);
364         }
365
366         OCStackResult deleteResourceFromRD(const std::string& host,
367                                            OCConnectivityType connectivityType,
368                                            DeleteResourceCallback callback)
369         {
370             ResourceHandles resourceHandles;
371             return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
372                                                                     resourceHandles, callback);
373         }
374
375         OCStackResult deleteResourceFromRD(const std::string& host,
376                                            OCConnectivityType connectivityType,
377                                            DeleteResourceCallback callback,
378                                            QualityOfService QoS)
379         {
380             ResourceHandles resourceHandles;
381             return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
382                                                                     resourceHandles, callback, QoS);
383         }
384
385         OCStackResult deleteResourceFromRD(const std::string& host,
386                                            OCConnectivityType connectivityType,
387                                            ResourceHandles& resourceHandles,
388                                            DeleteResourceCallback callback)
389         {
390             return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
391                                                                     resourceHandles, callback);
392         }
393
394         OCStackResult deleteResourceFromRD(const std::string& host,
395                                            OCConnectivityType connectivityType,
396                                            ResourceHandles& resourceHandles,
397                                            DeleteResourceCallback callback, QualityOfService QoS)
398         {
399             return OCPlatform_impl::Instance().deleteResourceFromRD(host, connectivityType,
400                                                                     resourceHandles, callback,
401                                                                     QoS);
402         }
403 #endif
404         OCStackResult getDeviceId(OCUUIdentity *deviceId)
405         {
406             return OCPlatform_impl::Instance().getDeviceId(deviceId);
407         }
408
409         OCStackResult setDeviceId(const OCUUIdentity *deviceId)
410         {
411             return OCPlatform_impl::Instance().setDeviceId(deviceId);
412         }
413     } // namespace OCPlatform
414 } //namespace OC
415