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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
25 #include "ocstackconfig.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 //TODO: May want to refactor this in upcoming sprints.
36 //Don't want to expose to application layer that lower level stack is using CoAP.
38 /// Authority + URI string to prefix well known queries
39 #define OC_WELL_KNOWN_QUERY "224.0.1.187:5683/oc/core"
40 #define OC_EXPLICIT_DEVICE_DISCOVERY_URI "224.0.1.187:5683/oc/core/d?rt=core.led"
41 /// Multicast address and port string to prefix multicast queries
42 #define OC_MULTICAST_PREFIX "224.0.1.187:5683"
43 /// IP Multicast address to use for multicast requests
44 #define OC_MULTICAST_IP "224.0.1.187"
45 /// IP Multicast port to use for multicast requests
46 #define OC_MULTICAST_PORT 5683
49 #define OC_DEFAULT_PRESENCE_TTL_SECONDS (60)
50 /// OC_MAX_PRESENCE_TTL_SECONDS sets the maximum time to live (TTL) for presence.
51 /// NOTE: Changing the setting to a longer duration may lead to unsupported and untested
53 #define OC_MAX_PRESENCE_TTL_SECONDS (60 * 60 * 24) // 60 sec/min * 60 min/hr * 24 hr/day
54 #define OC_PRESENCE_URI "/oc/presence"
57 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
62 * Data structure to encapsulate IPv4/IPv6/Contiki/lwIP device addresses.
64 typedef struct OCDevAddr
66 uint32_t size; ///< length of the address stored in addr field.
67 uint8_t addr[DEV_ADDR_SIZE_MAX]; ///< device address.
71 * OC Virtual resources supported by every OC device.
75 OC_WELL_KNOWN_URI= 0, ///< "/oc/core"
76 OC_DEVICE_URI, ///< "/oc/core/d"
77 OC_RESOURCE_TYPES_URI, ///< "/oc/core/d/type"
79 OC_PRESENCE, ///< "/oc/presence"
81 OC_MAX_VIRTUAL_RESOURCES ///<s Max items in the list
85 * Standard RESTful HTTP Methods.
90 OC_REST_GET = (1 << 0), ///< Read
91 OC_REST_PUT = (1 << 1), ///< Write
92 OC_REST_POST = (1 << 2), ///< Update
93 OC_REST_DELETE = (1 << 3), ///< Delete
94 /// Register observe request for most up date notifications ONLY.
95 OC_REST_OBSERVE = (1 << 4),
96 /// Register observe request for all notifications, including stale notifications.
97 OC_REST_OBSERVE_ALL = (1 << 5),
98 /// Deregister observation, intended for internal use
99 OC_REST_CANCEL_OBSERVE = (1 << 6),
101 /// Subscribe for all presence notifications of a particular resource.
102 OC_REST_PRESENCE = (1 << 7)
107 * Host Mode of Operation.
117 * Quality of Service.
124 OC_NA_QOS // No Quality is defined, let the stack decide
125 } OCQualityOfService;
128 * Resource Properties.
130 * ::OC_ACTIVE When this bit is set, the resource is initialized, otherwise the resource
131 * is 'inactive'. 'inactive' signifies that the resource has been marked for
132 * deletion or is already deleted.
133 * ::OC_DISCOVERABLE When this bit is set, the resource is allowed to be discovered by clients.
134 * ::OC_OBSERVABLE When this bit is set, the resource is allowed to be observed by clients.
135 * ::OC_SLOW When this bit is set, the resource has been marked as 'slow'. 'slow' signifies
136 * that responses from this resource can expect delays in processing its
137 * requests from clients.
138 * ::OC_SECURE When this bit is set, the resource is a secure resource.
142 OC_ACTIVE = (1 << 0),
143 OC_DISCOVERABLE = (1 << 1),
144 OC_OBSERVABLE = (1 << 2),
147 } OCResourceProperty;
150 * Transport Protocol IDs.
154 OC_INVALID_ID = (1 << 0),
155 OC_COAP_ID = (1 << 1)
156 } OCTransportProtocolID;
167 OC_ALL // Multicast message: send over all the interfaces.
168 } OCConnectivityType;
171 * Declares Stack Results & Errors.
175 /* Success status code - START HERE */
177 OC_STACK_RESOURCE_CREATED,
178 OC_STACK_RESOURCE_DELETED,
180 /* Success status code - END HERE */
181 /* Error status code - START HERE */
182 OC_STACK_INVALID_URI = 20,
183 OC_STACK_INVALID_QUERY,
185 OC_STACK_INVALID_PORT,
186 OC_STACK_INVALID_CALLBACK,
187 OC_STACK_INVALID_METHOD,
188 OC_STACK_INVALID_PARAM,
189 OC_STACK_INVALID_OBSERVE_PARAM,
193 OC_STACK_ADAPTER_NOT_ENABLED,
195 OC_STACK_NO_RESOURCE, /* resource not found */
196 OC_STACK_RESOURCE_ERROR, /* ex: not supported method or interface */
197 OC_STACK_SLOW_RESOURCE,
198 OC_STACK_DUPLICATE_REQUEST,
199 OC_STACK_NO_OBSERVERS, /* resource has no registered observers */
200 OC_STACK_OBSERVER_NOT_FOUND,
201 OC_STACK_VIRTUAL_DO_NOT_HANDLE,
202 OC_STACK_INVALID_OPTION,
203 OC_STACK_MALFORMED_RESPONSE, /* the remote reply contained malformed data */
204 OC_STACK_PERSISTENT_BUFFER_REQUIRED,
205 OC_STACK_INVALID_REQUEST_HANDLE,
206 OC_STACK_INVALID_DEVICE_INFO,
207 OC_STACK_INVALID_JSON,
208 /* NOTE: Insert all new error codes here!*/
210 OC_STACK_PRESENCE_STOPPED = 128,
211 OC_STACK_PRESENCE_TIMEOUT,
212 OC_STACK_PRESENCE_DO_NOT_HANDLE,
215 /* Error status code - END HERE */
219 * Handle to an @ref OCDoResource invocation.
221 typedef void * OCDoHandle;
224 * Handle to an OCResource object owned by the OCStack.
226 typedef void * OCResourceHandle;
228 typedef void * OCRequestHandle;
229 typedef void * OCResponseHandle;
232 * Unique identifier for each observation request. Used when observations are
233 * registered or deregistering. Used by entity handler to signal specific
234 * observers to be notified of resource changes.
235 * There can be maximum of 256 observations per server.
237 typedef uint8_t OCObservationId;
240 * Action associated with observation.
244 OC_OBSERVE_REGISTER = 0,
245 OC_OBSERVE_DEREGISTER = 1,
246 OC_OBSERVE_NO_OPTION = 2
251 // Action associated with observation request
252 OCObserveAction action;
253 // Identifier for observation being registered/deregistered
254 OCObservationId obsId;
258 * Possible returned values from entity handler.
264 OC_EH_RESOURCE_CREATED,
265 OC_EH_RESOURCE_DELETED,
268 OC_EH_RESOURCE_NOT_FOUND
269 } OCEntityHandlerResult;
272 * This structure will be used to define the vendor specific header options to be included
273 * in communication packets.
275 typedef struct OCHeaderOption
277 // The protocol ID this option applies to
278 OCTransportProtocolID protocolID;
279 // The header option ID which will be added to communication packets
282 uint16_t optionLength;
283 // pointer to its data
284 uint8_t optionData[MAX_HEADER_OPTION_DATA_LENGTH];
288 * Incoming requests handled by the server. Requests are passed in as a parameter to the
289 * @ref OCEntityHandler callback API.
290 * @brief The @ref OCEntityHandler callback API must be implemented in the application in order
291 * to receive these requests.
295 // Associated resource
296 OCResourceHandle resource;
297 OCRequestHandle requestHandle;
298 // the REST method retrieved from received request PDU
300 // resource query send by client
302 // Information associated with observation - valid only when OCEntityHandler
303 // flag includes OC_OBSERVE_FLAG
304 OCObservationInfo obsInfo;
305 // An array of the received vendor specific header options
306 uint8_t numRcvdVendorSpecificHeaderOptions;
307 OCHeaderOption * rcvdVendorSpecificHeaderOptions;
308 // reqJSON is retrieved from the payload of the received request PDU
309 char * reqJSONPayload;
310 } OCEntityHandlerRequest;
313 * Response from queries to remote servers. Queries are made by calling the @ref OCDoResource API.
317 /// Address of remote server
319 /// Indicates adaptor type on which the response was received
320 OCConnectivityType connType;
321 /// the is the result of our stack, OCStackResult should contain coap/other error codes;
322 OCStackResult result;
323 /// If associated with observe, this will represent the sequence of notifications from server.
324 uint32_t sequenceNumber;
325 /// resJSONPayload is retrieved from the payload of the received request PDU
326 const char * resJSONPayload;
327 /// An array of the received vendor specific header options
328 uint8_t numRcvdVendorSpecificHeaderOptions;
329 OCHeaderOption rcvdVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
333 * This structure describes the device properties. All non-Null properties will be included
334 * in a device discovery request.
343 char *manufacturerName;
344 char *manufacturerUrl;
346 char *dateOfManufacture;
347 char *platformVersion;
348 char *firmwareVersion;
354 // Request handle is passed to server via the entity handler for each incoming request.
355 // Stack assigns when request is received, server sets to indicate what request response is for
356 OCRequestHandle requestHandle;
357 // New handle for tracking block (or slow) response. Stack assigns, server uses for subsequent calls
358 OCResponseHandle *responseHandle;
360 OCResourceHandle resourceHandle;
361 // Allow the entity handler to pass a result with the response
362 OCEntityHandlerResult ehResult;
363 // this is the pointer to server payload data to be transferred
365 // size of server payload data. I don't think we should rely on null terminated data for size
366 uint16_t payloadSize;
367 // An array of the vendor specific header options the entity handler wishes to use in response
368 uint8_t numSendVendorSpecificHeaderOptions;
369 OCHeaderOption sendVendorSpecificHeaderOptions[MAX_HEADER_OPTIONS];
370 // URI of new resource that entity handler might create
371 char resourceUri[MAX_URI_LENGTH];
372 // Server sets to true for persistent response buffer, false for non-persistent response buffer
373 uint8_t persistentBufferFlag;
374 } OCEntityHandlerResponse;
378 OC_INIT_FLAG = (1 << 0),
379 OC_REQUEST_FLAG = (1 << 1),
380 OC_OBSERVE_FLAG = (1 << 2)
381 } OCEntityHandlerFlag; //entity_handler_flag_t ;
384 * Possible returned values from client application.
388 OC_STACK_DELETE_TRANSACTION = 0,//!< OC_STACK_DELETE_TRANSACTION
389 OC_STACK_KEEP_TRANSACTION //!< OC_STACK_KEEP_TRANSACTION
390 } OCStackApplicationResult;
392 //-----------------------------------------------------------------------------
393 // Callback function definitions
394 //-----------------------------------------------------------------------------
397 * Client applications implement this callback to consume responses received from Servers.
399 typedef OCStackApplicationResult (* OCClientResponseHandler)(void *context, OCDoHandle handle,
400 OCClientResponse * clientResponse);
403 * Client applications using a context pointer implement this callback to delete the
404 * context upon removal of the callback/context pointer from the internal callback-list.
406 typedef void (* OCClientContextDeleter)(void *context);
409 * This info is passed from application to OC Stack when initiating a request to Server.
414 /// The pointer to a function the stack will call to handle the requests
415 OCClientResponseHandler cb;
416 /// A pointer to a function to delete the context when this callback is removed
417 OCClientContextDeleter cd;
421 * Application server implementations must implement this callback to consume requests OTA.
422 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
424 typedef OCEntityHandlerResult (*OCEntityHandler)
425 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest);
428 * Device Entity handler need to use this call back instead of OCEntityHandler.
430 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
431 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri);
433 //-----------------------------------------------------------------------------
434 // Function prototypes
435 //-----------------------------------------------------------------------------
438 * Initialize the OC Stack. Must be called prior to starting the stack.
441 * IP Address of host device. Deprecated parameter.
443 * Port of host device. Deprecated parameter.
445 * Host device is client, server, or client-server.
447 * @return ::OC_STACK_OK on success, some other value upon failure.
449 OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode);
452 * Stop the OC stack. Use for a controlled shutdown.
454 * Note: OCStop() performs operations similar to OCStopPresence(), as well as OCDeleteResource() on
455 * all resources this server is hosting. OCDeleteResource() performs operations similar to
456 * OCNotifyAllObservers() to notify all client observers that the respective resource is being
459 * @return ::OC_STACK_OK on success, some other value upon failure.
461 OCStackResult OCStop();
464 * Called in main loop of OC client or server. Allows low-level processing of
467 * @return ::OC_STACK_OK on success, some other value upon failure.
469 OCStackResult OCProcess();
472 * Discover or Perform requests on a specified resource (specified by that Resource's respective
475 * @param handle @ref OCDoHandle to refer to the request sent out on behalf of
476 * calling this API. This handle can be used to cancel this operation
477 * via the OCCancel API.
478 * Note: This reference is handled internally, and
479 * should not be free'd by the consumer. A NULL handle is permitted
480 * in the event where the caller has no use for the return value.
481 * @param method @ref OCMethod to perform on the resource.
482 * @param requiredUri URI of the resource to interact with.
483 * @param referenceUri URI of the reference resource.
484 * @param request JSON encoded request.
485 * @param conType @ref OCConnectivityType type of connectivity indicating the
486 * interface. Example: ::OC_WIFI, ::OC_ETHERNET, ::OC_ALL.
487 * @param qos Quality of service. Note that if this API is called on a uri with
488 * the well-known multicast IP address, the qos will be forced to
490 * since it is impractical to send other QOS levels on such addresses.
491 * @param cbData Asynchronous callback function that is invoked
492 * by the stack when discovery or resource interaction is complete.
493 * @param options The address of an array containing the vendor specific
494 * header options to be sent with the request.
495 * @param numOptions Number of header options to be included.
497 * Note: Presence subscription amendments (ie. adding additional resource type filters by calling
498 * this API again) require the use of the same base URI as the original request to successfully
499 * amend the presence filters.
501 * @return ::OC_STACK_OK on success, some other value upon failure.
503 OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
504 const char *referenceUri, const char *request, OCConnectivityType conType,
505 OCQualityOfService qos, OCCallbackData *cbData,
506 OCHeaderOption * options, uint8_t numOptions);
509 * Cancel a request associated with a specific @ref OCDoResource invocation.
511 * @param handle - Used to identify a specific OCDoResource invocation.
512 * @param qos - used to specify Quality of Service (read below for more info)
513 * @param options- used to specify vendor specific header options when sending
514 * explicit observe cancellation
515 * @param numOptions- Number of header options to be included
517 * @return ::OC_STACK_OK on success, some other value upon failure.
519 OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption * options,
524 * When operating in @ref OCServer or @ref OCClientServer mode, this API will start sending out
525 * presence notifications to clients via multicast. Once this API has been called with a success,
526 * clients may query for this server's presence and this server's stack will respond via multicast.
528 * Server can call this function when it comes online for the first time, or when it comes back
529 * online from offline mode, or when it re enters network.
531 * @param ttl Time To Live in seconds.
532 * Note: If ttl is '0', then the default stack value will be used (60 Seconds).
534 * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
535 * OC_MAX_PRESENCE_TTL_SECONDS.
537 * @return ::OC_STACK_OK on success, some other value upon failure.
539 OCStackResult OCStartPresence(const uint32_t ttl);
542 * When operating in @ref OCServer or @ref OCClientServer mode, this API will stop sending out
543 * presence notifications to clients via multicast. Once this API has been called with a success,
544 * this server's stack will not respond to clients querying for this server's presence.
546 * Server can call this function when it is terminating, going offline, or when going
549 * @return ::OC_STACK_OK on success, some other value upon failure.
552 OCStackResult OCStopPresence();
557 * Set default device entity handler.
559 * @param entityHandler Entity handler function that is called by ocstack to handle requests for
560 * any undefined resources or default actions.
561 * If NULL is passed it removes the device default entity handler.
563 * @return ::OC_STACK_OK on success, some other value upon failure.
565 OCStackResult OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandler entityHandler);
568 * Set device information.
570 * @param deviceInfo - Structure passed by the server application containing
571 * the device information.
575 * OC_STACK_OK - no errors
576 * OC_STACK_INVALID_PARAM - invalid paramerter
577 * OC_STACK_ERROR - stack process error
579 OCStackResult OCSetDeviceInfo(OCDeviceInfo deviceInfo);
584 * @param handle Pointer to handle to newly created resource. Set by ocstack and
585 * used to refer to resource.
586 * @param resourceTypeName Name of resource type. Example: "core.led".
587 * @param resourceInterfaceName Name of resource interface. Example: "core.rw".
588 * @param uri URI of the resource. Example: "/a/led".
589 * @param entityHandler Entity handler function that is called by ocstack to handle requests, etc.
590 * NULL for default entity handler.
591 * @param resourceProperties Properties supported by resource.
592 * Example: ::OC_DISCOVERABLE|::OC_OBSERVABLE.
594 * @return ::OC_STACK_OK on success, some other value upon failure.
596 OCStackResult OCCreateResource(OCResourceHandle *handle,
597 const char *resourceTypeName,
598 const char *resourceInterfaceName,
600 OCEntityHandler entityHandler,
601 uint8_t resourceProperties);
604 * Create a resource. with host ip address for remote resource.
606 * @param handle Pointer to handle to newly created resource. Set by ocstack.
607 * Used to refer to resource.
608 * @param resourceTypeName Name of resource type. Example: "core.led".
609 * @param resourceInterfaceName Name of resource interface. Example: "core.rw".
610 * @param host HOST address of the remote resource. Example: "coap://xxx.xxx.xxx.xxx:xxxxx".
611 * @param uri URI of the resource. Example: "/a/led".
612 * @param entityHandler Entity handler function that is called by ocstack to handle requests, etc.
613 * NULL for default entity handler.
614 * @param resourceProperties Properties supported by resource.
615 * Example: ::OC_DISCOVERABLE|::OC_OBSERVABLE
617 * @return ::OC_STACK_OK on success, some other value upon failure.
619 OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
620 const char *resourceTypeName,
621 const char *resourceInterfaceName,
624 OCEntityHandler entityHandler,
625 uint8_t resourceProperties);
628 * Add a resource to a collection resource.
630 * @param collectionHandle Handle to the collection resource.
631 * @param resourceHandle Handle to resource to be added to the collection resource.
633 * @return ::OC_STACK_OK on success, some other value upon failure.
635 OCStackResult OCBindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle);
638 * Remove a resource from a collection resource.
640 * @param collectionHandle Handle to the collection resource.
641 * @param resourceHandle Handle to resource to be removed from the collection resource.
643 * @return ::OC_STACK_OK on success, some other value upon failure.
645 OCStackResult OCUnBindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle);
648 * Bind a resourcetype to a resource.
650 * @param handle Handle to the resource.
651 * @param resourceTypeName Name of resource type. Example: "core.led".
653 * @return ::OC_STACK_OK on success, some other value upon failure.
655 OCStackResult OCBindResourceTypeToResource(OCResourceHandle handle,
656 const char *resourceTypeName);
658 * Bind a resource interface to a resource.
660 * @param handle Handle to the resource.
661 * @param resourceInterfaceName Name of resource interface. Example: "core.rw".
663 * @return ::OC_STACK_OK on success, some other value upon failure.
665 OCStackResult OCBindResourceInterfaceToResource(OCResourceHandle handle,
666 const char *resourceInterfaceName);
669 * Bind an entity handler to the resource.
671 * @param handle Handle to the resource that the contained resource is to be bound.
672 * @param entityHandler Entity handler function that is called by ocstack to handle requests, etc.
673 * @return ::OC_STACK_OK on success, some other value upon failure.
675 OCStackResult OCBindResourceHandler(OCResourceHandle handle, OCEntityHandler entityHandler);
678 * Get the number of resources that have been created in the stack.
680 * @param numResources Pointer to count variable.
682 * @return ::OC_STACK_OK on success, some other value upon failure.
684 OCStackResult OCGetNumberOfResources(uint8_t *numResources);
687 * Get a resource handle by index.
689 * @param index Index of resource, 0 to Count - 1.
691 * @return Found resource handle or NULL if not found.
693 OCResourceHandle OCGetResourceHandle(uint8_t index);
696 * Delete resource specified by handle. Deletes resource and all resourcetype and resourceinterface
699 * Note: OCDeleteResource() performs operations similar to OCNotifyAllObservers() to notify all
700 * client observers that "this" resource is being deleted.
702 * @param handle Handle of resource to be deleted.
704 * @return ::OC_STACK_OK on success, some other value upon failure.
706 OCStackResult OCDeleteResource(OCResourceHandle handle);
709 * Get the URI of the resource specified by handle.
711 * @param handle Handle of resource.
712 * @return URI string if resource found or NULL if not found.
714 const char *OCGetResourceUri(OCResourceHandle handle);
717 * Get the properties of the resource specified by handle.
718 * NOTE: that after a resource is created, the OC_ACTIVE property is set
719 * for the resource by the stack.
721 * @param handle Handle of resource.
722 * @return OCResourceProperty Bitmask or -1 if resource is not found.
724 OCResourceProperty OCGetResourceProperties(OCResourceHandle handle);
727 * Get the number of resource types of the resource.
729 * @param handle Handle of resource.
730 * @param numResourceTypes Pointer to count variable.
732 * @return ::OC_STACK_OK on success, some other value upon failure.
734 OCStackResult OCGetNumberOfResourceTypes(OCResourceHandle handle, uint8_t *numResourceTypes);
737 * Get name of resource type of the resource.
739 * @param handle Handle of resource.
740 * @param index Index of resource, 0 to Count - 1.
742 * @return Resource type name if resource found or NULL if resource not found.
744 const char *OCGetResourceTypeName(OCResourceHandle handle, uint8_t index);
747 * Get the number of resource interfaces of the resource.
749 * @param handle Handle of resource.
750 * @param numResourceInterfaces Pointer to count variable.
752 * @return ::OC_STACK_OK on success, some other value upon failure.
754 OCStackResult OCGetNumberOfResourceInterfaces(OCResourceHandle handle,
755 uint8_t *numResourceInterfaces);
758 * Get name of resource interface of the resource.
760 * @param handle Handle of resource.
761 * @param index Index of resource, 0 to Count - 1.
763 * @return Resource interface name if resource found or NULL if resource not found.
765 const char *OCGetResourceInterfaceName(OCResourceHandle handle, uint8_t index);
768 * Get methods of resource interface of the resource.
770 * @param handle Handle of resource.
771 * @param index Index of resource, 0 to Count - 1.
773 * @return Allowed methods if resource found or NULL if resource not found.
775 uint8_t OCGetResourceInterfaceAllowedMethods(OCResourceHandle handle, uint8_t index);
778 * Get resource handle from the collection resource by index.
780 * @param collectionHandle Handle of collection resource.
781 * @param index Index of contained resource, 0 to Count - 1.
783 * @return Handle to contained resource if resource found or NULL if resource not found.
785 OCResourceHandle OCGetResourceHandleFromCollection(OCResourceHandle collectionHandle,
789 * Get the entity handler for a resource.
791 * @param handle Handle of resource.
793 * @return Entity handler if resource found or NULL resource not found.
795 OCEntityHandler OCGetResourceHandler(OCResourceHandle handle);
798 * Notify all registered observers that the resource representation has
799 * changed. If observation includes a query the client is notified only
800 * if the query is valid after the resource representation has changed.
802 * @param handle Handle of resource.
803 * @param qos Desired quality of service for the observation notifications.
805 * @return ::OC_STACK_OK on success, some other value upon failure.
807 OCStackResult OCNotifyAllObservers(OCResourceHandle handle, OCQualityOfService qos);
810 * Notify specific observers with updated value of representation.
811 * Before this API is invoked by entity handler it has finished processing
812 * queries for the associated observers.
814 * @param handle Handle of resource.
815 * @param obsIdList List of observation ids that need to be notified.
816 * @param numberOfIds Number of observation ids included in obsIdList.
817 * @param notificationJSONPayload JSON encoded payload to send in notification.
818 * @param qos Desired quality of service of the observation notifications.
819 * NOTE: The memory for obsIdList and notificationJSONPayload is managed by the
820 * entity invoking the API. The maximum size of the notification is 1015 bytes
821 * for non-Arduino platforms. For Arduino the maximum size is 247 bytes.
823 * @return ::OC_STACK_OK on success, some other value upon failure.
826 OCNotifyListOfObservers (OCResourceHandle handle,
827 OCObservationId *obsIdList,
829 const char *notificationJSONPayload,
830 OCQualityOfService qos);
834 * Send a response to a request.
835 * The response can be a normal, slow, or block (i.e. a response that
836 * is too large to be sent in a single PDU and must span multiple transmissions).
838 * @param response Pointer to structure that contains response parameters.
840 * @return ::OC_STACK_OK on success, some other value upon failure.
842 OCStackResult OCDoResponse(OCEntityHandlerResponse *response);
845 * Cancel a response. Applies to a block response.
847 * @param responseHandle Response handle set by stack in OCServerResponse after
848 * OCDoResponse is called.
850 * @return ::OC_STACK_OK on success, some other value upon failure.
852 OCStackResult OCCancelResponse(OCResponseHandle responseHandle);
857 * This method is used to retrieved the IPv4 address from OCDev address
860 * @param ipAddr OCDevAddr address.
861 * @param a first byte of IPv4 address.
862 * @param b second byte of IPv4 address.
863 * @param c third byte of IPv4 address.
864 * @param d fourth byte of IPv4 address.
865 * @return ::OC_STACK_OK on success, some other value upon failure.
867 int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
868 uint8_t *c, uint8_t *d );
871 * This method is used to retrieve the port number from OCDev address
874 * @param ipAddr OCDevAddr address.
875 * @param port Port number.
876 * @return ::OC_STACK_OK on success, some other value upon failure.
878 int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port);
882 #endif // __cplusplus
884 #endif /* OCSTACK_H_ */