libcoap  4.3.0beta
Resource Observation

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_tcoap_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_tcoap_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_tcoap_resource_get_uri_path (coap_resource_t *resource)
 Get the UriPath from a resource. More...
 

Detailed Description

API functions for interfacing with the observe handling (RFC7641)

Macro Definition Documentation

◆ COAP_OBSERVE_CANCEL

#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.

◆ COAP_OBSERVE_ESTABLISH

#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.

Function Documentation

◆ coap_add_observer()

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.

Parameters
resourceThe observed resource.
sessionThe observer's session
tokenThe token that identifies this subscription.
queryThe query string, if any. subscription will take ownership of the string unless this function returns NULL.
has_block2If Option Block2 defined.
block2Contents of Block2 if Block 2 defined.
codeRequest type code.
Returns
A pointer to the added/updated subscription information or NULL on error.

Definition at line 711 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_delete_observer()

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.

Parameters
resourceThe observed resource.
sessionThe observer's session.
tokenThe token that identifies this subscription or NULL for any token.
Returns
1 if the observer has been deleted, 0 otherwise.

Definition at line 795 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_delete_observers()

void coap_delete_observers ( coap_context_t context,
coap_session_t session 
)

Removes any subscription for session and releases the allocated storage.

Parameters
contextThe CoAP context to use.
sessionThe observer's session.

Definition at line 821 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_find_observer()

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.

Parameters
resourceThe observed resource.
sessionThe observer's session
tokenThe token that identifies this subscription or NULL for any token.
Returns
A valid subscription if exists or NULL otherwise.

Definition at line 675 of file resource.c.

+ Here is the caller graph for this function:

◆ coap_resource_get_uri_path()

COAP_STATIC_INLINE coap_str_const_t* coap_resource_get_uri_path ( coap_resource_t resource)

Get the UriPath from a resource.

Parameters
resourceThe CoAP resource to check.
Returns
The UriPath if it exists or NULL otherwise.

Definition at line 552 of file resource.h.

◆ coap_resource_notify_observers()

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.

Parameters
resourceThe CoAP resource to use.
queryThe Query to match against or NULL
Returns
1 if the Observe has been triggered, 0 otherwise.

Definition at line 948 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_resource_set_get_observable()

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.

Parameters
resourceThe CoAP resource to use.
mode1 if Observable is to be set, 0 otherwise.

Definition at line 527 of file resource.h.

◆ coap_touch_observer()

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.

Parameters
contextThe CoAP context to use.
sessionThe observer's session
tokenThe corresponding token that has been used for the subscription.

Definition at line 782 of file resource.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: