IoTivity-Lite
Server side

Optional group of functions OCF server support. More...

Modules

 Collection Support
 Optional group of functions to support OCF compliant collections.
 

Typedefs

typedef void(* oc_con_write_cb_t) (size_t device_index, oc_rep_t *rep)
 Callback for change notifications from the oic.wk.con resource. More...
 
typedef void(* oc_send_response_cb_t) (oc_request_t *request, oc_status_t response_code)
 Callback function is triggered by oc_send_response before the response is set. More...
 

Functions

OC_API bool oc_add_resource (oc_resource_t *resource)
 Add a resource to the IoTivity stack. More...
 
OC_API void oc_delayed_delete_resource (oc_resource_t *resource)
 Schedule a callback to remove a resource. More...
 
OC_API bool oc_delete_resource (oc_resource_t *resource)
 Remove a resource from the IoTivity stack and delete the resource. More...
 
OC_API void oc_device_bind_resource_type (size_t device, const char *type)
 Add a Resource Type "rt" property to the an /oic/d resource. More...
 
OC_API bool oc_get_diagnostic_message (const oc_client_response_t *response, const char **msg, size_t *size)
 retrieve the diagnostic payload from a response More...
 
OC_API int oc_get_query_value (const oc_request_t *request, const char *key, const char **value)
 Get a pointer to the start of the value in a URL query parameter key=value pair. More...
 
OC_API bool oc_get_request_payload_raw (const oc_request_t *request, const uint8_t **payload, size_t *size, oc_content_format_t *content_format)
 retrieve the payload from the request, no processing More...
 
OC_API bool oc_get_response_payload_raw (const oc_client_response_t *response, const uint8_t **payload, size_t *size, oc_content_format_t *content_format)
 retrieve the response payload, without processing More...
 
OC_API void oc_ignore_request (oc_request_t *request)
 Ignore the request. More...
 
OC_API void oc_indicate_separate_response (oc_request_t *request, oc_separate_response_t *response)
 Respond to an incoming request asynchronously. More...
 
OC_API void oc_init_query_iterator (void)
 This resets the query iterator to the start of the URI query parameter. More...
 
OC_API int oc_iterate_query (const oc_request_t *request, const char **key, size_t *key_len, const char **value, size_t *value_len)
 Iterate through the URI query parameters and get each key=value pair. More...
 
OC_API bool oc_iterate_query_get_values (const oc_request_t *request, const char *key, const char **value, int *value_len)
 Iterate though the URI query parameters for a specific key. More...
 
OC_API oc_resource_toc_new_resource (const char *name, const char *uri, uint8_t num_resource_types, size_t device) OC_NONNULL(2)
 Allocate and populate a new oc_resource_t. More...
 
OC_API int oc_notify_observers (oc_resource_t *resource)
 Notify all observers of a change to a given resource's property. More...
 
OC_API void oc_notify_observers_delayed (oc_resource_t *resource, uint16_t seconds)
 Schedule notify all observers to invoke after a set number of seconds. More...
 
OC_API void oc_notify_observers_delayed_ms (oc_resource_t *resource, uint16_t milliseconds)
 Schedule notify all observers to invoke after a set number of milliseconds. More...
 
OC_API void oc_process_baseline_interface (const oc_resource_t *resource)
 Helper function used when responding to a GET request to add Common Properties to a GET response. More...
 
OC_API int oc_query_value_exists (const oc_request_t *request, const char *key)
 Checks if a query parameter 'key' exist in the URL query parameter. More...
 
OC_API void oc_resource_bind_resource_interface (oc_resource_t *resource, oc_interface_mask_t iface_mask)
 Add the supported interface(s) to the resource. More...
 
OC_API void oc_resource_bind_resource_type (oc_resource_t *resource, const char *type)
 Add a Resource Type "rt" property to the resource. More...
 
OC_API void oc_resource_make_public (oc_resource_t *resource)
 Expose unsecured coap:// endpoints (in addition to secured coaps:// endpoints) for this resource in /oic/res. More...
 
OC_API void oc_resource_set_default_interface (oc_resource_t *resource, oc_interface_mask_t iface_mask)
 Select the default interface. More...
 
OC_API void oc_resource_set_discoverable (oc_resource_t *resource, bool state)
 Specify if a resource can be found using OCF discover mechanisms. More...
 
