1 /* t_list -- tinydtls lists
3 * Copyright (C) 2012 Olaf Bergmann <bergmann@tzi.org>
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use, copy,
9 * modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * @brief Wrappers for list structures and functions
38 /* We define list structures and utility functions to be compatible
39 * with Contiki list structures. The Contiki list API is part of the
40 * Contiki operating system, and therefore the following licensing
41 * terms apply (taken from contiki/core/lib/list.h):
43 * Copyright (c) 2004, Swedish Institute of Computer Science.
44 * All rights reserved.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the Institute nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * This file is part of the Contiki operating system.
72 * Author: Adam Dunkels <adam@sics.se>
74 * $ Id: list.h,v 1.5 2010/09/13 13:31:00 adamdunkels Exp $
77 typedef void **list_t;
83 #define LIST_CONCAT(s1, s2) s1##s2
85 #define LIST_STRUCT(name) \
86 void *LIST_CONCAT(name, _list); \
89 #define LIST_STRUCT_INIT(struct_ptr, name) { \
90 (struct_ptr)->name = &((struct_ptr)->LIST_CONCAT(name,_list)); \
91 (struct_ptr)->LIST_CONCAT(name,_list) = NULL; \
95 list_head(list_t the_list)
100 INLINE_API void list_remove(list_t the_list, void *item)
102 if (list_head(the_list))
103 LL_DELETE(*(struct list **)the_list, (struct list *)item);
106 INLINE_API void list_add(list_t the_list, void *item)
108 list_remove(the_list, item);
109 LL_APPEND(*(struct list **)the_list, (struct list *)item);
112 INLINE_API void list_push(list_t the_list, void *item)
114 LL_PREPEND(*(struct list **)the_list, (struct list *)item);
118 list_pop(list_t the_list)
121 l = (struct list*) *the_list;
123 list_remove(the_list, l);
128 INLINE_API void list_insert(list_t the_list, void *previtem, void *newitem)
130 if (previtem == NULL)
132 list_push(the_list, newitem);
136 ((struct list *) newitem)->next = ((struct list *) previtem)->next;
137 ((struct list *) previtem)->next = (struct list*) newitem;
142 list_item_next(void *item)
144 return item == NULL ? NULL : ((struct list *) item)->next;
147 #else /* WITH_CONTIKI */
149 #endif /* WITH_CONTIKI */
151 #endif /* _DTLS_LIST_H_ */