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 __OCPLATFORM_H
29 #define __OCPLATFORM_H
31 #include <OCPlatform_impl.h>
35 * @brief: 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 OCStackResult return value of this API. 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.
62 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle);
64 * API for notifying base that resource's attributes have changed.
66 * @param resourceHandle resource handle of the resource
67 * @param QoS the quality of communication
69 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
70 * NOTE: This API is for server side only.
71 * NOTE: OCResourceHandle is defined in ocstack.h.
72 * NOTE: OCStackResult is defined in ocstack.h.
74 OCStackResult notifyAllObservers(OCResourceHandle resourceHandle, QualityOfService QoS);
77 * API for notifying only specific clients that resource's attributes have changed.
79 * @param resourceHandle resource handle of the resource
80 * @param observationIds std vector of observationIds. These set of ids are ones which
81 * which will be notified upon resource change.
82 * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
85 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
87 * NOTE: This API is for server side only.
88 * NOTE: OCResourceHandle is defined in ocstack.h.
89 * NOTE: OCStackResult is defined in ocstack.h.
91 OCStackResult notifyListOfObservers(
92 OCResourceHandle resourceHandle,
93 ObservationIds& observationIds,
94 const std::shared_ptr<OCResourceResponse> responsePtr);
96 * API for notifying only specific clients that resource's attributes have changed.
98 * @param resourceHandle resource handle of the resource
99 * @param observationIds std vector of observationIds. These set of ids are ones which
100 * which will be notified upon resource change.
101 * @param responsePtr OCResourceResponse pointer used by app to fill the response for this
103 * @param QoS the quality of communication
105 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
107 * NOTE: This API is for server side only.
108 * NOTE: OCResourceHandle is defined in ocstack.h.
109 * NOTE: OCStackResult is defined in ocstack.h.
111 OCStackResult notifyListOfObservers(
112 OCResourceHandle resourceHandle,
113 ObservationIds& observationIds,
114 const std::shared_ptr<OCResourceResponse> responsePtr,
115 QualityOfService QoS);
118 * API for Service and Resource Discovery.
120 * @note This API applies to client side only.
121 * @note First parameter 'host' currently represents an IP address. This will change in
122 * future and will refer to endpoint interface so that we can refer to other transports such
124 * @note OCStackResult is defined in ocstack.h.
126 * @param host Host IP Address of a service to direct resource discovery query. If null or
127 * empty, performs multicast resource discovery query
128 * @param resourceURI name of the resource. If null or empty, performs search for all
130 * @param resourceHandler Handles callbacks, success states and failure states.
132 * Four modes of discovery defined as follows:
133 * (NULL/Empty, NULL/Empty) Performs ALL service discovery AND ALL resource
135 * (NULL/Empty, Not Empty) Performs query for a filtered/scoped/particular
136 * resource(s) from ALL services.
137 * (Not Empty, NULL/Empty) Performs ALL resource discovery on a particular service.
138 * (Not Empty, Not Empty) Performs query for a filtered/scoped/particular
139 * resource(s) from a particular service.
141 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
143 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
144 FindCallback resourceHandler);
146 * API for Service and Resource Discovery.
148 * @note This API applies to client side only.
149 * @note First parameter 'host' currently represents an IP address. This will change in
150 * future and will refer to endpoint interface so that we can refer to other transports such
152 * @note OCStackResult is defined in ocstack.h.
154 * @param host Host IP Address of a service to direct resource
155 * discovery query. If null or empty, performs multicast resource
157 * @param resourceURI Name of the resource. If null or empty, performs search for all
159 * @param resourceHandler Handles callbacks, success states and failure states.
161 * Four modes of discovery defined as follows:
162 * (NULL/Empty, NULL/Empty) Performs ALL service discovery AND ALL resource
164 * (NULL/Empty, Not Empty) Performs query for a filtered/scoped/particular
165 * resource(s) from ALL services.
166 * (Not Empty, NULL/Empty) Performs ALL resource discovery on a particular service.
167 * (Not Empty, Not Empty) Performs query for a filtered/scoped/particular
168 * resource(s) from a particular service.
169 * @param QoS The quality of communication
171 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
173 OCStackResult findResource(const std::string& host, const std::string& resourceURI,
174 FindCallback resourceHandler, QualityOfService QoS);
177 * API for Device Discovery
180 * @param host Host IP Address. If null or empty, Multicast is performed.
181 * @param deviceURI Uri containing address to the virtual device in C Stack
183 * @param deviceInfoHandler A callback function to receive the results of
187 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
188 FindDeviceCallback deviceInfoHandler);
190 * API for Device Discovery
193 * @param host Host IP Address. If null or empty, Multicast is performed.
194 * @param deviceURI Uri containing address to the virtual device in C Stack
196 * @param deviceInfoHandler A callback function to receive the results of
198 * @param QoS The quality of communication
201 OCStackResult getDeviceInfo(const std::string& host, const std::string& deviceURI,
202 FindDeviceCallback deviceInfoHandler, QualityOfService QoS);
205 * This API registers a resource with the server
206 * NOTE: This API applies to server side only.
208 * @param resourceHandle - Upon successful registration, resourceHandle will be filled
209 * @param resourceURI - The URI of the resource. Example: "a/light". See NOTE below
210 * @param resourceTypeName - The resource type. Example: "light"
211 * @param resourceInterface - The resource interface (whether it is collection etc).
212 * @param entityHandler - entity handler callback.
213 * @param resourceProperty - indicates the property of the resource. Defined in ocstack.h.
214 * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource
215 * setting resourceProperty as OC_OBSERVABLE will allow observation
216 * settings resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and
219 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
220 * NOTE: "a/light" is a relative URI.
221 * Above relative URI will be prepended (by core) with a host IP + namespace "oc"
222 * Therefore, fully qualified URI format would be //HostIP-Address/namespace/relativeURI"
223 * Example, a relative URI: 'a/light' will result in a fully qualified URI:
224 * //192.168.1.1/oc/a/light"
225 * First parameter can take a relative URI and core will take care of preparing the fully
227 * first paramter can take fully qualified URI and core will take that as is for further
229 * NOTE: OCStackResult is defined in ocstack.h.
231 OCStackResult registerResource(OCResourceHandle& resourceHandle,
232 std::string& resourceURI,
233 const std::string& resourceTypeName,
234 const std::string& resourceInterface,
235 EntityHandler entityHandler,
236 uint8_t resourceProperty);
239 * This API registers a resource with the server
240 * NOTE: This API applies to server & client side.
242 * @param resourceHandle Upon successful registration, resourceHandle will be filled
243 * @param resource The instance of OCResource that all data filled.
245 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
248 OCStackResult registerResource(OCResourceHandle& resourceHandle,
249 const std::shared_ptr< OCResource > resource);
252 * Register Device Info
254 * @param deviceInfo - structure containing all the device specific information
257 * OC_STACK_OK - no errors
258 * OC_STACK_ERROR - stack process error
261 OCStackResult registerDeviceInfo(const OCDeviceInfo deviceInfo);
264 * Set default device entity handler
266 * @param entityHandler - entity handler to handle requests for
267 * any undefined resources or default actions.
268 * if NULL is passed it removes the device default entity handler.
271 * OC_STACK_OK - no errors
272 * OC_STACK_ERROR - stack process error
274 OCStackResult setDefaultDeviceEntityHandler(EntityHandler entityHandler);
277 * This API unregisters a resource with the server
278 * NOTE: This API applies to server side only.
280 * @param resourceHandle - This is the resource handle which we which to unregister from the
283 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.
284 * NOTE: OCStackResult is defined in ocstack.h.
286 OCStackResult unregisterResource(const OCResourceHandle& resourceHandle);
289 * Add a resource to a collection resource.
291 * bindResource() must be used only after the both collection resource and
292 * resource to add under a collections are created and respective handles obtained<br>
293 * <b>Example:</b> <br>
294 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
295 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
296 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
297 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
298 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
299 * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
301 * @param collectionHandle Handle to the collection resource
302 * @param resourceHandle Handle to resource to be added to the collection resource
304 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success.<br>
305 * @note OCStackResult is defined in ocstack.h. <br>
307 OCStackResult bindResource(const OCResourceHandle collectionHandle,
308 const OCResourceHandle resourceHandle);
311 * Add multiple resources to a collection resource.
313 * bindResources() must be used only after the both collection resource and
314 * resource to add under a collections are created and respective handles obtained<br>
315 * <b>Example:</b> <br>
316 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
317 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
318 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
319 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
320 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
321 * At the end of Step 3, resource "a/home" will contain a reference to "a/kitchen".<br>
323 * @param collectionHandle Handle to the collection resource
324 * @param addedResourceHandleList Reference to list of resource handles to be added to the
325 * collection resource
327 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
328 * @note OCStackResult is defined in ocstack.h. <br>
330 OCStackResult bindResources(const OCResourceHandle collectionHandle,
331 const std::vector<OCResourceHandle>& addedResourceHandleList);
334 * Unbind a resource from a collection resource.
336 * @param collectionHandle - handle to the collection resource
337 * @param resourceHandle resource handle to be unbound from the collection resource
339 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
340 * NOTE: OCStackResult is defined in ocstack.h.<br>
341 * NOTE: unbindResource must be used only after the both collection resource and
342 * resource to unbind from a collection are created and respective handles obtained<br>
343 * <b> Example </b> <br>
344 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
345 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
346 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
347 * entityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
348 * Step 3: bindResource(homeResourceHandle, kitchenResourceHandle);<br>
349 * Step 4: unbindResource(homeResourceHandle, kitchenResourceHandle);<br>
350 * At the end of Step 4, resource "a/home" will no longer reference "a/kitchen". <br>
352 OCStackResult unbindResource(const OCResourceHandle collectionHandle,
353 const OCResourceHandle resourceHandle);
356 * Unbind resources from a collection resource.
358 * @param collectionHandle - handle to the collection resource
359 * @param resourceHandleList List of resource handles to be unbound from the collection
362 * @return OCStackResult return value of this API. Returns OC_STACK_OK if success. <br>
364 * NOTE: OCStackResult is defined in ocstack.h.<br>
365 * NOTE: unbindResources must be used only after the both collection resource and
366 * list of resources resource to unbind from a collection are created and respective handles
368 * <b>Example</b> <br>
369 * Step 1: registerResource(homeResourceHandle, "a/home", "home", Link_Interface,
370 * homeEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
371 * Step 2: registerResource(kitchenResourceHandle, "a/kitchen", "kitchen", Link_Interface,
372 * kitchenEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
373 * Step 3: registerResource(roomResourceHandle, "a/room", "room", Link_Interface,
374 * roomEntityHandler, OC_DISCOVERABLE | OC_OBSERVABLE);<br>
375 * Step 4: std::vector<OCResourceHandle> rList; rList.push_back(kitchenResourceHandle);
376 * rList.push_back(roomResourceHandle);<br>
377 * Step 5: bindResource(homeResourceHandle, rList);<br>
378 * Step 6: unbindResources(homeResourceHandle, rList);<br>
379 * At the end of Step 6, resource "a/home" will no longer reference to "a/kitchen" and
382 OCStackResult unbindResources(const OCResourceHandle collectionHandle,
383 const std::vector<OCResourceHandle>& resourceHandleList);
386 * Binds a type to a particular resource
387 * @param resourceHandle - handle to the resource
388 * @param resourceTypeName - new typename to bind to the resource
390 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
392 OCStackResult bindTypeToResource(const OCResourceHandle& resourceHandle,
393 const std::string& resourceTypeName);
396 * Binds an interface to a particular resource
398 * @param resourceHandle Handle to the resource
399 * @param resourceInterfaceName New interface to bind to the resource
401 * @return OCStackResult return value of the API. Returns OCSTACK_OK if success <br>
403 OCStackResult bindInterfaceToResource(const OCResourceHandle& resourceHandle,
404 const std::string& resourceInterfaceName);
408 * Start Presence announcements.
410 * @param ttl - time to live
411 * @return OCStackResult - Returns OCSTACK_OK if success <br>
413 * Server can call this function when it comes online for the
414 * first time, or when it comes back online from offline mode,
415 * or when it re enters network.
419 OCStackResult startPresence(const unsigned int ttl);
422 * Stop Presence announcements.
424 * @return OCStackResult - Returns OCSTACK_OK if success <br>
426 * Server can call this function when it is terminating,
427 * going offline, or when going away from network.
431 OCStackResult stopPresence();
434 * subscribes to a server's presence change events. By making this subscription,
435 * every time a server adds/removes/alters a resource, starts or is intentionally
436 * stopped (potentially more to be added later).
438 * @param presenceHandle A handle object that can be used to identify this subscription
439 * request. It can be used to unsubscribe from these events in the future.
440 * It will be set upon successful return of this method.
441 * @param host The IP address/addressable name of the server to subscribe to.
442 * @param presenceHandler Callback function that will receive notifications/subscription
445 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if successful
447 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
448 SubscribeCallback presenceHandler);
450 * subscribes to a server's presence change events. By making this subscription,
451 * every time a server adds/removes/alters a resource, starts or is intentionally
452 * stopped (potentially more to be added later).
454 * @param presenceHandle A handle object that can be used to identify this subscription
455 * request. It can be used to unsubscribe from these events in the future.
456 * It will be set upon successful return of this method.
457 * @param host The IP address/addressable name of the server to subscribe to.
458 * @param resourceType A resource type specified as a filter for subscription callbacks.
459 * @param presenceHandler Callback function that will receive notifications/subscription
462 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
464 OCStackResult subscribePresence(OCPresenceHandle& presenceHandle, const std::string& host,
465 const std::string& resourceType, SubscribeCallback presenceHandler);
468 * unsubscribes from a previously subscribed server's presence events. Note that
469 * you may for a short time still receive events from the server since it may take time
470 * for the unsubscribe to take effect.
472 * @param presenceHandle - the handle object provided by the subscribePresence call that
473 * identifies this subscription.
475 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
477 OCStackResult unsubscribePresence(OCPresenceHandle presenceHandle);
480 * Creates a resource proxy object so that get/put/observe functionality
481 * can be used without discovering the object in advance. Note that the
482 * consumer of this method needs to provide all of the details required to
483 * correctly contact and observe the object. If the consumer lacks any of
484 * this information, they should discover the resource object normally.
485 * Additionally, you can only create this object if OCPlatform was initialized
486 * to be a Client or Client/Server. Otherwise, this will return an empty
489 * @param host - a string containing a resolvable host address of the server
490 * holding the resource. Currently this should be in the format
491 * coap://address:port, though in the future, we expect this to
492 * change to //address:port
494 * @param uri - the rest of the resource's URI that will permit messages to be
495 * properly routed. Example: /a/light
497 * @param isObservable - a boolean containing whether the resource supports observation
499 * @param resourceTypes - a collection of resource types implemented by the resource
501 * @param interfaces - a collection of interfaces that the resource supports/implements
502 * @return OCResource::Ptr - a shared pointer to the new resource object
504 OCResource::Ptr constructResourceObject(const std::string& host, const std::string& uri,
505 bool isObservable, const std::vector<std::string>& resourceTypes,
506 const std::vector<std::string>& interfaces);
509 * Allows application entity handler to send response to an incoming request.
511 * @param pResponse - OCResourceResponse pointer that will permit to set values related
512 * to resource response. <br>
513 * @return OCStackResult - return value of the API. Returns OCSTACK_OK if success <br>
515 OCStackResult sendResponse(const std::shared_ptr<OCResourceResponse> pResponse);
519 #endif //__OCPLATFORM_H