OC_API void oc_resource_set_observable (oc_resource_t *resource, bool state)
 Specify that a resource should notify clients when a property has been modified. More...
 
OC_API void oc_resource_set_periodic_observable (oc_resource_t *resource, uint16_t seconds)
 The resource will periodically notify observing clients of is property values. More...
 
OC_API void oc_resource_set_pushable (oc_resource_t *resource, bool state)
 Specify if a resource can be pushable. More...
 
OC_API void oc_resource_set_request_handler (oc_resource_t *resource, oc_method_t method, oc_request_callback_t callback, void *user_data)
 Specify a request_callback for GET, PUT, POST, and DELETE methods. More...
 
OC_API void oc_resource_tag_func_desc (oc_resource_t *resource, oc_enum_t func)
 Sets the tag value for the relatvie position "tag_func_rel" tag. More...
 
OC_API void oc_resource_tag_locn (oc_resource_t *resource, oc_locn_t locn)
 sets the value of the "tag_locn" tag More...
 
OC_API void oc_resource_tag_pos_desc (oc_resource_t *resource, oc_pos_description_t pos)
 Sets the tag value for tag "tag-pos-desc" on the resource. More...
 
OC_API void oc_resource_tag_pos_rel (oc_resource_t *resource, double x, double y, double z)
 Sets the value for the relative position "tag-pos-rel" tag. More...
 
OC_API void oc_send_diagnostic_message (oc_request_t *request, const char *msg, size_t msg_len, oc_status_t response_code)
 send a diagnostic payload More...
 
OC_API void oc_send_response (oc_request_t *request, oc_status_t response_code)
 Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More...
 
OC_API void oc_send_response_raw (oc_request_t *request, const uint8_t *payload, size_t size, oc_content_format_t content_format, oc_status_t response_code)
 send the request, no processing More...
 
OC_API void oc_send_response_with_callback (oc_request_t *request, oc_status_t response_code, bool trigger_cb)
 Called after the response to a GET, PUT, POST or DELETE call has been prepared completed. More...
 
OC_API void oc_send_separate_response (oc_separate_response_t *handle, oc_status_t response_code)
 Called to send the deferred response to a GET, PUT, POST or DELETE request. More...
 
OC_API void oc_set_con_write_cb (oc_con_write_cb_t callback)
 Sets the callback to receive change notifications for the oic.wk.con resource. More...
 
OC_API void oc_set_send_response_callback (oc_send_response_cb_t cb)
 Set the send response callback function. More...
 
OC_API void oc_set_separate_response_buffer (oc_separate_response_t *handle)
 Set a response buffer for holding the response payload. More...
 

Detailed Description

Optional group of functions OCF server support.

Typedef Documentation

◆ oc_con_write_cb_t

typedef void(* oc_con_write_cb_t) (size_t device_index, oc_rep_t *rep)

Callback for change notifications from the oic.wk.con resource.

This callback is invoked to notify a change of one or more properties on the oic.wk.con resource. The rep parameter contains all properties, the function is not invoked for each property.

When the function is invoked, all properties handled by the stack are already updated. The callee can use the invocation to optionally store the new values persistently.

Once the callback returns, the response will be sent to the client and observers will be notified.

Note
As of now only the attribute "n" is supported.
The callee shall not block for too long as the stack is blocked during the invocation.
Parameters
device_indexindex of the device to which the change was applied, 0 is the first device
replist of properties and their new values

◆ oc_send_response_cb_t

typedef void(* oc_send_response_cb_t) (oc_request_t *request, oc_status_t response_code)

Callback function is triggered by oc_send_response before the response is set.

In this callback, the application can set/override the response payload.

Note
For separate message, pong message, and notification, this callback is not triggered.
Parameters
requestthe request being responded to
response_codethe status of the response

Function Documentation

◆ oc_add_resource()

OC_API bool oc_add_resource ( oc_resource_t resource)

Add a resource to the IoTivity stack.

The resource will be validated then added to the stack.

Parameters
[in]resourcethe resource to add to the stack
Returns
  • true: the resource was successfully added to the stack.
  • false: the resource can not be added to the stack.

◆ oc_delayed_delete_resource()

OC_API void oc_delayed_delete_resource ( oc_resource_t resource)

Schedule a callback to remove a resource.

Parameters
[in]resourcethe resource to delete

