IoTivity-Lite
Server side

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

Typedefs

typedef void(* oc_con_write_cb_t) (size_t device_index, const 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

bool oc_add_resource (oc_resource_t *resource)
 Add a resource to the IoTivity stack. More...
 
void oc_delayed_delete_resource (oc_resource_t *resource)
 Schedule a callback to remove a resource. More...
 
bool oc_delete_resource (oc_resource_t *resource)
 Remove a resource from the IoTivity stack and delete the resource. More...
 
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...
 
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...
 
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...
 
int oc_get_query_value_v1 (const oc_request_t *request, const char *key, size_t key_len, const char **value)
 Get a pointer to the start of the value in a URL query parameter key=value pair. More...
 
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...
 
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...
 
void oc_ignore_request (oc_request_t *request)
 Ignore the request. More...
 
void oc_indicate_separate_response (oc_request_t *request, oc_separate_response_t *response)
 Respond to an incoming request asynchronously. More...
 
void oc_init_query_iterator (void)
 This resets the query iterator to the start of the URI query parameter. More...
 
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...
 
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...
 
bool oc_iterate_query_get_values_v1 (const oc_request_t *request, const char *key, size_t key_len, const char **value, int *value_len)
 Iterate though the URI query parameters for a specific key. More...
 
oc_resource_toc_new_resource (const char *name, const char *uri, uint8_t num_resource_types, size_t device)
 Allocate and populate a new oc_resource_t. More...
 
int oc_notify_observers (oc_resource_t *resource)
 Notify all observers of a change to a given resource's property. More...
 
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...
 
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...
 
void oc_notify_resource_changed (oc_resource_t *resource)
 Notify all relevant mechanisms of a change to a given resource. More...
 
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...
 
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...
 
bool oc_query_value_exists_v1 (const oc_request_t *request, const char *key, size_t key_len)
 Checks if a query parameter 'key' exist in the URL query parameter. More...
 
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...
 
void oc_resource_bind_resource_type (oc_resource_t *resource, const char *type)
 Add a Resource Type "rt" property to the resource. More...
 
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...
 
void oc_resource_set_default_interface (oc_resource_t *resource, oc_interface_mask_t iface_mask)
 Select the default interface. More...
 
void oc_resource_set_discoverable (oc_resource_t *resource, bool state)
 Specify if a resource can be found using OCF discover mechanisms. More...
 
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...
 
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...
 
void oc_resource_set_pushable (oc_resource_t *resource, bool state)
 Specify if a resource can be pushable. More...
 
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...
 
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...
 
void oc_resource_tag_locn (oc_resource_t *resource, oc_locn_t locn)
 sets the value of the "tag_locn" tag More...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
void oc_set_send_response_callback (oc_send_response_cb_t cb)
 Set the send response callback function. More...
 
int oc_set_send_response_etag (oc_request_t *request, const uint8_t *etag, uint8_t etag_len)
 Set the ETag for the response to a OC_GET request. More...
 
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, const 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()

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
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()

void oc_delayed_delete_resource ( oc_resource_t resource)

Schedule a callback to remove a resource.

Parameters
resourcethe resource to delete

◆ oc_delete_resource()

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
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()

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
deviceindex of a logical device
typethe Resource type to add to the Resource Type "rt" property (cannot be NULL)

◆ oc_get_diagnostic_message()

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()

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.

Deprecated:
replaced by oc_get_query_value_v1 in v2.2.5.9

◆ oc_get_query_value_v1()

int oc_get_query_value_v1 ( const oc_request_t request,
const char *  key,
size_t  key_len,
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 (cannot be NULL)
[in]key_lenthe length of the key
[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()

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()

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()

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 (cannot be NULL)
See also
oc_request_callback_t
oc_send_response

◆ oc_indicate_separate_response()

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);
}
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.
void oc_set_separate_response_buffer(oc_separate_response_t *handle)
Set a response buffer for holding the response payload.
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.
void oc_indicate_separate_response(oc_request_t *request, oc_separate_response_t *response)
Respond to an incoming request asynchronously.
#define oc_rep_start_root_object()
This macro has been replaced with oc_rep_begin_root_object.
Definition: oc_rep.h:583
#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:416
#define oc_rep_end_root_object()
End the root object.
Definition: oc_rep.h:600
#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:370
@ OC_STATUS_OK
OK.
Definition: oc_ri.h:76
oc_interface_mask_t
interface masks
Definition: oc_ri.h:169
struct oc_separate_response_s oc_separate_response_t
seperate response type
Definition: oc_ri.h:238
request information structure
Definition: oc_ri.h:249
Parameters
[in]requestthe request that will be responded to as a separate response (cannot be NULL)
[in]responseinstance of an internal struct that is used to track the state of the separate response. (cannot be NULL)
See also
oc_set_separate_response_buffer
oc_send_separate_response

◆ oc_init_query_iterator()

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()

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);
}
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.
void oc_init_query_iterator(void)
This resets the query iterator to the start of the URI query parameter.
Parameters
[in]requestthe oc_request_t that contains the query parameters (cannot be NULL)
[out]keypointer to the location of the the key of the key=value pair (cannot be NULL)
[out]key_lenthe length of the key string (cannot be NULL)
[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()

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.

Deprecated:
replaced by oc_iterate_query_get_values_v1 in v2.2.5.9

◆ oc_iterate_query_get_values_v1()

bool oc_iterate_query_get_values_v1 ( const oc_request_t request,
const char *  key,
size_t  key_len,
const char **  value,
int *  value_len 
)

Iterate though the URI query parameters for a specific key.

Before calling oc_iterate_query_get_values_v1() 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";
const char *value = NULL;
int value_len = -1;
do {
more_query_params = oc_iterate_query_get_values_v1(request, "hello",
strlen("hello"), &value, &value_len);
if (rt_len > 0) {
printf("Found %s = %.*s\n", "hello", value_len, value);
}
} while (more_query_params);
bool oc_iterate_query_get_values_v1(const oc_request_t *request, const char *key, size_t key_len, 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)
[in]key_lenthe length of the key
[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_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);
}
void oc_resource_set_discoverable(oc_resource_t *resource, bool state)
Specify if a resource can be found using OCF discover mechanisms.
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.
bool oc_add_resource(oc_resource_t *resource)
Add a resource to the IoTivity stack.
void oc_resource_set_default_interface(oc_resource_t *resource, oc_interface_mask_t iface_mask)
Select the default interface.
void oc_resource_bind_resource_type(oc_resource_t *resource, const char *type)
Add a Resource Type "rt" property to the resource.
void oc_resource_bind_resource_interface(oc_resource_t *resource, oc_interface_mask_t iface_mask)
Add the supported interface(s) to the resource.
void oc_resource_set_observable(oc_resource_t *resource, bool state)
Specify that a resource should notify clients when a property has been modified.
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:175
resource structure
Definition: oc_ri.h:326
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()

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 (cannot be NULL)
Returns
  • the number observers notified on success
  • 0 on failure could also mean no registered observers

