47typedef struct coap_resource_s coap_resource_t;
48typedef struct coap_periodic_resource_s coap_periodic_resource_t;
54 COAP_HANDLER_STATUS_CONTINUE,
55 COAP_HANDLER_STATUS_PROCESSED
56} coap_handler_status_t;
58typedef coap_handler_status_t
59(* coap_handler_callback_t)(coap_message_t *request,
60 coap_message_t *response,
61 uint8_t *buffer, uint16_t buffer_size,
64typedef struct coap_handler coap_handler_t;
68 coap_handler_callback_t handler;
71#define COAP_HANDLER(name, handler) \
72 coap_handler_t name = { NULL, handler }
74void coap_add_handler(coap_handler_t *handler);
75void coap_remove_handler(coap_handler_t *handler);
77void coap_engine_init(
void);
79int coap_receive(
const coap_endpoint_t *src,
80 uint8_t *payload, uint16_t payload_length);
82coap_handler_status_t coap_call_handlers(coap_message_t *request,
83 coap_message_t *response,
89typedef void (* coap_resource_handler_t)(coap_message_t *request,
90 coap_message_t *response,
92 uint16_t preferred_size,
94typedef void (* coap_resource_periodic_handler_t)(void);
95typedef void (* coap_resource_response_handler_t)(
void *data,
96 coap_message_t *response);
97typedef void (* coap_resource_trigger_handler_t)(void);
100struct coap_resource_s {
101 coap_resource_t *next;
104 const char *attributes;
105 coap_resource_handler_t get_handler;
106 coap_resource_handler_t post_handler;
107 coap_resource_handler_t put_handler;
108 coap_resource_handler_t delete_handler;
110 coap_periodic_resource_t *periodic;
111 coap_resource_trigger_handler_t trigger;
112 coap_resource_trigger_handler_t resume;
116struct coap_periodic_resource_s {
118 coap_timer_t periodic_timer;
119 const coap_resource_periodic_handler_t periodic_handler;
126#define RESOURCE(name, attributes, get_handler, post_handler, put_handler, delete_handler) \
127 coap_resource_t name = { NULL, NULL, NO_FLAGS, attributes, get_handler, post_handler, put_handler, delete_handler, { NULL } }
129#define PARENT_RESOURCE(name, attributes, get_handler, post_handler, put_handler, delete_handler) \
130 coap_resource_t name = { NULL, NULL, HAS_SUB_RESOURCES, attributes, get_handler, post_handler, put_handler, delete_handler, { NULL } }
132#define SEPARATE_RESOURCE(name, attributes, get_handler, post_handler, put_handler, delete_handler, resume_handler) \
133 coap_resource_t name = { NULL, NULL, IS_SEPARATE, attributes, get_handler, post_handler, put_handler, delete_handler, { .resume = resume_handler } }
135#define EVENT_RESOURCE(name, attributes, get_handler, post_handler, put_handler, delete_handler, event_handler) \
136 coap_resource_t name = { NULL, NULL, IS_OBSERVABLE, attributes, get_handler, post_handler, put_handler, delete_handler, { .trigger = event_handler } }
143#define PERIODIC_RESOURCE(name, attributes, get_handler, post_handler, put_handler, delete_handler, period, periodic_handler) \
144 static coap_periodic_resource_t periodic_##name = { period, { 0 }, periodic_handler }; \
145 coap_resource_t name = { NULL, NULL, IS_OBSERVABLE | IS_PERIODIC, attributes, get_handler, post_handler, put_handler, delete_handler, { .periodic = &periodic_##name } }
174#include "coap-observe-client.h"
CoAP module for observing resources (draft-ietf-core-observe-11).
CoAP module for separate responses.
CoAP module for reliable transport.
An implementation of the Constrained Application Protocol (RFC 7252).
void coap_activate_resource(coap_resource_t *resource, const char *path)
Makes a resource available under the given URI path.
coap_resource_t * coap_get_next_resource(coap_resource_t *resource)
Returns the next registered CoAP resource.
coap_resource_flags_t
Resource flags for allowed methods and special functionalities.
coap_resource_t * coap_get_first_resource(void)
Returns the first of the registered CoAP resources.