◆ oc_delete_resource()

OC_API bool oc_delete_resource ( oc_resource_t resource)

Remove a resource from the IoTivity stack and delete the resource.

Any resource observers will automatically be removed.

This will free the memory associated with the resource.

Parameters
[in]resourcethe resource to delete
Returns
  • true: when the resource has been deleted and memory freed.
  • false: there was an issue deleting the resource.

◆ oc_device_bind_resource_type()

OC_API void oc_device_bind_resource_type ( size_t  device,
const char *  type 
)

Add a Resource Type "rt" property to the an /oic/d resource.

This function can be used to bind a new Resource Type to a logical device's /oic/d resource.

Parameters
[in]deviceindex of a logical device
[in]typethe Resource type to add to the Resource Type "rt" property (cannot be NULL)

◆ oc_get_diagnostic_message()

OC_API bool oc_get_diagnostic_message ( const oc_client_response_t response,
const char **  msg,
size_t *  size 
)

retrieve the diagnostic payload from a response

Parameters
responsethe response to get the diagnostic payload from
msgthe diagnotic payload
sizethe size of the diagnostic payload
Returns
true - retrieved payload
false

◆ oc_get_query_value()

OC_API int oc_get_query_value ( const oc_request_t request,
const char *  key,
const char **  value 
)

Get a pointer to the start of the value in a URL query parameter key=value pair.

Note
The char pointer returned is pointing to the string location in the query string. Do not rely on a nul terminator to find the end of the string since there may be additional query parameters.
Parameters
[in]requestthe oc_request_t that contains the query parameters
[in]keythe key being searched for
[out]valuepointer to the value string assigned to the key
Returns
  • The position in the query string of the next key=value string pair
  • -1 if there are no additional query parameters

◆ oc_get_request_payload_raw()

OC_API bool oc_get_request_payload_raw ( const oc_request_t request,
const uint8_t **  payload,
size_t *  size,
oc_content_format_t content_format 
)

retrieve the payload from the request, no processing

Parameters
requestthe request
payloadthe payload of the request
sizethe size in bytes of the payload
content_formatthe content format of the payload
Returns
true
false

◆ oc_get_response_payload_raw()

OC_API bool oc_get_response_payload_raw ( const oc_client_response_t response,
const uint8_t **  payload,
size_t *  size,
oc_content_format_t content_format 
)

retrieve the response payload, without processing

Parameters
responsethe response
payloadthe payload of the response
sizethe size of the payload
content_formatthe content format of the payload
Returns
true - retrieved payload
false

◆ oc_ignore_request()

OC_API void oc_ignore_request ( oc_request_t request)

Ignore the request.

The GET, PUT, POST or DELETE requests can be ignored. For example a oc_request_callback_t may only want to respond to multicast requests. Thus any request that is not over multicast endpoint could be ignored.

Using oc_ignore(request) is preferred over oc_send_response(request, OC_IGNORE) since it does not attempt to fill the response buffer before sending the response.

Parameters
[in]requestthe request being responded to
See also
oc_request_callback_t
oc_send_response

◆ oc_indicate_separate_response()

OC_API void oc_indicate_separate_response ( oc_request_t request,
oc_separate_response_t response 
)

Respond to an incoming request asynchronously.

If for some reason the response to a request would take a long time or is not immediately available, then this function may be used defer responding to the request.

Example:

