Replace select with poll.
[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         OCStackResult Configure(const PlatformConfig& config)
36         {
37             return OCPlatform_impl::Configure(config);
38         }
39
40         OCStackResult start()
41         {
42             return OCPlatform_impl::Instance().start();
43         }
44
45         OCStackResult stop()
46         {
47             return OCPlatform_impl::Instance().stop();
48         }
49
50         OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler)
51         {
52             return OCPlatform_impl::Instance().setDefaultDeviceEntityHandler(entityHandler);
53         }
54
55         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle,
56                                      QualityOfService QoS)
57         {
58             return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle, QoS);
59         }
60
61         OCStackResult notifyAllObservers(OCResourceHandle resourceHandle)
62         {
63             return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle);
64         }
65
66         OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
67                                      ObservationIds& observationIds,
68                                      const std::shared_ptr<OCResourceResponse> pResponse)
69         {
70             return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
71                                      observationIds, pResponse);
72         }
73
74         OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
75                                      ObservationIds& observationIds,
76                                      const std::shared_ptr<OCResourceResponse> pResponse,
77                                      QualityOfService QoS)
78         {
79             return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
80                                      observationIds, pResponse, QoS);
81         }
82
83         OCResource::Ptr constructResourceObject(const std::string& host,
84                                      const std::string& uri,
85                                      OCConnectivityType connectivityType,
86                                      bool isObservable,
87                                      const std::vector<std::string>& resourceTypes,
88                                      const std::vector<std::string>& interfaces)
89         {
90             return OCPlatform_impl::Instance().constructResourceObject(host,
91                                      uri, connectivityType,
92                                      isObservable,
93                                      resourceTypes, interfaces);
94         }
95
96         OCStackResult findResource(const std::string& host,
97                                  const std::string& resourceName,
98                                  OCConnectivityType connectivityType,
99                                  FindCallback resourceHandler)
100         {
101             return OCPlatform_impl::Instance().findResource(host, resourceName,
102                                  connectivityType, resourceHandler);
103         }
104
105         OCStackResult findResource(const std::string& host,
106                                  const std::string& resourceName,
107                                  OCConnectivityType connectivityType,
108                                  FindCallback resourceHandler,
109                                  QualityOfService QoS)
110         {
111             return OCPlatform_impl::Instance().findResource(host, resourceName,
112                                  connectivityType, resourceHandler, QoS);
113         }
114
115         OCStackResult findResource(const std::string& host,
116                                             const std::string& resourceName,
117                                             OCConnectivityType connectivityType,
118                                             FindCallback resourceHandler,
119                                             FindErrorCallback errorHandler)
120         {
121             return OCPlatform_impl::Instance().findResource(host, resourceName,
122                                     connectivityType, resourceHandler, errorHandler);
123         }
124
125         OCStackResult findResource(const std::string& host,
126                                             const std::string& resourceName,
127                                             OCConnectivityType connectivityType,
128                                             FindCallback resourceHandler,
129                                             FindErrorCallback errorHandler,
130                                             QualityOfService QoS)
131         {
132             return OCPlatform_impl::Instance().findResource(host, resourceName,
133                                     connectivityType, resourceHandler, errorHandler, QoS);
134         }
135
136         OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
137                     OCConnectivityType connectivityType, FindResListCallback resourceHandler,
138                     QualityOfService QoS)
139         {
140             return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
141                                     connectivityType, resourceHandler, QoS);
142         }
143
144         OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
145                     OCConnectivityType connectivityType, FindResListCallback resourceHandler,
146                     FindErrorCallback errorHandler, QualityOfService QoS)
147         {
148             return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
149                                     connectivityType, resourceHandler, errorHandler, QoS);
150         }
151
152         OCStackResult getDeviceInfo(const std::string& host,
153                                  const std::string& deviceURI,
154                                  OCConnectivityType connectivityType,
155                                  FindDeviceCallback deviceInfoHandler)
156         {
157             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
158                                  connectivityType, deviceInfoHandler);
159         }
160
161         OCStackResult getDeviceInfo(const std::string& host,
162                                  const std::string& deviceURI,
163                                  OCConnectivityType connectivityType,
164                                  FindDeviceCallback deviceInfoHandler,
165                                  QualityOfService QoS)
166         {
167             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
168                                  deviceInfoHandler, QoS);
169         }
170
171         OCStackResult getPlatformInfo(const std::string& host,
172                                  const std::string& platformURI,
173                                  OCConnectivityType connectivityType,
174                                  FindPlatformCallback platformInfoHandler)
175         {
176             return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI,
177                                  connectivityType, platformInfoHandler);
178         }
179
180         OCStackResult getPlatformInfo(const std::string& host,
181                                  const std::string& platformURI,
182                                  OCConnectivityType connectivityType,
183                                  FindPlatformCallback platformInfoHandler,
184                                  QualityOfService QoS)
185         {
186             return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI, connectivityType,
187                                  platformInfoHandler, QoS);
188         }
189
190         OCStackResult registerResource(OCResourceHandle& resourceHandle,
191                                  std::string& resourceURI,
192                                  const std::string& resourceTypeName,
193                                  const std::string& resourceInterface,
194                                  EntityHandler entityHandler,
195                                  uint8_t resourceProperty)
196         {
197             return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
198                                  resourceTypeName, resourceInterface,
199                                  entityHandler, resourceProperty);
200         }
201
202         OCStackResult registerResource(OCResourceHandle& resourceHandle,
203                                  const std::shared_ptr< OCResource > resource)
204         {
205             return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
206         }
207
208         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo)
209         {
210             return OCPlatform_impl::Instance().registerDeviceInfo(deviceInfo);
211         }
212
213         OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo)
214         {
215             return OCPlatform_impl::Instance().registerPlatformInfo(platformInfo);
216         }
217
218         OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value)
219         {
220             return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
221         }
222
223         OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value)
224         {
225             return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
226         }
227
228         OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value)
229         {
230             return OCPlatform_impl::Instance().getPropertyValue(type, tag, value);
231         }
232
233         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
234         {
235             return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
236         }
237
238         OCStackResult unbindResource(OCResourceHandle collectionHandle,
239                                  OCResourceHandle resourceHandle)
240         {
241             return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
242         }
243
244         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
245                                  const std::vector<OCResourceHandle>& resourceHandles)
246         {
247             return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
248         }
249
250         OCStackResult bindResource(const OCResourceHandle collectionHandle,
251                                  const OCResourceHandle resourceHandle)
252         {
253             return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
254         }
255
256         OCStackResult bindResources(const OCResourceHandle collectionHandle,
257                                  const std::vector<OCResourceHandle>& resourceHandles
258                                  )
259         {
260             return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
261         }
262
263         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
264                                  const std::string& resourceTypeName)
265         {
266             return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
267         }
268
269         OCStackResult resetResourceTypes(const OCResourceHandle& resourceHandle,
270                                          const std::string& newResourceType)
271         {
272             return OCPlatform_impl::Instance().resetResourceTypes(resourceHandle,newResourceType);
273         }
274
275         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
276                                  const std::string& resourceInterfaceName)
277         {
278             return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
279                                                              resourceInterfaceName);
280         }
281
282         OCStackResult resetResourceInterfaces(const OCResourceHandle& resourceHandle,
283                                               const std::string& newResourceInterface)
284         {
285             return OCPlatform_impl::Instance().resetResourceInterfaces(resourceHandle,
286                                                              newResourceInterface);
287         }
288
289         OCStackResult startPresence(const unsigned int announceDurationSeconds)
290         {
291             return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
292         }
293
294         OCStackResult stopPresence()
295         {
296             return OCPlatform_impl::Instance().stopPresence();
297         }
298
299         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
300                                      const std::string& host,
301                                      OCConnectivityType connectivityType,
302                                      SubscribeCallback presenceHandler)
303         {
304             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
305                                                              connectivityType, presenceHandler);
306         }
307
308         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
309                                      const std::string& host,
310                                      const std::string& resourceType,
311                                      OCConnectivityType connectivityType,
312                                      SubscribeCallback presenceHandler)
313         {
314             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
315                                              resourceType, connectivityType, presenceHandler);
316         }
317
318         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
319         {
320             return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
321         }
322
323 #ifdef WITH_CLOUD
324         OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
325                                               const std::string& host,
326                                               const std::vector<std::string>& di,
327                                               OCConnectivityType connectivityType,
328                                               ObserveCallback callback)
329         {
330             return OCPlatform_impl::Instance().subscribeDevicePresence(presenceHandle,
331                                                                        host,
332                                                                        di,
333                                                                        connectivityType,
334                                                                        callback);
335         }
336 #endif
337
338         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
339         {
340             return OCPlatform_impl::Instance().sendResponse(pResponse);
341         }
342
343         OCStackResult findDirectPairingDevices(unsigned short waittime,
344                                          GetDirectPairedCallback directPairingHandler)
345         {
346             return OCPlatform_impl::Instance().findDirectPairingDevices(waittime,
347                                          directPairingHandler);
348         }
349
350         OCStackResult getDirectPairedDevices(GetDirectPairedCallback directPairingHandler)
351         {
352             return OCPlatform_impl::Instance().getDirectPairedDevices(directPairingHandler);
353         }
354
355         OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
356                                  const std::string& pinNumber,
357                                  DirectPairingCallback resultCallback)
358         {
359             return OCPlatform_impl::Instance().doDirectPairing(peer, pmSel,
360                                              pinNumber, resultCallback);
361         }
362 #ifdef WITH_CLOUD
363         OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
364                                                             OCConnectivityType connectivityType)
365         {
366             return OCPlatform_impl::Instance().constructAccountManagerObject(host,
367                                                                              connectivityType);
368         }
369 #endif // WITH_CLOUD
370 #ifdef TCP_ADAPTER
371         OCStackResult findKeepAliveResource(std::string host, KeepAliveCallback resultCallback)
372         {
373             return OCPlatform_impl::Instance().findKeepAliveResource(host, resultCallback);
374         }
375
376         OCStackResult sendKeepAliveRequest(std::string host, const OCRepresentation& rep,
377                                                              KeepAliveCallback pingHandler)
378         {
379             return OCPlatform_impl::Instance().sendKeepAliveRequest(host, rep, pingHandler);
380         }
381 #endif
382
383         OCStackResult getDeviceId(OCUUIdentity *deviceId)
384         {
385             return OCPlatform_impl::Instance().getDeviceId(deviceId);
386         }
387
388         OCStackResult setDeviceId(const OCUUIdentity *deviceId)
389         {
390             return OCPlatform_impl::Instance().setDeviceId(deviceId);
391         }
392     } // namespace OCPlatform
393 } //namespace OC