libcoap  4.0.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
resource.h
Go to the documentation of this file.
1 /* resource.h -- generic resource handling
2  *
3  * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * This file is part of the CoAP library libcoap. Please see
6  * README for terms of use.
7  */
8 
14 #ifndef _COAP_RESOURCE_H_
15 #define _COAP_RESOURCE_H_
16 
17 #include "config.h"
18 #include "t_list.h"
19 
20 #if defined(HAVE_ASSERT_H) && !defined(assert)
21 # include <assert.h>
22 #endif
23 
24 #ifndef COAP_RESOURCE_CHECK_TIME
25 
26 #define COAP_RESOURCE_CHECK_TIME 2
27 #endif /* COAP_RESOURCE_CHECK_TIME */
28 
29 #ifndef WITH_CONTIKI
30 #include "uthash.h"
31 #else /* WITH_CONTIKI */
32 #endif /* WITH_CONTIKI */
33 #include "hashkey.h"
34 #include "async.h"
35 #include "str.h"
36 #include "pdu.h"
37 #include "net.h"
38 #include "subscribe.h"
39 
41 typedef void (*coap_method_handler_t)
43  str * /* token */, coap_pdu_t * /* response */);
44 
45 #define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
46 #define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
47 
48 typedef struct coap_attr_t {
49  struct coap_attr_t *next;
50  str name;
51  str value;
52  int flags;
53 } coap_attr_t;
54 
55 #define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
56 
57 typedef struct coap_resource_t {
58  unsigned int dirty:1;
59  unsigned int observable:1;
60  unsigned int cacheable:1;
69 
72 #ifndef WITH_CONTIKI
75 #else /* WITH_CONTIKI */
77 #endif /* WITH_CONTIKI */
78  LIST_STRUCT(subscribers);
84  str uri;
85  int flags;
86 
88 
100 coap_resource_t *coap_resource_init(const unsigned char *uri, size_t len, int flags);
101 
111 
122 
139  const unsigned char *name, size_t nlen,
140  const unsigned char *val, size_t vlen,
141  int flags);
142 
154  const unsigned char *name, size_t nlen);
155 
162 void coap_delete_attr(coap_attr_t *attr);
163 
180  unsigned char *buf, size_t *len);
181 
190 static inline void
192  unsigned char method, coap_method_handler_t handler) {
193  assert(resource);
194  assert(method > 0 && (size_t)(method-1) < sizeof(resource->handler)/sizeof(coap_method_handler_t));
195  resource->handler[method-1] = handler;
196 }
197 
208  coap_key_t key);
209 
218 void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key);
219 
239  const coap_address_t *observer,
240  const str *token);
241 
252  const coap_address_t *peer,
253  const str *token);
254 
263 void coap_touch_observer(coap_context_t *context,
264  const coap_address_t *observer,
265  const str *token);
266 
277  const coap_address_t *observer,
278  const str *token);
279 
284 void coap_check_notify(coap_context_t *context);
285 
288 #endif /* _COAP_RESOURCE_H_ */