static oc_separate_response_t sep_response;
static oc_event_callback_retval_t
handle_separate_response(void *data)
{
if (sep_response.active) {
printf("Handle separate response for GET handler:\n");
oc_rep_set_boolean(root, value, true);
oc_rep_set_int(root, dimmingSetting, 75);
}
return OC_EVENT_DONE;
}
static void
get_handler(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data)
{
printf("GET handler:\n");
oc_indicate_separate_response(request, &sep_response);
oc_set_delayed_callback(NULL, &handle_separate_response, 10);
}
OC_API void oc_set_delayed_callback(void *cb_data, oc_trigger_t callback, uint16_t seconds)
Schedule a callback to be invoked after a set number of seconds.
OC_API void oc_send_separate_response(oc_separate_response_t *handle, oc_status_t response_code)
Called to send the deferred response to a GET, PUT, POST or DELETE request.
OC_API void oc_indicate_separate_response(oc_request_t *request, oc_separate_response_t *response)
Respond to an incoming request asynchronously.
OC_API void oc_set_separate_response_buffer(oc_separate_response_t *handle)
Set a response buffer for holding the response payload.
#define oc_rep_start_root_object()
This macro has been replaced with oc_rep_begin_root_object.
Definition: oc_rep.h:557
#define oc_rep_set_boolean(object, key, value)
Add an boolean value to the cbor object under the key name Example:
Definition: oc_rep.h:383
#define oc_rep_end_root_object()
End the root object.
Definition: oc_rep.h:574
#define oc_rep_set_int(object, key, value)
Add an integer value to the cbor object under the key name Example:
Definition: oc_rep.h:331
@ OC_STATUS_OK
OK.
Definition: oc_ri.h:76
oc_interface_mask_t
interface masks
Definition: oc_ri.h:189
struct oc_separate_response_s oc_separate_response_t
seperate response type
Definition: oc_ri.h:167
request information structure
Definition: oc_ri.h:255
Parameters
[in]requestthe request that will be responded to as a separate response
[in]responseinstance of an internal struct that is used to track the state of the separate response.
See also
oc_set_separate_response_buffer
oc_send_separate_response

◆ oc_init_query_iterator()

OC_API void oc_init_query_iterator ( void  )

This resets the query iterator to the start of the URI query parameter.

This is used together with oc_iterate_query_get_values() or oc_iterate_query() to iterate through query parameter of a URI that are part of an oc_request_t

◆ oc_iterate_query()

OC_API int oc_iterate_query ( const oc_request_t request,
const char **  key,
size_t *  key_len,
const char **  value,
size_t *  value_len 
)

Iterate through the URI query parameters and get each key=value pair.

Before calling oc_iterate_query() the first time oc_init_query_iterator() must be called to reset the query iterator to the first query parameter.

Note
the char pointers returned are pointing to the string location in the query string. Do not rely on a nul terminator to find the end of the string since there may be additional query parameters.

Example:

char *value = NULL;
int value_len = -1;
char *key
while (oc_iterate_query(request, &key, &key_len, &value, &value_len) > 0) {
printf("%.*s = %.*s\n", key_len, key, query_value_len, query_value);
}
OC_API void oc_init_query_iterator(void)
This resets the query iterator to the start of the URI query parameter.
OC_API int oc_iterate_query(const oc_request_t *request, const char **key, size_t *key_len, const char **value, size_t *value_len)
Iterate through the URI query parameters and get each key=value pair.
Parameters
[in]requestthe oc_request_t that contains the query parameters
[out]keypointer to the location of the the key of the key=value pair
[out]key_lenthe length of the key string
[out]valuepointer the location of the value string assigned to the key=value pair
[out]value_lenthe length of the value string
Returns
  • The position in the query string of the next key=value string pair
  • -1 if there are no additional query parameters

◆ oc_iterate_query_get_values()

OC_API bool oc_iterate_query_get_values ( const oc_request_t request,
const char *  key,
const char **  value,
int *  value_len 
)

Iterate though the URI query parameters for a specific key.

Before calling oc_iterate_query_get_values() the first time oc_init_query_iterator() must be called to reset the query iterator to the first query parameter.

Note
The char pointer returned is pointing to the string location in the query string. Do not rely on a nul terminator to find the end of the string since there may be additional query parameters.

Example:

bool more_query_params = false;
const char* expected_value = "world"
char *value = NULL;
int value_len = -1;
do {
more_query_params = oc_iterate_query_get_values(request, "hello",
&value, &value_len);
if (rt_len > 0) {
printf("Found %s = %.*s\n", "hello", value_len, value);
}
} while (more_query_params);
OC_API bool oc_iterate_query_get_values(const oc_request_t *request, const char *key, const char **value, int *value_len)
Iterate though the URI query parameters for a specific key.
Parameters
[in]requestthe oc_request_t that contains the query parameters (cannot be NULL)
[in]keythe key being searched for (cannot be NULL)
[out]valuepointer to the value string for to the key=value pair (cannot be NULL)
[out]value_lenthe length of the value string (cannot be NULL)
Returns
True if there are more query parameters to iterate through

◆ oc_new_resource()

OC_API oc_resource_t* oc_new_resource ( const char *  name,
const char *  uri,
uint8_t  num_resource_types,
size_t  device 
)

