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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
24 * This file contains the declaration of classes and its members related to
28 #ifndef OC_PLATFORM_H_
29 #define OC_PLATFORM_H_
31 #include <OCPlatform_impl.h>
35 * This namespace contains the main entrance/functionality of the product.
36 * It may be used with OC::OCPlatform::functionName. To set a custom configuration,
37 * the implementer must make a call to OCPlatform::Configure before the first usage
38 * of a function in this namespace.
43 * API for overwriting the default configuration of the OCPlatform object.
44 * @note Any calls made to this AFTER the first call to OCPlatform::Instance
47 void Configure(const PlatformConfig& config);
49 // typedef for handle to cancel presence info with
50 typedef OCDoHandle OCPresenceHandle;
53 * API for notifying base that resource's attributes have changed.
55 * @param resourceHandle resource handle of the resource
57 * @return Returns ::OC_STACK_OK if success.
58 * @note This API is for server side only.
59 * @note OCResourceHandle is defined in ocstack.h
60 * @note OCStackResult is defined in ocstack.h.
61 * @see notifyAllObservers(OCResourceHandle, QualityOfService)
63 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
68 * @param resourceHandle resource handle of the resource
69 * @param QoS the quality of communication
70 * @see notifyAllObservers(OCResourceHandle)
72 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
75 * API for notifying only specific clients that resource's attributes have changed.
77 * @param resourceHandle resource handle of the resource
78 * @param observationIds std vector of observationIds. These set of ids are ones which
79 * which will be notified upon resource change.
80 * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
83 * @return Returns ::OC_STACK_OK if success.
84 * @note This API is for server side only.
85 * @note OCResourceHandle is defined in ocstack.h.
86 * @note OCStackResult is defined in ocstack.h.
87 * @see notifyListOfObservers(OCResourceHandle, ObservationIds&, const std::shared_ptr<OCResourceResponse>, QualityOfService)
89 OCStackResult notifyListOfObservers(
90 OCResourceHandle resourceHandle,
91 ObservationIds& observationIds,
92 const std::shared_ptr<OCResourceResponse> responsePtr);
96 * @param resourceHandle resource handle of the resource
97 * @param observationIds std vector of observationIds. These set of ids are ones which
98 * which will be notified upon resource change.
99 * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
101 * @param QoS the quality of communication
102 * @see notifyListOfObservers(OCResourceHandle, ObservationIds&, const std::shared_ptr<OCResourceResponse>)
104 OCStackResult notifyListOfObservers(
105 OCResourceHandle resourceHandle,
106 ObservationIds& observationIds,
107 const std::shared_ptr<OCResourceResponse> responsePtr,
108 QualityOfService QoS);
111 * API for Service and Resource Discovery.
112 * @note This API applies to client side only.
114 * @param host Host IP Address of a service to direct resource discovery query. If null or
115 * empty, performs multicast resource discovery query
116 * @param resourceURI name of the resource. If null or empty, performs search for all
118 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
119 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
120 * @param resourceHandler Handles callbacks, success states and failure states.
122 * Four modes of discovery defined as follows:
123 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
125 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
126 * resource(s) from ALL services.
127 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
128 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
130 * from a particular service.
132 * @return Returns ::OC_STACK_OK if success.
133 * @note First parameter 'host' currently represents an IP address. This will change in
134 * future and will refer to endpoint interface so that we can refer to other transports such
136 * @note OCStackResult is defined in ocstack.h.
137 * @see findResource(const std::string&, const std::string&, OCConnectivityType, FindCallback, QualityOfService)
139 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
140 OCConnectivityType connectivityType, FindCallback resourceHandler);
144 * @param host Host IP Address of a service to direct resource discovery query. If null or
145 * empty, performs multicast resource discovery query
146 * @param resourceURI name of the resource. If null or empty, performs search for all
148 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
149 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
150 * @param resourceHandler Handles callbacks, success states and failure states.
152 * Four modes of discovery defined as follows:
153 * (NULL/Empty, NULL/Empty) - Performs ALL service discovery AND ALL resource
155 * (NULL/Empty, Not Empty) - Performs query for a filtered/scoped/particular
156 * resource(s) from ALL services.
157 * (Not Empty, NULL/Empty) - Performs ALL resource discovery on a particular service.
158 * (Not Empty, Not Empty) - Performs query for a filtered/scoped/particular
160 * from a particular service.
161 * @param QoS QualityOfService the quality of communication
162 * @see findResource(const std::string&, const std::string&, OCConnectivityType, FindCallback)
164 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
165 OCConnectivityType connectivityType, FindCallback resourceHandler,
166 QualityOfService QoS);
169 * API for Device Discovery
172 * @param host Host IP Address. If null or empty, Multicast is performed.
173 * @param deviceURI Uri containing address to the virtual device in C Stack
175 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
176 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
177 * @param deviceInfoHandler device discovery callback
179 * @return Returns ::OC_STACK_OK if success.
180 * @note OCStackResult is defined in ocstack.h.
181 * @see getDeviceInfo(const std::string&, const std::string&, OCConnectivityType, FindDeviceCallback, QualityOfService)
183 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
184 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler);
188 * @param host Host IP Address. If null or empty, Multicast is performed.
189 * @param deviceURI Uri containing address to the virtual device in C Stack
191 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
192 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
193 * @param deviceInfoHandler device discovery callback
194 * @param QoS the quality of communication
195 * @see getDeviceInfo(const std::string&, const std::string&, OCConnectivityType, FindDeviceCallback)
197 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
198 OCConnectivityType connectivityType, FindDeviceCallback deviceInfoHandler,
199 QualityOfService QoS);
202 * API for Platform Discovery
205 * @param host Host IP Address. If null or empty, Multicast is performed.
206 * @param platformURI Uri containing address to the virtual platform in C Stack
208 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
209 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
210 * @param platformInfoHandler platform discovery callback
212 * @return Returns ::OC_STACK_OK if success.
214 * @note OCStackResult is defined in ocstack.h.
215 * @see getPlatformInfo(const std::string&, const std::string&, OCConnectivityType, FindPlatformCallback, QualityOfService)
217 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
218 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler);
222 * @param host Host IP Address. If null or empty, Multicast is performed.
223 * @param platformURI Uri containing address to the virtual platform in C Stack
225 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
226 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
227 * @param platformInfoHandler platform discovery callback
228 * @param QoS the quality of communication
229 * @see getPlatformInfo(const std::string&, const std::string&, OCConnectivityType, FindPlatformCallback)
231 OCStackResult getPlatformInfo(const std::string& host, const std::string& platformURI,
232 OCConnectivityType connectivityType, FindPlatformCallback platformInfoHandler,
233 QualityOfService QoS);
236 * This API registers a resource with the server
237 * @note This API applies to server side only.
239 * @param resourceHandle Upon successful registration, resourceHandle will be filled
240 * @param resourceURI The URI of the resource. Example: "a/light". See NOTE below
241 * @param resourceTypeName The resource type. Example: "light"
242 * @param resourceInterface The resource interface (whether it is collection etc).
243 * @param entityHandler entity handler callback.
244 * @param resourceProperty indicates the property of the resource. Defined in ocstack.h.
245 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
246 * setting resourceProperty as OC_OBSERVABLE will allow observation
247 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
250 * @return Returns ::OC_STACK_OK if success.
251 * @note "a/light" is a relative URI.
252 * Above relative URI will be prepended (by core) with a host IP + namespace "oic"
253 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
254 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
255 * //192.168.1.1/oic/a/light"
256 * First parameter can take a relative URI and core will take care of preparing the fully
258 * first parameter can take fully qualified URI and core will take that as is for further
260 * @note OCStackResult is defined in ocstack.h.
262 OCStackResult registerResource(OCResourceHandle& resourceHandle,
263 std::string& resourceURI,
264 const std::string& resourceTypeName,
265 const std::string& resourceInterface,
266 EntityHandler entityHandler,
267 uint8_t resourceProperty);
270 * This API registers a resource with the server
271 * @note This API applies to server & client side.
273 * @param resourceHandle Upon successful registration, resourceHandle will be filled
274 * @param resource The instance of OCResource that all data filled.
276 * @return Returns ::OC_STACK_OK if success.
277 * @note OCStackResult is defined in ocstack.h.
279 OCStackResult registerResource(OCResourceHandle& resourceHandle,
280 const std::shared_ptr< OCResource > resource);
283 * Register Device Info
285 * @param deviceInfo structure containing all the device specific information
286 * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
288 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
291 * Register Platform Info
293 * @param platformInfo structure containing all the platform specific information
294 * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
296 OCStackResult registerPlatformInfo(const OCPlatformInfo platformInfo);
299 * Set default device entity handler
301 * @param entityHandler entity handler to handle requests for
302 * any undefined resources or default actions.
303 * if NULL is passed it removes the device default entity handler.
304 * @return Returns ::OC_STACK_OK if no errors and ::OC_STACK_ERROR in case of stack process error
306 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
309 * This API unregisters a resource with the server
310 * @note This API applies to server side only.
312 * @param resourceHandle This is the resource handle which we need to unregister from the
315 * @return Returns ::OC_STACK_OK if success.
316 * @note OCStackResult is defined in ocstack.h.
318 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
321 * Add a resource to a collection resource.
323 * @param collectionHandle handle to the collection resource
324 * @param resourceHandle handle to resource to be added to the collection resource
326 * @return Returns ::OC_STACK_OK if success.
327 * @note OCStackResult is defined in ocstack.h.
328 * @note bindResource must be used only after the both collection resource and
329 * resource to add under a collections are created and respective handles obtained
332 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
333 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
334 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
335 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
336 * -# bindResource(homeResourceHandle, kitchenResourceHandle);
338 * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".
340 OCStackResult bindResource(const OCResourceHandle collectionHandle,
341 const OCResourceHandle resourceHandle);
344 * Add multiple resources to a collection resource.
346 * @param collectionHandle handle to the collection resource
347 * @param addedResourceHandleList reference to list of resource handles to be added to the
348 * collection resource
350 * @return Returns ::OC_STACK_OK if success.
351 * @note OCStackResult is defined in ocstack.h.
352 * @note bindResources must be used only after the both collection resource and
353 * list of resources to add under a collection are created and respective handles
357 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
358 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
359 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
360 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
361 * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
362 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
363 * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
364 * rList.push_back(roomResourceHandle);
365 * -# bindResource(homeResourceHandle, rList);
367 * At the end of Step 5, resource "a/home" will contain a references to "a/kitchen" and
370 OCStackResult bindResources(const OCResourceHandle collectionHandle,
371 const std::vector<OCResourceHandle>& addedResourceHandleList);
374 * Unbind a resource from a collection resource.
376 * @param collectionHandle handle to the collection resource
377 * @param resourceHandle resource handle to be unbound from the collection resource
379 * @return Returns ::OC_STACK_OK if success.
380 * @note OCStackResult is defined in ocstack.h.
381 * @note unbindResource must be used only after the both collection resource and
382 * resource to unbind from a collection are created and respective handles obtained
385 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
386 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
387 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
388 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
389 * -# bindResource(homeResourceHandle, kitchenResourceHandle);
390 * -# unbindResource(homeResourceHandle, kitchenResourceHandle);
392 * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen".
394 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
395 const OCResourceHandle resourceHandle);
398 * Unbind resources from a collection resource.
400 * @param collectionHandle handle to the collection resource
401 * @param resourceHandleList List of resource handles to be unbound from the collection
404 * @return Returns ::OC_STACK_OK if success.
405 * @note OCStackResult is defined in ocstack.h.
406 * @note unbindResources must be used only after the both collection resource and
407 * list of resources resource to unbind from a collection are created and respective handles
411 * -# registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
412 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
413 * -# registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
414 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
415 * -# registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
416 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);
417 * -# std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
418 * rList.push_back(roomResourceHandle);
419 * -# bindResource(homeResourceHandle, rList);
420 * -# unbindResources(homeResourceHandle, rList);
422 * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
425 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
426 const std::vector<OCResourceHandle>& resourceHandleList);
429 * Binds a type to a particular resource
430 * @param resourceHandle handle to the resource
431 * @param resourceTypeName new typename to bind to the resource
433 * @return Returns ::OC_STACK_OK if success.
435 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
436 const std::string& resourceTypeName);
439 * Binds an interface to a particular resource
440 * @param resourceHandle handle to the resource
441 * @param resourceInterfaceName new interface to bind to the resource
443 * @return Returns ::OC_STACK_OK if success.
445 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
446 const std::string& resourceInterfaceName);
450 * Start Presence announcements.
452 * @param ttl time to live
454 * If ttl is '0', then the default stack value will be used (60 Seconds).
455 * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
456 * OC_MAX_PRESENCE_TTL_SECONDS.
458 * @return Returns ::OC_STACK_OK if success.
460 * Server can call this function when it comes online for the
461 * first time, or when it comes back online from offline mode,
462 * or when it re enters network.
465 OCStackResult startPresence(const unsigned int ttl);
468 * Stop Presence announcements.
470 * @return Returns ::OC_STACK_OK if success.
472 * Server can call this function when it is terminating,
473 * going offline, or when going away from network.
476 OCStackResult stopPresence();
479 * subscribes to a server's presence change events. By making this subscription,
480 * every time a server adds/removes/alters a resource, starts or is intentionally
481 * stopped (potentially more to be added later).
483 * @param presenceHandle a handle object that can be used to identify this subscription
484 * request. It can be used to unsubscribe from these events in the future.
485 * It will be set upon successful return of this method.
486 * @param host The IP address/addressable name of the server to subscribe to.
487 * This should be in the format coap://address:port
488 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
489 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
490 * @param presenceHandler callback function that will receive notifications/subscription
493 * @return Returns ::OC_STACK_OK if success.
494 * @copydoc subscribePresence(OCPresenceHandle&, const std::string&, resourceType, OCConnectivityType, SubscribeCallback)
496 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
497 OCConnectivityType connectivityType, SubscribeCallback presenceHandler);
501 * @param presenceHandle a handle object that can be used to identify this subscription
502 * request. It can be used to unsubscribe from these events in the future.
503 * It will be set upon successful return of this method.
504 * @param host The IP address/addressable name of the server to subscribe to.
505 * This should be in the format coap://address:port
506 * @param resourceType a resource type specified as a filter for subscription callbacks.
507 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
508 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
509 * @param presenceHandler callback function that will receive notifications/subscription
511 * @see subscribePresence(OCPresenceHandle&, const std::string&, OCConnectivityType, SubscribeCallback)
513 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
514 const std::string& resourceType, OCConnectivityType connectivityType,
515 SubscribeCallback presenceHandler);
518 * unsubscribes from a previously subscribed server's presence events. Note that
519 * you may for a short time still receive events from the server since it may take time
520 * for the unsubscribe to take effect.
522 * @param presenceHandle the handle object provided by the subscribePresence call that
523 * identifies this subscription.
525 * @return Returns ::OC_STACK_OK if success.
527 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
530 * Creates a resource proxy object so that get/put/observe functionality
531 * can be used without discovering the object in advance. Note that the
532 * consumer of this method needs to provide all of the details required to
533 * correctly contact and observe the object. If the consumer lacks any of
534 * this information, they should discover the resource object normally.
535 * Additionally, you can only create this object if OCPlatform was initialized
536 * to be a Client or Client/Server. Otherwise, this will return an empty
539 * @param host a string containing a resolvable host address of the server
540 * holding the resource. Currently this should be in the format
541 * coap://address:port, though in the future, we expect this to
542 * change to //address:port
544 * @param uri the rest of the resource's URI that will permit messages to be
545 * properly routed. Example: /a/light
547 * @param connectivityType ::OCConnectivityType type of connectivity indicating the
548 * interface. Example: OC_WIFI, OC_ETHERNET, OC_ALL
550 * @param isObservable a boolean containing whether the resource supports observation
552 * @param resourceTypes a collection of resource types implemented by the resource
554 * @param interfaces a collection of interfaces that the resource supports/implements
555 * @return OCResource::Ptr a shared pointer to the new resource object
557 OCResource::Ptr constructResourceObject(const std::string& host,
558 const std::string& uri,
559 OCConnectivityType connectivityType, bool isObservable,
560 const std::vector<std::string>& resourceTypes,
561 const std::vector<std::string>& interfaces);
564 * Allows application entity handler to send response to an incoming request.
566 * @param pResponse OCResourceResponse pointer that will permit to set values related
567 * to resource response.
569 * @return Returns ::OC_STACK_OK if success.
571 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
575 #endif // OC_PLATFORM_H_