libcoap
4.1.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Macros
Groups
Pages
resource.h
Go to the documentation of this file.
1
/* resource.h -- generic resource handling
2
*
3
* Copyright (C) 2010,2011,2014 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
# ifdef COAP_RESOURCES_NOHASH
31
# include "
utlist.h
"
32
# else
33
# include "
uthash.h
"
34
# endif
35
#else
/* WITH_CONTIKI */
36
#endif
/* WITH_CONTIKI */
37
#include "
hashkey.h
"
38
#include "
async.h
"
39
#include "
str.h
"
40
#include "
pdu.h
"
41
#include "
net.h
"
42
#include "
subscribe.h
"
43
45
typedef
void (*
coap_method_handler_t
)
46
(
coap_context_t
*,
struct
coap_resource_t
*, coap_address_t *,
coap_pdu_t
*,
47
str
*
/* token */
, coap_pdu_t *
/* response */
);
48
49
#define COAP_ATTR_FLAGS_RELEASE_NAME 0x1
50
#define COAP_ATTR_FLAGS_RELEASE_VALUE 0x2
51
52
typedef
struct
coap_attr_t
{
53
struct
coap_attr_t
*
next
;
54
str
name
;
55
str
value
;
56
int
flags
;
57
}
coap_attr_t
;
58
59
#define COAP_RESOURCE_FLAGS_RELEASE_URI 0x1
60
61
typedef
struct
coap_resource_t
{
62
unsigned
int
dirty
:1;
63
unsigned
int
partiallydirty
:1;
64
unsigned
int
observable
:1;
65
unsigned
int
cacheable
:1;
73
coap_method_handler_t
handler
[4];
74
75
coap_key_t
key
;
77
#ifndef WITH_CONTIKI
78
#ifdef COAP_RESOURCES_NOHASH
79
struct
coap_resource_t
*next;
80
#else
81
UT_hash_handle
hh
;
82
#endif
83
#endif
/* WITH_CONTIKI */
84
85
#ifndef WITH_CONTIKI
86
coap_attr_t
*
link_attr
;
87
#else
/* WITH_CONTIKI */
88
LIST_STRUCT
(
link_attr
);
89
#endif
/* WITH_CONTIKI */
90
LIST_STRUCT
(subscribers);
96
str
uri
;
97
int
flags
;
98
99
}
coap_resource_t
;
100
112
coap_resource_t
*
coap_resource_init
(
const
unsigned
char
*
uri
,
size_t
len,
int
flags
);
113
122
void
coap_add_resource
(
coap_context_t
*context,
coap_resource_t
*
resource
);
123
133
int
coap_delete_resource
(
coap_context_t
*context,
coap_key_t
key
);
134
150
coap_attr_t
*
coap_add_attr
(
coap_resource_t
*
resource
,
151
const
unsigned
char
*name,
size_t
nlen,
152
const
unsigned
char
*val,
size_t
vlen,
153
int
flags
);
154
165
coap_attr_t
*
coap_find_attr
(
coap_resource_t
*
resource
,
166
const
unsigned
char
*name,
size_t
nlen);
167
174
void
coap_delete_attr
(
coap_attr_t
*attr);
175
186
typedef
unsigned
int
coap_print_status_t
;
187
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
192
215
coap_print_status_t
coap_print_link
(
const
coap_resource_t
*
resource
,
216
unsigned
char
*buf,
size_t
*len,
size_t
*offset);
217
226
static
inline
void
227
coap_register_handler
(
coap_resource_t
*
resource
,
228
unsigned
char
method
,
coap_method_handler_t
handler
) {
229
assert(resource);
230
assert(method > 0 && (
size_t
)(method-1) <
sizeof
(resource->
handler
)/
sizeof
(
coap_method_handler_t
));
231
resource->
handler
[method-1] =
handler
;
232
}
233
243
coap_resource_t
*
coap_get_resource_from_key
(
coap_context_t
*context,
244
coap_key_t
key
);
245
254
void
coap_hash_request_uri
(
const
coap_pdu_t *request,
coap_key_t
key
);
255
274
coap_subscription_t
*
coap_add_observer
(
coap_resource_t
*
resource
,
275
const
coap_address_t *observer,
276
const
str *token);
277
287
coap_subscription_t
*
coap_find_observer
(
coap_resource_t
*
resource
,
288
const
coap_address_t *peer,
289
const
str *token);
290
299
void
coap_touch_observer
(
coap_context_t
*context,
300
const
coap_address_t *observer,
301
const
str *token);
302
312
void
coap_delete_observer
(
coap_resource_t
*
resource
,
313
const
coap_address_t *observer,
314
const
str *token);
315
320
void
coap_check_notify
(
coap_context_t
*context);
321
324
#endif
/* _COAP_RESOURCE_H_ */
Generated on Wed Feb 5 2014 15:10:20 for libcoap by
1.8.4