1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 //******************************************************************
25 // Description: Implementation of the OCPlatform.
29 //*********************************************************************
30 #include <OCPlatform.h>
35 OCStackResult Configure(const PlatformConfig& config)
37 return OCPlatform_impl::Configure(config);
42 return OCPlatform_impl::Instance().start();
47 return OCPlatform_impl::Instance().stop();
50 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler)
52 return OCPlatform_impl::Instance().setDefaultDeviceEntityHandler(entityHandler);
55 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle,
58 return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle, QoS);
61 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle)
63 return OCPlatform_impl::Instance().notifyAllObservers(resourceHandle);
66 OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
67 ObservationIds& observationIds,
68 const std::shared_ptr<OCResourceResponse> pResponse)
70 return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
71 observationIds, pResponse);
74 OCStackResult notifyListOfObservers(OCResourceHandle resourceHandle,
75 ObservationIds& observationIds,
76 const std::shared_ptr<OCResourceResponse> pResponse,
79 return OCPlatform_impl::Instance().notifyListOfObservers(resourceHandle,
80 observationIds, pResponse, QoS);
83 OCResource::Ptr constructResourceObject(const std::string& host,
84 const std::string& uri,
85 OCConnectivityType connectivityType,
87 const std::vector<std::string>& resourceTypes,
88 const std::vector<std::string>& interfaces)
90 return OCPlatform_impl::Instance().constructResourceObject(host,
91 uri, connectivityType,
93 resourceTypes, interfaces);
96 OCStackResult findResource(const std::string& host,
97 const std::string& resourceName,
98 OCConnectivityType connectivityType,
99 FindCallback resourceHandler)
101 return OCPlatform_impl::Instance().findResource(host, resourceName,
102 connectivityType, resourceHandler);
105 OCStackResult findResource(const std::string& host,
106 const std::string& resourceName,
107 OCConnectivityType connectivityType,
108 FindCallback resourceHandler,
109 QualityOfService QoS)
111 return OCPlatform_impl::Instance().findResource(host, resourceName,
112 connectivityType, resourceHandler, QoS);
115 OCStackResult findResource(const std::string& host,
116 const std::string& resourceName,
117 OCConnectivityType connectivityType,
118 FindCallback resourceHandler,
119 FindErrorCallback errorHandler)
121 return OCPlatform_impl::Instance().findResource(host, resourceName,
122 connectivityType, resourceHandler, errorHandler);
125 OCStackResult findResource(const std::string& host,
126 const std::string& resourceName,
127 OCConnectivityType connectivityType,
128 FindCallback resourceHandler,
129 FindErrorCallback errorHandler,
130 QualityOfService QoS)
132 return OCPlatform_impl::Instance().findResource(host, resourceName,
133 connectivityType, resourceHandler, errorHandler, QoS);
136 OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
137 OCConnectivityType connectivityType, FindResListCallback resourceHandler,
138 QualityOfService QoS)
140 return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
141 connectivityType, resourceHandler, QoS);
144 OCStackResult findResourceList(const std::string& host, const std::string& resourceURI,
145 OCConnectivityType connectivityType, FindResListCallback resourceHandler,
146 FindErrorCallback errorHandler, QualityOfService QoS)
148 return OCPlatform_impl::Instance().findResourceList(host, resourceURI,
149 connectivityType, resourceHandler, errorHandler, QoS);
152 OCStackResult getDeviceInfo(const std::string& host,
153 const std::string& deviceURI,
154 OCConnectivityType connectivityType,
155 FindDeviceCallback deviceInfoHandler)
157 return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI,
158 connectivityType, deviceInfoHandler);
161 OCStackResult getDeviceInfo(const std::string& host,
162 const std::string& deviceURI,
163 OCConnectivityType connectivityType,
164 FindDeviceCallback deviceInfoHandler,
165 QualityOfService QoS)
167 return OCPlatform_impl::Instance().getDeviceInfo(host, deviceURI, connectivityType,
168 deviceInfoHandler, QoS);
171 OCStackResult getPlatformInfo(const std::string& host,
172 const std::string& platformURI,
173 OCConnectivityType connectivityType,
174 FindPlatformCallback platformInfoHandler)
176 return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI,
177 connectivityType, platformInfoHandler);
180 OCStackResult getPlatformInfo(const std::string& host,
181 const std::string& platformURI,
182 OCConnectivityType connectivityType,
183 FindPlatformCallback platformInfoHandler,
184 QualityOfService QoS)
186 return OCPlatform_impl::Instance().getPlatformInfo(host, platformURI, connectivityType,
187 platformInfoHandler, QoS);
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)
197 return OCPlatform_impl::Instance().registerResource(resourceHandle, resourceURI,
198 resourceTypeName, resourceInterface,
199 entityHandler, resourceProperty);
202 OCStackResult registerResource(OCResourceHandle& resourceHandle,
203 const std::shared_ptr< OCResource > resource)
205 return OCPlatform_impl::Instance().registerResource(resourceHandle, resource);
208 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo)
210 return OCPlatform_impl::Instance().registerDeviceInfo(deviceInfo);
213 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo)
215 return OCPlatform_impl::Instance().registerPlatformInfo(platformInfo);
218 OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::string& value)
220 return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
223 OCStackResult setPropertyValue(OCPayloadType type, const std::string& tag, const std::vector<std::string>& value)
225 return OCPlatform_impl::Instance().setPropertyValue(type, tag, value);
228 OCStackResult getPropertyValue(OCPayloadType type, const std::string& tag, std::string& value)
230 return OCPlatform_impl::Instance().getPropertyValue(type, tag, value);
233 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle)
235 return OCPlatform_impl::Instance().unregisterResource(resourceHandle);
238 OCStackResult unbindResource(OCResourceHandle collectionHandle,
239 OCResourceHandle resourceHandle)
241 return OCPlatform_impl::Instance().unbindResource(collectionHandle, resourceHandle);
244 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
245 const std::vector<OCResourceHandle>& resourceHandles)
247 return OCPlatform_impl::Instance().unbindResources(collectionHandle, resourceHandles);
250 OCStackResult bindResource(const OCResourceHandle collectionHandle,
251 const OCResourceHandle resourceHandle)
253 return OCPlatform_impl::Instance().bindResource(collectionHandle, resourceHandle);
256 OCStackResult bindResources(const OCResourceHandle collectionHandle,
257 const std::vector<OCResourceHandle>& resourceHandles
260 return OCPlatform_impl::Instance().bindResources(collectionHandle, resourceHandles);
263 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
264 const std::string& resourceTypeName)
266 return OCPlatform_impl::Instance().bindTypeToResource(resourceHandle,resourceTypeName);
269 OCStackResult resetResourceTypes(const OCResourceHandle& resourceHandle,
270 const std::string& newResourceType)
272 return OCPlatform_impl::Instance().resetResourceTypes(resourceHandle,newResourceType);
275 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
276 const std::string& resourceInterfaceName)
278 return OCPlatform_impl::Instance().bindInterfaceToResource(resourceHandle,
279 resourceInterfaceName);
282 OCStackResult resetResourceInterfaces(const OCResourceHandle& resourceHandle,
283 const std::string& newResourceInterface)
285 return OCPlatform_impl::Instance().resetResourceInterfaces(resourceHandle,
286 newResourceInterface);
289 OCStackResult startPresence(const unsigned int announceDurationSeconds)
291 return OCPlatform_impl::Instance().startPresence(announceDurationSeconds);
294 OCStackResult stopPresence()
296 return OCPlatform_impl::Instance().stopPresence();
299 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
300 const std::string& host,
301 OCConnectivityType connectivityType,
302 SubscribeCallback presenceHandler)
304 return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
305 connectivityType, presenceHandler);
308 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle,
309 const std::string& host,
310 const std::string& resourceType,
311 OCConnectivityType connectivityType,
312 SubscribeCallback presenceHandler)
314 return OCPlatform_impl::Instance().subscribePresence(presenceHandle, host,
315 resourceType, connectivityType, presenceHandler);
318 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle)
320 return OCPlatform_impl::Instance().unsubscribePresence(presenceHandle);
324 OCStackResult subscribeDevicePresence(OCPresenceHandle& presenceHandle,
325 const std::string& host,
326 const std::vector<std::string>& di,
327 OCConnectivityType connectivityType,
328 ObserveCallback callback)
330 return OCPlatform_impl::Instance().subscribeDevicePresence(presenceHandle,
338 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse)
340 return OCPlatform_impl::Instance().sendResponse(pResponse);
343 OCStackResult findDirectPairingDevices(unsigned short waittime,
344 GetDirectPairedCallback directPairingHandler)
346 return OCPlatform_impl::Instance().findDirectPairingDevices(waittime,
347 directPairingHandler);
350 OCStackResult getDirectPairedDevices(GetDirectPairedCallback directPairingHandler)
352 return OCPlatform_impl::Instance().getDirectPairedDevices(directPairingHandler);
355 OCStackResult doDirectPairing(std::shared_ptr<OCDirectPairing> peer, OCPrm_t pmSel,
356 const std::string& pinNumber,
357 DirectPairingCallback resultCallback)
359 return OCPlatform_impl::Instance().doDirectPairing(peer, pmSel,
360 pinNumber, resultCallback);
363 OCAccountManager::Ptr constructAccountManagerObject(const std::string& host,
364 OCConnectivityType connectivityType)
366 return OCPlatform_impl::Instance().constructAccountManagerObject(host,
371 OCStackResult findKeepAliveResource(std::string host, KeepAliveCallback resultCallback)
373 return OCPlatform_impl::Instance().findKeepAliveResource(host, resultCallback);
376 OCStackResult sendKeepAliveRequest(std::string host, const OCRepresentation& rep,
377 KeepAliveCallback pingHandler)
379 return OCPlatform_impl::Instance().sendKeepAliveRequest(host, rep, pingHandler);
383 OCStackResult getDeviceId(OCUUIdentity *deviceId)
385 return OCPlatform_impl::Instance().getDeviceId(deviceId);
388 OCStackResult setDeviceId(const OCUUIdentity *deviceId)
390 return OCPlatform_impl::Instance().setDeviceId(deviceId);
392 } // namespace OCPlatform