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