Merge from master to CA branch
[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 #ifdef CA_INT
74         OCResource::Ptr constructResourceObject(const std::string& host,
75                                                 const std::string& uri, uint8_t 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, uri, connectivityType,
81                                                 isObservable,
82                                                 resourceTypes, interfaces);
83         }
84
85         OCStackResult findResource(const std::string& host,
86                                                 const std::string& resourceName,
87                                                 uint8_t connectivityType,
88                                                 FindCallback resourceHandler)
89         {
90             return OCPlatform_impl::Instance().findResource(host, resourceName,
91                    connectivityType, resourceHandler);
92         }
93
94         OCStackResult findResource(const std::string& host,
95                                                 const std::string& resourceName,
96                                                 uint8_t connectivityType,
97                                                 FindCallback resourceHandler, QualityOfService QoS)
98         {
99             return OCPlatform_impl::Instance().findResource(host, resourceName, connectivityType,
100                                                 resourceHandler, QoS);
101         }
102
103         OCStackResult getDeviceInfo(const std::string& host,
104                                                 const std::string& deviceURI,
105                                                 uint8_t connectivityType,
106                                                 FindDeviceCallback deviceInfoHandler)
107         {
108             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
109                    connectivityType, deviceInfoHandler);
110         }
111
112         OCStackResult getDeviceInfo(const std::string& host,
113                                                 const std::string& deviceURI,
114                                                 uint8_t connectivityType,
115                                                 FindDeviceCallback deviceInfoHandler,
116                                                 QualityOfService QoS)
117         {
118             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
119                     deviceInfoHandler, QoS);
120         }
121 #endif
122
123         OCStackResult findResource(const std::string& host,
124                                                 const std::string& resourceName,
125                                                 FindCallback resourceHandler)
126         {
127 //TODO-CA Revisit this API
128 #ifdef CA_INT
129             return OCPlatform_impl::Instance().findResource(host, resourceName,
130                                                     OC_WIFI | OC_ETHERNET, resourceHandler);
131 #else
132             return OCPlatform_impl::Instance().findResource(host, resourceName, resourceHandler);
133 #endif
134         }
135
136         OCStackResult findResource(const std::string& host,
137                                                 const std::string& resourceName,
138                                                 FindCallback resourceHandler, QualityOfService QoS)
139         {
140 //TODO-CA Revisit this API
141 #ifdef CA_INT
142             return OCPlatform_impl::Instance().findResource(host, resourceName,
143                                                 OC_WIFI | OC_ETHERNET, resourceHandler, QoS);
144 #else
145             return OCPlatform_impl::Instance().findResource(host, resourceName,
146                                                 resourceHandler, QoS);
147 #endif
148         }
149
150         OCResource::Ptr constructResourceObject(const std::string& host,
151                                                 const std::string& uri,
152                                                 bool isObservable,
153                                                 const std::vector<std::string>& resourceTypes,
154                                                 const std::vector<std::string>& interfaces)
155         {
156 //TODO-CA Revisit this API
157 #ifdef CA_INT
158             return OCPlatform_impl::Instance().constructResourceObject(host, uri, isObservable,
159                                                 OC_WIFI | OC_ETHERNET, resourceTypes, interfaces);
160 #else
161             return OCPlatform_impl::Instance().constructResourceObject(host, uri, isObservable,
162                                                 resourceTypes, interfaces);
163 #endif
164         }
165
166         OCStackResult getDeviceInfo(const std::string& host,
167                                                 const std::string& deviceURI,
168                                                 FindDeviceCallback deviceInfoHandler)
169         {
170 #ifdef CA_INT
171             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, OC_WIFI | OC_ETHERNET,
172                                                             deviceInfoHandler);
173 #else
174             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, deviceInfoHandler);
175 #endif
176         }
177
178         OCStackResult getDeviceInfo(const std::string& host,
179                                                 const std::string& deviceURI,
180                                                 FindDeviceCallback deviceInfoHandler,
181                                                 QualityOfService QoS)
182         {
183 #ifdef CA_INT
184             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, OC_WIFI | OC_ETHERNET,
185                                                             deviceInfoHandler, QoS);
186 #else
187             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, deviceInfoHandler, QoS);
188 #endif
189         }
190
191
192         OCStackResult registerResource(OCResourceHandle& resourceHandle,
193                                                 std::string& resourceURI,
194                                                 const std::string& resourceTypeName,
195                                                 const std::string& resourceInterface,
196                                                 EntityHandler entityHandler,
197                                                 uint8_t resourceProperty)
198         {
199             return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
200                                                 resourceTypeName, resourceInterface,
201                                                 entityHandler, resourceProperty);
202         }
203
204         OCStackResult registerResource(OCResourceHandle& resourceHandle,
205                                                 const std::shared_ptr< OCResource > resource)
206         {
207             return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
208         }
209
210         OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo)
211         {
212             return OCPlatform_impl::Instance().registerDeviceInfo(deviceInfo);
213         }
214
215         OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
216         {
217             return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
218         }
219
220         OCStackResult unbindResource(OCResourceHandle collectionHandle,
221                                                 OCResourceHandle resourceHandle)
222         {
223             return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
224         }
225
226         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
227                                                 const std::vector<OCResourceHandle>& resourceHandles
228                                                 )
229         {
230             return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
231         }
232
233         OCStackResult bindResource(const OCResourceHandle collectionHandle,
234                                                 const OCResourceHandle resourceHandle)
235         {
236             return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
237         }
238
239         OCStackResult bindResources(const OCResourceHandle collectionHandle,
240                                                 const std::vector<OCResourceHandle>& resourceHandles
241                                                 )
242         {
243             return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
244         }
245
246         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
247                                                 const std::string& resourceTypeName)
248         {
249             return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
250         }
251
252         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
253                                                 const std::string& resourceInterfaceName)
254         {
255             return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
256                                                 resourceInterfaceName);
257         }
258
259         OCStackResult startPresence(const unsigned int announceDurationSeconds)
260         {
261             return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
262         }
263
264         OCStackResult stopPresence()
265         {
266             return OCPlatform_impl::Instance().stopPresence();
267         }
268
269 #ifdef CA_INT
270         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
271                                                 const std::string& host,
272                                                 uint8_t connectivityType,
273                                                 SubscribeCallback presenceHandler)
274         {
275             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
276                                                 connectivityType, presenceHandler);
277         }
278
279         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
280                                                 const std::string& host,
281                                                 const std::string& resourceType,
282                                                 uint8_t connectivityType,
283                                                 SubscribeCallback presenceHandler)
284         {
285             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
286                                                 resourceType, connectivityType, presenceHandler);
287         }
288 #endif
289         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
290                                                 const std::string& host,
291                                                 SubscribeCallback presenceHandler)
292         {
293 //TODO-CA Revisit this API
294 #ifdef CA_INT
295             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
296                                                 OC_WIFI | OC_ETHERNET, presenceHandler);
297 #else
298             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
299                                                 presenceHandler);
300 #endif
301         }
302
303         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
304                                                 const std::string& host,
305                                                 const std::string& resourceType,
306                                                 SubscribeCallback presenceHandler)
307         {
308 //TODO-CA Revisit this API
309 #ifdef CA_INT
310             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
311                                                 resourceType, OC_WIFI | OC_ETHERNET,
312                                                 presenceHandler);
313 #else
314             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
315                                                 resourceType, presenceHandler);
316 #endif
317         }
318
319         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
320         {
321             return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
322         }
323
324         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
325         {
326             return OCPlatform_impl::Instance().sendResponse(pResponse);
327         }
328     } // namespace OCPlatform
329 } //namespace OC