Allocate and populate a new oc_resource_t.

Resources are the primary interface between code and real world devices.

Each resource has a Uniform Resource Identifier (URI) that identifies it. All resources must specify one or more Resource Types to be considered a valid resource. The number of Resource Types is specified by the num_resource_types the actual Resource Types are added later using the oc_resource_bind_resource_type() function.

The resource is populated with a default interface OC_IF_BASELINE.

Many properties associated with a resource are set or modified after the new resource has been created.

The resource is not added to the device till oc_add_resource() is called.

Example:

static void register_resources(void)
{
oc_resource_t *bswitch = oc_new_resource("light switch", "/switch", 1, 0);
oc_resource_bind_resource_type(bswitch, "oic.r.switch.binary");
oc_resource_set_request_handler(bswitch, OC_GET, get_switch, NULL);
oc_resource_set_request_handler(bswitch, OC_POST, post_switch, NULL);
oc_resource_set_request_handler(bswitch, OC_PUT, put_switch, NULL);
oc_add_resource(bswitch);
}
OC_API void oc_resource_set_observable(oc_resource_t *resource, bool state)
Specify that a resource should notify clients when a property has been modified.
OC_API bool oc_add_resource(oc_resource_t *resource)
Add a resource to the IoTivity stack.
OC_API void oc_resource_set_default_interface(oc_resource_t *resource, oc_interface_mask_t iface_mask)
Select the default interface.
OC_API void oc_resource_bind_resource_interface(oc_resource_t *resource, oc_interface_mask_t iface_mask)
Add the supported interface(s) to the resource.
OC_API oc_resource_t * oc_new_resource(const char *name, const char *uri, uint8_t num_resource_types, size_t device) OC_NONNULL(2)
Allocate and populate a new oc_resource_t.
OC_API void oc_resource_bind_resource_type(oc_resource_t *resource, const char *type)
Add a Resource Type "rt" property to the resource.
OC_API void oc_resource_set_discoverable(oc_resource_t *resource, bool state)
Specify if a resource can be found using OCF discover mechanisms.
OC_API void oc_resource_set_request_handler(oc_resource_t *resource, oc_method_t method, oc_request_callback_t callback, void *user_data)
Specify a request_callback for GET, PUT, POST, and DELETE methods.
@ OC_POST
POST.
Definition: oc_ri.h:46
@ OC_PUT
PUT.
Definition: oc_ri.h:47
@ OC_GET
GET.
Definition: oc_ri.h:45
@ OC_IF_A
oic.if.a
Definition: oc_ri.h:195
resource structure
Definition: oc_ri.h:333
Parameters
[in]namethe name of the new resource this will set the property n
[in]urithe Uniform Resource Identifier for the resource (cannot be NULL)
[in]num_resource_typesthe number of Resource Types that will be added/bound to the resource
[in]deviceindex of the logical device the resource will be added to
See also
oc_resource_bind_resource_interface
oc_resource_set_default_interface
oc_resource_bind_resource_type
oc_process_baseline_interface
oc_resource_set_discoverable
oc_resource_set_periodic_observable
oc_resource_set_request_handler

◆ oc_notify_observers()

OC_API int oc_notify_observers ( oc_resource_t resource)

Notify all observers of a change to a given resource's property.

Note
no need to call oc_notify_observers about resource changes that result from a PUT, or POST oc_request_callback_t.
Parameters
[in]resourcethe oc_resource_t that has a modified property
Returns
  • the number observers notified on success
  • 0 on failure could also mean no registered observers

◆ oc_notify_observers_delayed()

OC_API void oc_notify_observers_delayed ( oc_resource_t resource,
uint16_t  seconds 
)

Schedule notify all observers to invoke after a set number of seconds.

Note
no need to call oc_notify_observers about resource changes that result from a PUT, or POST oc_request_callback_t.
Parameters
[in]resourcethe oc_resource_t that has a modified property
[in]secondsthe number of seconds to wait till the callback is invoked

◆ oc_notify_observers_delayed_ms()

OC_API void oc_notify_observers_delayed_ms ( oc_resource_t resource,
uint16_t  milliseconds 
)

Schedule notify all observers to invoke after a set number of milliseconds.

