15 #ifndef _COAP_RESOURCE_H_ 16 #define _COAP_RESOURCE_H_ 20 #ifndef COAP_RESOURCE_CHECK_TIME 22 #define COAP_RESOURCE_CHECK_TIME 2 25 #ifdef COAP_RESOURCES_NOHASH 50 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1 51 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2 60 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1 61 #define COAP_RESOURCE_FLAGS_NOTIFY_NON 0x0 62 #define COAP_RESOURCE_FLAGS_NOTIFY_CON 0x2 66 unsigned int partiallydirty:1;
68 unsigned int observable:1;
69 unsigned int cacheable:1;
81 #ifdef COAP_RESOURCES_NOHASH 110 size_t len,
int flags);
169 const unsigned char *
name,
171 const unsigned char *val,
186 const unsigned char *
name,
208 #define COAP_PRINT_STATUS_MASK 0xF0000000u 209 #define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK) 210 #define COAP_PRINT_STATUS_ERROR 0x80000000u 211 #define COAP_PRINT_STATUS_TRUNC 0x40000000u 249 unsigned char method,
296 const coap_endpoint_t *local_interface,
297 const coap_address_t *observer,
310 const coap_address_t *peer,
322 const coap_address_t *observer,
337 const coap_address_t *observer,
346 #ifdef COAP_RESOURCES_NOHASH 348 #define RESOURCES_ADD(r, obj) \ 349 LL_PREPEND((r), (obj)) 351 #define RESOURCES_DELETE(r, obj) \ 352 LL_DELETE((r), (obj)) 354 #define RESOURCES_ITER(r,tmp) \ 355 coap_resource_t *tmp; \ 358 #define RESOURCES_FIND(r, k, res) { \ 359 coap_resource_t *tmp; \ 360 (res) = tmp = NULL; \ 361 LL_FOREACH((r), tmp) { \ 362 if (memcmp((k), tmp->key, sizeof(coap_key_t)) == 0) { \ 370 #define RESOURCES_ADD(r, obj) \ 371 HASH_ADD(hh, (r), key, sizeof(coap_key_t), (obj)) 373 #define RESOURCES_DELETE(r, obj) \ 374 HASH_DELETE(hh, (r), (obj)) 376 #define RESOURCES_ITER(r,tmp) \ 377 coap_resource_t *tmp, *rtmp; \ 378 HASH_ITER(hh, (r), tmp, rtmp) 380 #define RESOURCES_FIND(r, k, res) { \ 381 HASH_FIND(hh, (r), (k), sizeof(coap_key_t), (res)); \ 394 const coap_address_t *,
unsigned char coap_key_t[4]
multi-purpose address abstraction
State management for asynchronous messages.
static void coap_resource_set_mode(coap_resource_t *r, int mode)
Sets the notification message type of resource r to given mode which must be one of COAP_RESOURCE_FLA...
int coap_delete_observer(coap_resource_t *resource, const coap_address_t *observer, const str *token)
Removes any subscription for observer from resource and releases the allocated storage.
coap_attr_t * link_attr
attributes to be included with the link format
coap_resource_t * coap_get_resource_from_key(coap_context_t *context, coap_key_t key)
Returns the resource identified by the unique string key.
int coap_delete_resource(coap_context_t *context, coap_key_t key)
Deletes a resource identified by key.
void coap_check_notify(coap_context_t *context)
Checks for all known resources, if they are dirty and notifies subscribed observers.
Abstraction of virtual endpoint that can be attached to coap_context_t.
void coap_delete_all_resources(coap_context_t *context)
Deletes all resources from given context and frees their storage.
void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key)
Calculates the hash key for the resource requested by the Uri-Options of request. ...
str uri
Request URI for this resource.
Header structure for CoAP PDUs.
coap_subscription_t * coap_find_observer(coap_resource_t *resource, const coap_address_t *peer, const str *token)
Returns a subscription object for given peer.
coap_key_t key
the actual key bytes for this resource
static void coap_register_handler(coap_resource_t *resource, unsigned char method, coap_method_handler_t handler)
Registers the specified handler as message handler for the request type method.
coap_print_status_t coap_print_link(const coap_resource_t *resource, unsigned char *buf, size_t *len, size_t *offset)
Writes a description of this resource in link-format to given text buffer.
coap_attr_t * coap_find_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen)
Returns resource's coap_attr_t object with given name if found, NULL otherwise.
struct coap_resource_t coap_resource_t
coap_subscription_t * coap_add_observer(coap_resource_t *resource, const coap_endpoint_t *local_interface, const coap_address_t *observer, const str *token)
Adds the specified peer as observer for resource.
struct coap_attr_t coap_attr_t
coap_subscription_t * subscribers
list of observers for this resource
coap_attr_t * coap_add_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen, const unsigned char *val, size_t vlen, int flags)
Registers a new attribute with the given resource.
Pre-defined constants that reflect defaults for CoAP.
coap_print_status_t coap_print_wellknown(coap_context_t *, unsigned char *, size_t *, size_t, coap_opt_t *)
Prints the names of all known resources to buf.
#define COAP_RESOURCE_FLAGS_NOTIFY_CON
void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
definition of hash key type and helper functions
struct coap_attr_t * next
coap_resource_t * coap_resource_init(const unsigned char *uri, size_t len, int flags)
Creates a new resource object and initializes the link field to the string of length len...
unsigned int coap_print_status_t
Status word to encode the result of conditional print or copy operations such as coap_print_link().
unsigned char coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
void coap_handle_failed_notify(coap_context_t *, const coap_address_t *, const str *)
void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_t *, const coap_endpoint_t *, coap_address_t *, coap_pdu_t *, str *, coap_pdu_t *)
Definition of message handler function (.
The CoAP stack's global state is stored in a coap_context_t object.
void coap_touch_observer(coap_context_t *context, const coap_address_t *observer, const str *token)
Marks an observer as alive.
void coap_delete_attr(coap_attr_t *attr)
Deletes an attribute.
coap_method_handler_t handler[4]
Used to store handlers for the four coap methods GET, POST, PUT, and DELETE.