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 // 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 OCClientResponseHandler cb;
415 OCClientContextDeleter cd;
419 * Application server implementations must implement this callback to consume requests OTA.
420 * Entity handler callback needs to fill the resPayload of the entityHandlerRequest.
422 typedef OCEntityHandlerResult (*OCEntityHandler)
423 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest);
426 * Device Entity handler need to use this call back instead of OCEntityHandler.
428 typedef OCEntityHandlerResult (*OCDeviceEntityHandler)
429 (OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, char* uri);
431 //-----------------------------------------------------------------------------
432 // Function prototypes
433 //-----------------------------------------------------------------------------
436 * Initialize the OC Stack. Must be called prior to starting the stack.
439 * IP Address of host device. Deprecated parameter.
441 * Port of host device. Deprecated parameter.
443 * Host device is client, server, or client-server.
445 * @return ::OC_STACK_OK on success, some other value upon failure.
447 OCStackResult OCInit(const char *ipAddr, uint16_t port, OCMode mode);
450 * Stop the OC stack. Use for a controlled shutdown.
452 * Note: OCStop() performs operations similar to OCStopPresence(), as well as OCDeleteResource() on
453 * all resources this server is hosting. OCDeleteResource() performs operations similar to
454 * OCNotifyAllObservers() to notify all client observers that the respective resource is being
457 * @return ::OC_STACK_OK on success, some other value upon failure.
459 OCStackResult OCStop();
462 * Called in main loop of OC client or server. Allows low-level processing of
465 * @return ::OC_STACK_OK on success, some other value upon failure.
467 OCStackResult OCProcess();
470 * Discover or Perform requests on a specified resource (specified by that Resource's respective
473 * @param handle @ref OCDoHandle to refer to the request sent out on behalf of
474 * calling this API. This handle can be used to cancel this operation
475 * via the OCCancel API.
476 * Note: This reference is handled internally, and
477 * should not be free'd by the consumer. A NULL handle is permitted
478 * in the event where the caller has no use for the return value.
479 * @param method @ref OCMethod to perform on the resource.
480 * @param requiredUri URI of the resource to interact with.
481 * @param referenceUri URI of the reference resource.
482 * @param request JSON encoded request.
483 * @param conType @ref OCConnectivityType type of connectivity indicating the
484 * interface. Example: ::OC_WIFI, ::OC_ETHERNET, ::OC_ALL.
485 * @param qos Quality of service. Note that if this API is called on a uri with
486 * the well-known multicast IP address, the qos will be forced to
488 * since it is impractical to send other QOS levels on such addresses.
489 * @param cbData Asynchronous callback function that is invoked
490 * by the stack when discovery or resource interaction is complete.
491 * @param options The address of an array containing the vendor specific
492 * header options to be sent with the request.
493 * @param numOptions Number of header options to be included.
495 * Note: Presence subscription amendments (ie. adding additional resource type filters by calling
496 * this API again) require the use of the same base URI as the original request to successfully
497 * amend the presence filters.
499 * @return ::OC_STACK_OK on success, some other value upon failure.
501 OCStackResult OCDoResource(OCDoHandle *handle, OCMethod method, const char *requiredUri,
502 const char *referenceUri, const char *request, OCConnectivityType conType,
503 OCQualityOfService qos, OCCallbackData *cbData,
504 OCHeaderOption * options, uint8_t numOptions);
507 * Cancel a request associated with a specific @ref OCDoResource invocation.
509 * @param handle - Used to identify a specific OCDoResource invocation.
510 * @param qos - used to specify Quality of Service (read below for more info)
511 * @param options- used to specify vendor specific header options when sending
512 * explicit observe cancellation
513 * @param numOptions- Number of header options to be included
515 * @return ::OC_STACK_OK on success, some other value upon failure.
517 OCStackResult OCCancel(OCDoHandle handle, OCQualityOfService qos, OCHeaderOption * options,
522 * When operating in @ref OCServer or @ref OCClientServer mode, this API will start sending out
523 * presence notifications to clients via multicast. Once this API has been called with a success,
524 * clients may query for this server's presence and this server's stack will respond via multicast.
526 * Server can call this function when it comes online for the first time, or when it comes back
527 * online from offline mode, or when it re enters network.
529 * @param ttl Time To Live in seconds.
530 * Note: If ttl is '0', then the default stack value will be used (60 Seconds).
532 * If ttl is greater than OC_MAX_PRESENCE_TTL_SECONDS, then the ttl will be set to
533 * OC_MAX_PRESENCE_TTL_SECONDS.
535 * @return ::OC_STACK_OK on success, some other value upon failure.
537 OCStackResult OCStartPresence(const uint32_t ttl);
540 * When operating in @ref OCServer or @ref OCClientServer mode, this API will stop sending out
541 * presence notifications to clients via multicast. Once this API has been called with a success,
542 * this server's stack will not respond to clients querying for this server's presence.
544 * Server can call this function when it is terminating, going offline, or when going
547 * @return ::OC_STACK_OK on success, some other value upon failure.
550 OCStackResult OCStopPresence();
555 * Set default device entity handler.
557 * @param entityHandler Entity handler function that is called by ocstack to handle requests for
558 * any undefined resources or default actions.
559 * If NULL is passed it removes the device default entity handler.
561 * @return ::OC_STACK_OK on success, some other value upon failure.
563 OCStackResult OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandler entityHandler);
566 * Set device information.
568 * @param deviceInfo - Structure passed by the server application containing
569 * the device information.
573 * OC_STACK_OK - no errors
574 * OC_STACK_INVALID_PARAM - invalid paramerter
575 * OC_STACK_ERROR - stack process error
577 OCStackResult OCSetDeviceInfo(OCDeviceInfo deviceInfo);
582 * @param handle Pointer to handle to newly created resource. Set by ocstack and
583 * used to refer to resource.
584 * @param resourceTypeName Name of resource type. Example: "core.led".
585 * @param resourceInterfaceName Name of resource interface. Example: "core.rw".
586 * @param uri URI of the resource. Example: "/a/led".
587 * @param entityHandler Entity handler function that is called by ocstack to handle requests, etc.
588 * NULL for default entity handler.
589 * @param resourceProperties Properties supported by resource.
590 * Example: ::OC_DISCOVERABLE|::OC_OBSERVABLE.
592 * @return ::OC_STACK_OK on success, some other value upon failure.
594 OCStackResult OCCreateResource(OCResourceHandle *handle,
595 const char *resourceTypeName,
596 const char *resourceInterfaceName,
598 OCEntityHandler entityHandler,
599 uint8_t resourceProperties);
602 * Create a resource. with host ip address for remote resource.
604 * @param handle Pointer to handle to newly created resource. Set by ocstack.
605 * Used to refer to resource.
606 * @param resourceTypeName Name of resource type. Example: "core.led".
607 * @param resourceInterfaceName Name of resource interface. Example: "core.rw".
608 * @param host HOST address of the remote resource. Example: "coap://xxx.xxx.xxx.xxx:xxxxx".
609 * @param uri URI of the resource. Example: "/a/led".
610 * @param entityHandler Entity handler function that is called by ocstack to handle requests, etc.
611 * NULL for default entity handler.
612 * @param resourceProperties Properties supported by resource.
613 * Example: ::OC_DISCOVERABLE|::OC_OBSERVABLE
615 * @return ::OC_STACK_OK on success, some other value upon failure.
617 OCStackResult OCCreateResourceWithHost(OCResourceHandle *handle,
618 const char *resourceTypeName,
619 const char *resourceInterfaceName,
622 OCEntityHandler entityHandler,
623 uint8_t resourceProperties);
626 * Add a resource to a collection resource.
628 * @param collectionHandle Handle to the collection resource.
629 * @param resourceHandle Handle to resource to be added to the collection resource.
631 * @return ::OC_STACK_OK on success, some other value upon failure.
633 OCStackResult OCBindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle);
636 * Remove a resource from a collection resource.
638 * @param collectionHandle Handle to the collection resource.
639 * @param resourceHandle Handle to resource to be removed from the collection resource.
641 * @return ::OC_STACK_OK on success, some other value upon failure.
643 OCStackResult OCUnBindResource(OCResourceHandle collectionHandle, OCResourceHandle resourceHandle);
646 * Bind a resourcetype to a resource.
648 * @param handle Handle to the resource.
649 * @param resourceTypeName Name of resource type. Example: "core.led".
651 * @return ::OC_STACK_OK on success, some other value upon failure.
653 OCStackResult OCBindResourceTypeToResource(OCResourceHandle handle,
654 const char *resourceTypeName);
656 * Bind a resource interface to a resource.
658 * @param handle Handle to the resource.
659 * @param resourceInterfaceName Name of resource interface. Example: "core.rw".
661 * @return ::OC_STACK_OK on success, some other value upon failure.
663 OCStackResult OCBindResourceInterfaceToResource(OCResourceHandle handle,
664 const char *resourceInterfaceName);
667 * Bind an entity handler to the resource.
669 * @param handle Handle to the resource that the contained resource is to be bound.
670 * @param entityHandler Entity handler function that is called by ocstack to handle requests, etc.
671 * @return ::OC_STACK_OK on success, some other value upon failure.
673 OCStackResult OCBindResourceHandler(OCResourceHandle handle, OCEntityHandler entityHandler);
676 * Get the number of resources that have been created in the stack.
678 * @param numResources Pointer to count variable.
680 * @return ::OC_STACK_OK on success, some other value upon failure.
682 OCStackResult OCGetNumberOfResources(uint8_t *numResources);
685 * Get a resource handle by index.
687 * @param index Index of resource, 0 to Count - 1.
689 * @return Found resource handle or NULL if not found.
691 OCResourceHandle OCGetResourceHandle(uint8_t index);
694 * Delete resource specified by handle. Deletes resource and all resourcetype and resourceinterface
697 * Note: OCDeleteResource() performs operations similar to OCNotifyAllObservers() to notify all
698 * client observers that "this" resource is being deleted.
700 * @param handle Handle of resource to be deleted.
702 * @return ::OC_STACK_OK on success, some other value upon failure.
704 OCStackResult OCDeleteResource(OCResourceHandle handle);
707 * Get the URI of the resource specified by handle.
709 * @param handle Handle of resource.
710 * @return URI string if resource found or NULL if not found.
712 const char *OCGetResourceUri(OCResourceHandle handle);
715 * Get the properties of the resource specified by handle.
716 * NOTE: that after a resource is created, the OC_ACTIVE property is set
717 * for the resource by the stack.
719 * @param handle Handle of resource.
720 * @return OCResourceProperty Bitmask or -1 if resource is not found.
722 OCResourceProperty OCGetResourceProperties(OCResourceHandle handle);
725 * Get the number of resource types of the resource.
727 * @param handle Handle of resource.
728 * @param numResourceTypes Pointer to count variable.
730 * @return ::OC_STACK_OK on success, some other value upon failure.
732 OCStackResult OCGetNumberOfResourceTypes(OCResourceHandle handle, uint8_t *numResourceTypes);
735 * Get name of resource type of the resource.
737 * @param handle Handle of resource.
738 * @param index Index of resource, 0 to Count - 1.
740 * @return Resource type name if resource found or NULL if resource not found.
742 const char *OCGetResourceTypeName(OCResourceHandle handle, uint8_t index);
745 * Get the number of resource interfaces of the resource.
747 * @param handle Handle of resource.
748 * @param numResourceInterfaces Pointer to count variable.
750 * @return ::OC_STACK_OK on success, some other value upon failure.
752 OCStackResult OCGetNumberOfResourceInterfaces(OCResourceHandle handle,
753 uint8_t *numResourceInterfaces);
756 * Get name of resource interface of the resource.
758 * @param handle Handle of resource.
759 * @param index Index of resource, 0 to Count - 1.
761 * @return Resource interface name if resource found or NULL if resource not found.
763 const char *OCGetResourceInterfaceName(OCResourceHandle handle, uint8_t index);
766 * Get methods of resource interface of the resource.
768 * @param handle Handle of resource.
769 * @param index Index of resource, 0 to Count - 1.
771 * @return Allowed methods if resource found or NULL if resource not found.
773 uint8_t OCGetResourceInterfaceAllowedMethods(OCResourceHandle handle, uint8_t index);
776 * Get resource handle from the collection resource by index.
778 * @param collectionHandle Handle of collection resource.
779 * @param index Index of contained resource, 0 to Count - 1.
781 * @return Handle to contained resource if resource found or NULL if resource not found.
783 OCResourceHandle OCGetResourceHandleFromCollection(OCResourceHandle collectionHandle,
787 * Get the entity handler for a resource.
789 * @param handle Handle of resource.
791 * @return Entity handler if resource found or NULL resource not found.
793 OCEntityHandler OCGetResourceHandler(OCResourceHandle handle);
796 * Notify all registered observers that the resource representation has
797 * changed. If observation includes a query the client is notified only
798 * if the query is valid after the resource representation has changed.
800 * @param handle Handle of resource.
801 * @param qos Desired quality of service for the observation notifications.
803 * @return ::OC_STACK_OK on success, some other value upon failure.
805 OCStackResult OCNotifyAllObservers(OCResourceHandle handle, OCQualityOfService qos);
808 * Notify specific observers with updated value of representation.
809 * Before this API is invoked by entity handler it has finished processing
810 * queries for the associated observers.
812 * @param handle Handle of resource.
813 * @param obsIdList List of observation ids that need to be notified.
814 * @param numberOfIds Number of observation ids included in obsIdList.
815 * @param notificationJSONPayload JSON encoded payload to send in notification.
816 * @param qos Desired quality of service of the observation notifications.
817 * NOTE: The memory for obsIdList and notificationJSONPayload is managed by the
818 * entity invoking the API. The maximum size of the notification is 1015 bytes
819 * for non-Arduino platforms. For Arduino the maximum size is 247 bytes.
821 * @return ::OC_STACK_OK on success, some other value upon failure.
824 OCNotifyListOfObservers (OCResourceHandle handle,
825 OCObservationId *obsIdList,
827 const char *notificationJSONPayload,
828 OCQualityOfService qos);
832 * Send a response to a request.
833 * The response can be a normal, slow, or block (i.e. a response that
834 * is too large to be sent in a single PDU and must span multiple transmissions).
836 * @param response Pointer to structure that contains response parameters.
838 * @return ::OC_STACK_OK on success, some other value upon failure.
840 OCStackResult OCDoResponse(OCEntityHandlerResponse *response);
843 * Cancel a response. Applies to a block response.
845 * @param responseHandle Response handle set by stack in OCServerResponse after
846 * OCDoResponse is called.
848 * @return ::OC_STACK_OK on success, some other value upon failure.
850 OCStackResult OCCancelResponse(OCResponseHandle responseHandle);
855 * This method is used to retrieved the IPv4 address from OCDev address
858 * @param ipAddr OCDevAddr address.
859 * @param a first byte of IPv4 address.
860 * @param b second byte of IPv4 address.
861 * @param c third byte of IPv4 address.
862 * @param d fourth byte of IPv4 address.
863 * @return ::OC_STACK_OK on success, some other value upon failure.
865 int32_t OCDevAddrToIPv4Addr(OCDevAddr *ipAddr, uint8_t *a, uint8_t *b,
866 uint8_t *c, uint8_t *d );
869 * This method is used to retrieve the port number from OCDev address
872 * @param ipAddr OCDevAddr address.
873 * @param port Port number.
874 * @return ::OC_STACK_OK on success, some other value upon failure.
876 int32_t OCDevAddrToPort(OCDevAddr *ipAddr, uint16_t *port);
880 #endif // __cplusplus
882 #endif /* OCSTACK_H_ */