Note
no need to call oc_notify_observers about resource changes that result from a PUT, or POST oc_request_callback_t.
Parameters
[in]resourcethe oc_resource_t that has a modified property
[in]millisecondsthe number of milliseconds to wait till the callback is invoked

◆ oc_process_baseline_interface()

OC_API void oc_process_baseline_interface ( const oc_resource_t resource)

Helper function used when responding to a GET request to add Common Properties to a GET response.

This add Common Properties name ("n"), Interface ("if"), and Resource Type ("rt") to a GET response.

Example:

bool bswitch_state = false;
void get_bswitch(oc_resource_t *resource, oc_interface_mask_t iface_mask,
void *data)
{
switch (iface_mask) {
// fall through
case OC_IF_A:
oc_rep_set_boolean(root, value, bswitch_state);
break;
default:
break;
}
}
OC_API void oc_process_baseline_interface(const oc_resource_t *resource)
Helper function used when responding to a GET request to add Common Properties to a GET response.
OC_API void oc_send_response(oc_request_t *request, oc_status_t response_code)
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
@ OC_IF_BASELINE
oic.if.baseline
Definition: oc_ri.h:190
Parameters
[in]resourcethe resource the baseline Common Properties will be read from to respond to the GET request (cannot be NULL)

◆ oc_query_value_exists()

OC_API int oc_query_value_exists ( const oc_request_t request,
const char *  key 
)

Checks if a query parameter 'key' exist in the URL query parameter.

Parameters
[in]requestthe oc_request_t that contains the query parameters
[in]keythe key being searched for
Returns
  • 1 exist
  • -1 does not exist

◆ oc_resource_bind_resource_interface()

OC_API void oc_resource_bind_resource_interface ( oc_resource_t resource,
oc_interface_mask_t  iface_mask 
)

Add the supported interface(s) to the resource.

Resource interfaces specify how the code is able to interact with the resource

The iface_mask is bitwise OR of the following interfaces:

  • OC_IF_BASELINE ("oic.if.baseline") baseline interface allow GET, PUT/POST, and notify/observe operations.
  • OC_IF_LL ("oic.if.ll") The links list interface is a specifically designed to provide a list of links pointing to other resources. Links list interfaces allow GET, and notify/observe operations.
  • OC_IF_B ("oic.if.b") batch interface. The batch interface is used to interact with a collection of resources at the same time.
  • OC_IF_R ("oic.if.r") a read-only interface. A read-only interface allows GET, and notify/observe operations.
  • OC_IF_RW ("oir.if.rw") a read-write interface. A read-write interface allows GET, PUT/POST, and notify/observe operations.
  • OC_IF_A ("oic.if.a") an actuator interface. An actuator interface allows GET, PUT/POST, and notify/observe operations.
  • OC_IF_S ("oic.if.s") a sensor interface. A sensor interface allows GET, and notify/observe operations.
  • OC_IC_CREATE ("oic.if.create") used to create new resources in a collection.

The read-write and actuator interfaces are very similar and sometimes hard to differentiate when one should be used over another. In general an actuator interface is used when it modifies the real world value. e.g. turn on light, increase temperature, open vent.

The read-only and sensor are also very similar in general a sensor value is read directly or indirectly from a real world sensor.

Parameters
[in]resourcethe resource that the interface(s) will be added to
[in]iface_maska bitwise ORed list of all interfaces supported by the resource.
See also
oc_interface_mask_t
oc_resource_set_default_interface

◆ oc_resource_bind_resource_type()

OC_API void oc_resource_bind_resource_type ( oc_resource_t resource,
const char *  type 
)

Add a Resource Type "rt" property to the resource.

All resources require at least one Resource Type. The number of Resource Types the resource contains is declared when the resource it created using oc_new_resource() function.

Resource Types use a dot "." naming scheme e.g. oic.r.switch.binary. Resource Types starting with oic are reserved for a OCF defined Resource Types. Developers are strongly encouraged to try and use an OCF defined Resource Type vs. creating their own. A repository of OCF defined resources can be found on https://github.com/openconnectivityfoundation/IoTDataModels.

Multi-value "rt" Resource means a resource with multiple Resource Types. i.e. oc_resource_bind_resource_type() is called multiple times for a single resource. When using a Mulit-value Resource the different resources properties must not conflict.

