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;
82 #define LIST_CONCAT(s1, s2) s1##s2
84 #define LIST_STRUCT(name) \
85 void *LIST_CONCAT(name, _list); \
88 #define LIST_STRUCT_INIT(struct_ptr, name) { \
89 (struct_ptr)->name = &((struct_ptr)->LIST_CONCAT(name,_list)); \
90 (struct_ptr)->LIST_CONCAT(name,_list) = NULL; \
94 list_head(list_t the_list) {
99 list_remove(list_t the_list, void *item) {
100 if (list_head(the_list))
101 LL_DELETE(*(struct list **)the_list, (struct list *)item);
105 list_add(list_t the_list, void *item) {
106 list_remove(the_list, item);
107 LL_APPEND(*(struct list **)the_list, (struct list *)item);
111 list_push(list_t the_list, void *item) {
112 LL_PREPEND(*(struct list **)the_list, (struct list *)item);
116 list_pop(list_t the_list) {
118 l = (struct list*)*the_list;
120 list_remove(the_list, l);
126 list_insert(list_t the_list, void *previtem, void *newitem) {
127 if(previtem == NULL) {
128 list_push(the_list, newitem);
130 ((struct list *)newitem)->next = ((struct list *)previtem)->next;
131 ((struct list *)previtem)->next = (struct list*)newitem;
136 list_item_next(void *item)
138 return item == NULL? NULL: ((struct list *)item)->next;
141 #else /* WITH_CONTIKI */
143 #endif /* WITH_CONTIKI */
145 #endif /* _DTLS_LIST_H_ */