libcoap
4.0.3
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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
)
42
(
coap_context_t
*,
struct
coap_resource_t
*,
coap_address_t
*,
coap_pdu_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;
68
coap_method_handler_t
handler
[4];
69
70
coap_key_t
key
;
72
#ifndef WITH_CONTIKI
73
UT_hash_handle
hh
;
74
coap_attr_t
*
link_attr
;
75
#else
/* WITH_CONTIKI */
76
LIST_STRUCT
(
link_attr
);
77
#endif
/* WITH_CONTIKI */
78
LIST_STRUCT
(subscribers);
84
str
uri
;
85
int
flags
;
86
87
}
coap_resource_t
;
88
100
coap_resource_t
*
coap_resource_init
(
const
unsigned
char
*
uri
,
size_t
len,
int
flags
);
101
110
void
coap_add_resource
(
coap_context_t
*context,
coap_resource_t
*
resource
);
111
121
int
coap_delete_resource
(
coap_context_t
*context,
coap_key_t
key);
122
138
coap_attr_t
*
coap_add_attr
(
coap_resource_t
*
resource
,
139
const
unsigned
char
*name,
size_t
nlen,
140
const
unsigned
char
*val,
size_t
vlen,
141
int
flags
);
142
153
coap_attr_t
*
coap_find_attr
(
coap_resource_t
*
resource
,
154
const
unsigned
char
*name,
size_t
nlen);
155
162
void
coap_delete_attr
(
coap_attr_t
*attr);
163
179
int
coap_print_link
(
const
coap_resource_t
*
resource
,
180
unsigned
char
*buf,
size_t
*len);
181
190
static
inline
void
191
coap_register_handler
(
coap_resource_t
*
resource
,
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
207
coap_resource_t
*
coap_get_resource_from_key
(
coap_context_t
*context,
208
coap_key_t
key);
209
218
void
coap_hash_request_uri
(
const
coap_pdu_t *request,
coap_key_t
key);
219
238
coap_subscription_t
*
coap_add_observer
(
coap_resource_t
*
resource
,
239
const
coap_address_t *observer,
240
const
str *token);
241
251
coap_subscription_t
*
coap_find_observer
(
coap_resource_t
*
resource
,
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
276
void
coap_delete_observer
(
coap_resource_t
*
resource
,
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_ */
Generated on Tue Sep 3 2013 14:32:34 for libcoap by
1.8.1.2