Parameters
[in]resourcethe resource that the Resource Type will be set on
[in]typethe Resource Type to add to the Resource Type "rt" property
See also
oc_new_resource
oc_device_bind_resource_type

◆ oc_resource_make_public()

OC_API void oc_resource_make_public ( oc_resource_t resource)

Expose unsecured coap:// endpoints (in addition to secured coaps:// endpoints) for this resource in /oic/res.

Note
While the resource may advertise unsecured endpoints, the resource shall remain inaccessible until the hosting device is configured with an anon-clear Access Control Entry (ACE).
Parameters
[in]resourcethe resource to make public
See also
oc_new_resource

◆ oc_resource_set_default_interface()

OC_API void oc_resource_set_default_interface ( oc_resource_t resource,
oc_interface_mask_t  iface_mask 
)

Select the default interface.

The default interface must be one of the resources specified in the oc_resource_bind_resource_interface() function.

If a request to the resource comes in and the interface is not specified then the default interface will be used to service the request.

If the default interface is not set then the OC_IF_BASELINE will be used by the stack.

Parameters
[in]resourcethe resource that the default interface will be set on
[in]iface_maska single interface that will will be used as the default interface

◆ oc_resource_set_discoverable()

OC_API void oc_resource_set_discoverable ( oc_resource_t resource,
bool  state 
)

Specify if a resource can be found using OCF discover mechanisms.

Parameters
[in]resourceto specify as discoverable or non-discoverable
[in]stateif true the resource will be discoverable if false the resource will be non-discoverable
See also
oc_new_resource for example code using this function

◆ oc_resource_set_observable()

OC_API void oc_resource_set_observable ( oc_resource_t resource,
bool  state 
)

Specify that a resource should notify clients when a property has been modified.

Note
this function can be used to make a periodic observable resource unobservable.
Parameters
[in]resourcethe resource to specify the observability
[in]statetrue to make resource observable, false to make resource unobservable
See also
oc_new_resource to see example code using this function
oc_resource_set_periodic_observable

◆ oc_resource_set_periodic_observable()

OC_API void oc_resource_set_periodic_observable ( oc_resource_t resource,
uint16_t  seconds 
)

The resource will periodically notify observing clients of is property values.

The oc_resource_set_observable() function can be used to turn off a periodic observable resource.

Setting a seconds frequency of zero 0 is invalid and will result in an invalid resource.

Parameters
[in]resourcethe resource to specify the periodic observability
[in]secondsthe frequency in seconds that the resource will send out an notification of is property values.

◆ oc_resource_set_pushable()

OC_API void oc_resource_set_pushable ( oc_resource_t resource,
bool  state 
)

Specify if a resource can be pushable.

Parameters
[in]resourceto specify as pushable or non-pushable
[in]stateif true the resource will be pushable if false the resource will be non-pushable

◆ oc_resource_set_request_handler()

OC_API void oc_resource_set_request_handler ( oc_resource_t resource,
oc_method_t  method,
oc_request_callback_t  callback,
void *  user_data 
)

Specify a request_callback for GET, PUT, POST, and DELETE methods.

All resources must provide at least one request handler to be a valid resource.

method types:

  • OC_GET the oc_request_callback_t is responsible for returning the current value of all of the resource properties.
  • OC_PUT the oc_request_callback_t is responsible for updating one or more of the resource properties.
  • OC_POST the oc_request_callback_t is responsible for updating one or more of the resource properties. The callback may also be responsible for creating new resources.
  • OC_DELETE the oc_request_callback_t is responsible for deleting a resource
Note
Some methods may never by invoked based on the resources Interface as well as the provisioning permissions of the client.
Parameters
[in]resourcethe resource the callback handler will be registered to
[in]methodspecify if type method the callback is responsible for handling
[in]callbackthe callback handler that will be invoked when a the method is called on the resource.
[in]user_datacontext pointer that is passed to the oc_request_callback_t. The pointer must remain valid as long as the resource exists.
See also
oc_new_resource to see example code using this function

◆ oc_resource_tag_func_desc()

OC_API void oc_resource_tag_func_desc ( oc_resource_t resource,
oc_enum_t  func 
)

Sets the tag value for the relatvie position "tag_func_rel" tag.

Parameters
resourcethe resource to apply the tag too.
functhe function description

◆ oc_resource_tag_locn()

OC_API void oc_resource_tag_locn ( oc_resource_t resource,
oc_locn_t  locn 
)

