libcoap
4.3.0beta
|
API functions for interfacing with the observe handling (RFC7641) More...
Macros | |
#define | COAP_OBSERVE_ESTABLISH 0 |
The value COAP_OBSERVE_ESTABLISH in a GET request indicates a new observe relationship for (sender address, token) is requested. More... | |
#define | COAP_OBSERVE_CANCEL 1 |
The value COAP_OBSERVE_CANCEL in a GET request indicates that the observe relationship for (sender address, token) must be cancelled. More... | |
Functions | |
coap_subscription_t * | coap_add_observer (coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token, coap_string_t *query, int has_block2, coap_block_t block2, uint8_t code) |
Adds the specified peer as observer for resource . More... | |
coap_subscription_t * | coap_find_observer (coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token) |
Returns a subscription object for given peer . More... | |
void | coap_touch_observer (coap_context_t *context, coap_session_t *session, const coap_binary_t *token) |
Flags that data is ready to be sent to observers. More... | |
int | coap_delete_observer (coap_resource_t *resource, coap_session_t *session, const coap_binary_t *token) |
Removes any subscription for observer from resource and releases the allocated storage. More... | |
void | coap_delete_observers (coap_context_t *context, coap_session_t *session) |
Removes any subscription for session and releases the allocated storage. More... | |
COAP_STATIC_INLINE void | coap_resource_set_get_observable (coap_resource_t *resource, int mode) |
Set whether a resource is observable. More... | |
int | coap_resource_notify_observers (coap_resource_t *resource, const coap_string_t *query) |
Initiate the sending of an Observe packet for all observers of resource , optionally matching query if not NULL. More... | |
COAP_STATIC_INLINE coap_str_const_t * | coap_resource_get_uri_path (coap_resource_t *resource) |
Get the UriPath from a resource . More... | |
API functions for interfacing with the observe handling (RFC7641)
#define COAP_OBSERVE_CANCEL 1 |
The value COAP_OBSERVE_CANCEL in a GET request indicates that the observe relationship for (sender address, token) must be cancelled.
Definition at line 35 of file subscribe.h.
#define COAP_OBSERVE_ESTABLISH 0 |
The value COAP_OBSERVE_ESTABLISH in a GET request indicates a new observe relationship for (sender address, token) is requested.
Definition at line 29 of file subscribe.h.
coap_subscription_t* coap_add_observer | ( | coap_resource_t * | resource, |
coap_session_t * | session, | ||
const coap_binary_t * | token, | ||
coap_string_t * | query, | ||
int | has_block2, | ||
coap_block_t | block2, | ||
uint8_t | code | ||
) |
Adds the specified peer as observer for resource
.
The subscription is identified by the given token
. This function returns the registered subscription information if the observer
has been added, or NULL
on error.
resource | The observed resource. |
session | The observer's session |
token | The token that identifies this subscription. |
query | The query string, if any. subscription will take ownership of the string unless this function returns NULL. |
has_block2 | If Option Block2 defined. |
block2 | Contents of Block2 if Block 2 defined. |
code | Request type code. |
NULL
on error. Definition at line 711 of file resource.c.
int coap_delete_observer | ( | coap_resource_t * | resource, |
coap_session_t * | session, | ||
const coap_binary_t * | token | ||
) |
Removes any subscription for observer
from resource
and releases the allocated storage.
The result is 1
if an observation relationship with observer
and token
existed, 0
otherwise.
resource | The observed resource. |
session | The observer's session. |
token | The token that identifies this subscription or NULL for any token. |
1
if the observer has been deleted, 0
otherwise. Definition at line 795 of file resource.c.
void coap_delete_observers | ( | coap_context_t * | context, |
coap_session_t * | session | ||
) |
Removes any subscription for session
and releases the allocated storage.
context | The CoAP context to use. |
session | The observer's session. |
Definition at line 821 of file resource.c.
coap_subscription_t* coap_find_observer | ( | coap_resource_t * | resource, |
coap_session_t * | session, | ||
const coap_binary_t * | token | ||
) |
Returns a subscription object for given peer
.
resource | The observed resource. |
session | The observer's session |
token | The token that identifies this subscription or NULL for any token. |
NULL
otherwise. Definition at line 675 of file resource.c.
COAP_STATIC_INLINE coap_str_const_t* coap_resource_get_uri_path | ( | coap_resource_t * | resource | ) |
Get the UriPath from a resource
.
resource | The CoAP resource to check. |
NULL
otherwise. Definition at line 552 of file resource.h.
int coap_resource_notify_observers | ( | coap_resource_t * | resource, |
const coap_string_t * | query | ||
) |
Initiate the sending of an Observe packet for all observers of resource
, optionally matching query
if not NULL.
resource | The CoAP resource to use. |
query | The Query to match against or NULL |
1
if the Observe has been triggered, 0
otherwise. Definition at line 948 of file resource.c.
COAP_STATIC_INLINE void coap_resource_set_get_observable | ( | coap_resource_t * | resource, |
int | mode | ||
) |
Set whether a resource
is observable.
If the resource is observable and the client has set the COAP_OPTION_OBSERVE in a request packet, then whenever the state of the resource changes (a call to coap_resource_trigger_observe()), an Observer response will get sent.
resource | The CoAP resource to use. |
mode | 1 if Observable is to be set, 0 otherwise. |
Definition at line 527 of file resource.h.
void coap_touch_observer | ( | coap_context_t * | context, |
coap_session_t * | session, | ||
const coap_binary_t * | token | ||
) |
Flags that data is ready to be sent to observers.
context | The CoAP context to use. |
session | The observer's session |
token | The corresponding token that has been used for the subscription. |
Definition at line 782 of file resource.c.