mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
nanocoap: Add handler for resource-based subtrees
This adds a coap_handler_t function that can be used to parse new subtrees. The subtree information is included in the context pointer of the call and must be of type coap_resource_subtree_t. This object then contains the pointer and length of a different coap_resource_t instance.
This commit is contained in:
parent
e56f86d594
commit
eecac6945b
@ -273,6 +273,14 @@ typedef struct {
|
||||
void *context; /**< ptr to user defined context data */
|
||||
} coap_resource_t;
|
||||
|
||||
/**
|
||||
* @brief Type for CoAP resource subtrees
|
||||
*/
|
||||
typedef const struct {
|
||||
const coap_resource_t *resources; /**< ptr to resource array */
|
||||
const size_t resources_numof; /**< number of entries in array */
|
||||
} coap_resource_subtree_t;
|
||||
|
||||
/**
|
||||
* @brief Block1 helper struct
|
||||
*/
|
||||
@ -1751,6 +1759,25 @@ ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
|
||||
const coap_resource_t *resources,
|
||||
size_t resources_numof);
|
||||
|
||||
/**
|
||||
* @brief Generic coap subtree handler
|
||||
*
|
||||
* This function can be used as a generic handler for resources with the
|
||||
* @ref COAP_MATCH_SUBTREE where a new @ref coap_resource_t is to be parsed.
|
||||
*
|
||||
* @note The @p context must be of type @ref coap_resource_subtree_t.
|
||||
*
|
||||
* @param[in] pkt pointer to (parsed) CoAP packet
|
||||
* @param[out] resp_buf buffer for response
|
||||
* @param[in] resp_buf_len size of response buffer
|
||||
* @param[in] context ptr to a @ref coap_resource_subtree_t instance
|
||||
*
|
||||
* @returns size of the reply packet on success
|
||||
* @returns <0 on error
|
||||
*/
|
||||
ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
|
||||
size_t resp_buf_len, void *context);
|
||||
|
||||
/**
|
||||
* @brief Convert message code (request method) into a corresponding bit field
|
||||
*
|
||||
|
@ -424,6 +424,15 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
|
||||
coap_resources_numof);
|
||||
}
|
||||
|
||||
ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
void *context)
|
||||
{
|
||||
assert(context);
|
||||
coap_resource_subtree_t *subtree = context;
|
||||
return coap_tree_handler(pkt, buf, len, subtree->resources,
|
||||
subtree->resources_numof);
|
||||
}
|
||||
|
||||
ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
|
||||
unsigned resp_buf_len,
|
||||
const coap_resource_t *resources,
|
||||
|
Loading…
Reference in New Issue
Block a user