sets the value of the "tag_locn" tag

Parameters
resourcethe resource to apply the tag too.
locnthe location

◆ oc_resource_tag_pos_desc()

OC_API void oc_resource_tag_pos_desc ( oc_resource_t resource,
oc_pos_description_t  pos 
)

Sets the tag value for tag "tag-pos-desc" on the resource.

Parameters
resourcethe resource
posthe descriptive text for the tag

◆ oc_resource_tag_pos_rel()

OC_API void oc_resource_tag_pos_rel ( oc_resource_t resource,
double  x,
double  y,
double  z 
)

Sets the value for the relative position "tag-pos-rel" tag.

Parameters
resourcethe resource to apply the tag too.
xthe x value in 3D space
ythe y value in 3D space
zthe z value in 3D space

◆ oc_send_diagnostic_message()

OC_API void oc_send_diagnostic_message ( oc_request_t request,
const char *  msg,
size_t  msg_len,
oc_status_t  response_code 
)

send a diagnostic payload

Parameters
requestthe request
msgthe message in ascii
msg_lenthe lenght of the message
response_codethe coap response code

◆ oc_send_response()

OC_API void oc_send_response ( oc_request_t request,
oc_status_t  response_code 
)

Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.

The function oc_send_response is called at the end of a oc_request_callback_t to inform the caller about the status of the requested action.

Note
This function just calls oc_send_response_with_callback with trigger_cb set to false.
Parameters
[in]requestthe request being responded to
[in]response_codethe status of the response
See also
oc_request_callback_t
oc_ignore_request
oc_indicate_separate_response
oc_send_response_with_callback

◆ oc_send_response_raw()

OC_API void oc_send_response_raw ( oc_request_t request,
const uint8_t *  payload,
size_t  size,
oc_content_format_t  content_format,
oc_status_t  response_code 
)

send the request, no processing

Parameters
requestthe request to send
payloadthe payload for the request
sizethe payload size
content_formatthe content format
response_codethe response code to send

◆ oc_send_response_with_callback()

OC_API void oc_send_response_with_callback ( oc_request_t request,
oc_status_t  response_code,
bool  trigger_cb 
)

Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.

The function oc_send_response is called at the end of a oc_request_callback_t to inform the caller about the status of the requested action.

Parameters
[in]requestthe request being responded to
[in]response_codethe status of the response
[in]trigger_cbif true, the send response callback will be triggered
Note
For libraries it is recommended to set trigger_cb to true to allow modify the response body.
See also
oc_request_callback_t
oc_ignore_request
oc_indicate_separate_response

◆ oc_send_separate_response()

OC_API void oc_send_separate_response ( oc_separate_response_t handle,
oc_status_t  response_code 
)

Called to send the deferred response to a GET, PUT, POST or DELETE request.

The function oc_send_separate_response is called to initiate transfer of the response.

Parameters
[in]handleinstance of the internal struct that was passed to oc_indicate_separate_response()
[in]response_codethe status of the response
See also
oc_indicate_separate_response
oc_send_separate_response
oc_send_response
oc_ignore_request

◆ oc_set_con_write_cb()

OC_API void oc_set_con_write_cb ( oc_con_write_cb_t  callback)

Sets the callback to receive change notifications for the oic.wk.con resource.

The function can be used to set or unset the callback. Whenever an attribute of the oic.wk.con resource is changed, the callback will be invoked.

Parameters
callbackThe callback to register or NULL to unset it. If the function is invoked a second time, then the previously set callback is simply replaced.

◆ oc_set_send_response_callback()

OC_API void oc_set_send_response_callback ( oc_send_response_cb_t  cb)

Set the send response callback function.

Note
This function is not thread safe. It should be called before oc_main_init().
Parameters
cbthat will be triggered by oc_send_response_with_callback when the trigger_cb is true.

◆ oc_set_separate_response_buffer()

OC_API void oc_set_separate_response_buffer ( oc_separate_response_t handle)

Set a response buffer for holding the response payload.

When a deferred response is ready, pass in the same oc_separate_response_t that was handed to oc_indicate_separate_response() for delaying the initial response.

Parameters
[in]handleinstance of the oc_separate_response_t that was passed to the oc_indicate_separate_response() function
See also
oc_indicate_separate_response
oc_send_separate_response