◆ oc_notify_observers_delayed()

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 (cannot be NULL)
[in]secondsthe number of seconds to wait till the callback is invoked

◆ oc_notify_observers_delayed_ms()

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 (cannot be NULL)
[in]millisecondsthe number of milliseconds to wait till the callback is invoked

◆ oc_notify_resource_changed()

void oc_notify_resource_changed ( oc_resource_t resource)

Notify all relevant mechanisms of a change to a given resource.

Parameters
resourceresource that has a modified property (cannot be NULL)

◆ oc_process_baseline_interface()

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;
}
}
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.
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_IF_BASELINE
oic.if.baseline
Definition: oc_ri.h:170
Parameters
resourcethe resource the baseline Common Properties will be read from to respond to the GET request (cannot be NULL)

◆ oc_query_value_exists()

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.

Returns
1 if the key exist in the query parameter
-1 if the key does not exist in the query parameter
Deprecated:
replaced by oc_query_value_exists_v1 in v2.2.5.9

◆ oc_query_value_exists_v1()

bool oc_query_value_exists_v1 ( const oc_request_t request,
const char *  key,
size_t  key_len 
)

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

Parameters
requestthe oc_request_t that contains the query parameters
keythe key being searched for (cannot be NULL)
key_lenthe length of the key
Returns
true if the key exist in the query parameter
false if the key does not exist in the query parameter

◆ oc_resource_bind_resource_interface()

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
resourcethe resource that the interface(s) will be added to (cannot be NULL)
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()

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
resourcethe resource that the Resource Type will be set on (cannot be NULL)
typethe Resource Type to add to the Resource Type "rt" property (cannot be NULL)
See also
oc_new_resource
oc_device_bind_resource_type

◆ oc_resource_make_public()

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
resourcethe resource to make public (cannot be NULL)
See also
oc_new_resource

◆ oc_resource_set_default_interface()

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
resourcethe resource that the default interface will be set on (cannot be NULL)
iface_maska single interface that will will be used as the default interface

◆ oc_resource_set_discoverable()

void oc_resource_set_discoverable ( oc_resource_t resource,
bool  state 
)

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

Parameters
resourceto specify as discoverable or non-discoverable (cannot be NULL)
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()

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
resourcethe resource to specify the observability (cannot be NULL)
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()

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
resourcethe resource to specify the periodic observability (cannot be NULL)
secondsthe frequency in seconds that the resource will send out an notification of is property values.

◆ oc_resource_set_pushable()

void oc_resource_set_pushable ( oc_resource_t resource,
bool  state 
)

Specify if a resource can be pushable.

Parameters
resourceto specify as pushable or non-pushable (cannot be NULL)
stateif true the resource will be pushable if false the resource will be non-pushable

◆ oc_resource_set_request_handler()

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
resourcethe resource the callback handler will be registered to (cannot be NULL)
methodspecify if type method the callback is responsible for handling
callbackthe callback handler that will be invoked when a the method is called on the resource.
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()

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 (cannot be NULL).
functhe function description

◆ oc_resource_tag_locn()

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 (cannot be NULL).
locnthe location

◆ oc_resource_tag_pos_desc()

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 (cannot be NULL)
posthe descriptive text for the tag

◆ oc_resource_tag_pos_rel()

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 (cannot be NULL).
xthe x value in 3D space
ythe y value in 3D space
zthe z value in 3D space

◆ oc_send_diagnostic_message()

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 length of the message
response_codethe coap response code

◆ oc_send_response()

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()

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()

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()

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()

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()

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_send_response_etag()

int oc_set_send_response_etag ( oc_request_t request,
const uint8_t *  etag,
uint8_t  etag_len 
)

Set the ETag for the response to a OC_GET request.

Parameters
requestthe request being responded to (cannot be NULL)
etagETag value (cannot be NULL)
etag_lenlength of the ETag value
Returns
0 if successful,
-EINVAL if the request method is not OC_GET or the etag_len is longer than COAP_ETAG_LEN

◆ oc_set_separate_response_buffer()

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 (cannot be NULL)
See also
oc_indicate_separate_response
oc_send_separate_response