Merge "[CA Integration] Updated C sample apps to accept connectivity type param"...
[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         OCResource::Ptr constructResourceObject(const std::string& host,
123                                                 const std::string& uri,
124                                                 bool isObservable,
125                                                 const std::vector<std::string>& resourceTypes,
126                                                 const std::vector<std::string>& interfaces)
127         {
128             return OCPlatform_impl::Instance().constructResourceObject(host, uri, isObservable,
129                                                 resourceTypes, interfaces);
130         }
131
132         OCStackResult findResource(const std::string& host,
133                                                 const std::string& resourceName,
134                                                 FindCallback resourceHandler)
135         {
136             return OCPlatform_impl::Instance().findResource(host, resourceName, resourceHandler);
137         }
138
139         OCStackResult findResource(const std::string& host,
140                                                 const std::string& resourceName,
141                                                 FindCallback resourceHandler, QualityOfService QoS)
142         {
143             return OCPlatform_impl::Instance().findResource(host, resourceName,
144                                                 resourceHandler, QoS);
145         }
146
147         OCStackResult getDeviceInfo(const std::string& host,
148                                                 const std::string& deviceURI,
149                                                 FindDeviceCallback deviceInfoHandler)
150         {
151             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, deviceInfoHandler);
152         }
153
154         OCStackResult getDeviceInfo(const std::string& host,
155                                                 const std::string& deviceURI,
156                                                 FindDeviceCallback deviceInfoHandler,
157                                                 QualityOfService QoS)
158         {
159             return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
160                     deviceInfoHandler, QoS);
161         }
162 #endif
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 unregisterResource(const OCResourceHandle& resourceHandle)
188         {
189             return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
190         }
191
192         OCStackResult unbindResource(OCResourceHandle collectionHandle,
193                                                 OCResourceHandle resourceHandle)
194         {
195             return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
196         }
197
198         OCStackResult unbindResources(const OCResourceHandle collectionHandle,
199                                                 const std::vector<OCResourceHandle>& resourceHandles
200                                                 )
201         {
202             return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
203         }
204
205         OCStackResult bindResource(const OCResourceHandle collectionHandle,
206                                                 const OCResourceHandle resourceHandle)
207         {
208             return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
209         }
210
211         OCStackResult bindResources(const OCResourceHandle collectionHandle,
212                                                 const std::vector<OCResourceHandle>& resourceHandles
213                                                 )
214         {
215             return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
216         }
217
218         OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
219                                                 const std::string& resourceTypeName)
220         {
221             return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
222         }
223
224         OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
225                                                 const std::string& resourceInterfaceName)
226         {
227             return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
228                                                 resourceInterfaceName);
229         }
230
231         OCStackResult startPresence(const unsigned int announceDurationSeconds)
232         {
233             return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
234         }
235
236         OCStackResult stopPresence()
237         {
238             return OCPlatform_impl::Instance().stopPresence();
239         }
240
241 #ifdef CA_INT
242         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
243                                                 const std::string& host,
244                                                 uint8_t connectivityType,
245                                                 SubscribeCallback presenceHandler)
246         {
247             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
248                                                 connectivityType, presenceHandler);
249         }
250
251         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
252                                                 const std::string& host,
253                                                 const std::string& resourceType,
254                                                 uint8_t connectivityType,
255                                                 SubscribeCallback presenceHandler)
256         {
257             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
258                                                 resourceType, connectivityType, presenceHandler);
259         }
260 #else
261         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
262                                                 const std::string& host,
263                                                 SubscribeCallback presenceHandler)
264         {
265             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
266                                                 presenceHandler);
267         }
268
269         OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
270                                                 const std::string& host,
271                                                 const std::string& resourceType,
272                                                 SubscribeCallback presenceHandler)
273         {
274             return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
275                                                 resourceType, presenceHandler);
276         }
277 #endif
278         OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
279         {
280             return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
281         }
282
283         OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
284         {
285             return OCPlatform_impl::Instance().sendResponse(pResponse);
286         }
287     } // namespace OCPlatform
288 } //namespace OC