14 #ifndef _COAP_RESOURCE_H_
15 #define _COAP_RESOURCE_H_
20 #if defined(HAVE_ASSERT_H) && !defined(assert)
24 #ifndef COAP_RESOURCE_CHECK_TIME
26 #define COAP_RESOURCE_CHECK_TIME 2
30 # ifdef COAP_RESOURCES_NOHASH
47 str * , coap_pdu_t * );
49 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
50 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
59 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
78 #ifdef COAP_RESOURCES_NOHASH
151 const unsigned char *name,
size_t nlen,
152 const unsigned char *val,
size_t vlen,
166 const unsigned char *name,
size_t nlen);
188 #define COAP_PRINT_STATUS_MASK 0xF0000000u
189 #define COAP_PRINT_OUTPUT_LENGTH(v) ((v) & ~COAP_PRINT_STATUS_MASK)
190 #define COAP_PRINT_STATUS_ERROR 0x80000000u
191 #define COAP_PRINT_STATUS_TRUNC 0x40000000u
216 unsigned char *buf,
size_t *len,
size_t *offset);
275 const coap_address_t *observer,
288 const coap_address_t *peer,
300 const coap_address_t *observer,
313 const coap_address_t *observer,
unsigned int cacheable
can be cached
unsigned char coap_key_t[4]
Wrappers for list structures and functions.
state management for asynchronous messages
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.
unsigned int partiallydirty
set to 1 if some subscribers have not yet been notified of the last change
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.
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. ...
LIST_STRUCT(subscribers)
list of observers for this resource
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
unsigned int dirty
set to 1 if resource has changed
unsigned int observable
can be observed
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
struct coap_attr_t coap_attr_t
coap_subscription_t * coap_add_observer(coap_resource_t *resource, const coap_address_t *observer, const str *token)
Adds the specified peer as observer for 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.
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().
void(* coap_method_handler_t)(coap_context_t *, struct coap_resource_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.
void 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_method_handler_t handler[4]
Used to store handlers for the four coap methods GET, POST, PUT, and DELETE.