Version 0.5.0 of tinydtls
Dependents: tinydtls_test_cellular tinydtls_test_ethernet tiny-dtls
t_list.h@1:598a56fe116e, 2014-02-12 (annotated)
- Committer:
- ashleymills
- Date:
- Wed Feb 12 09:30:16 2014 +0000
- Revision:
- 1:598a56fe116e
- Parent:
- 0:ff9ebe0cf0e9
Explicitly removed something instead of relying on MACRO to disable it. Mbed can't use it.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:ff9ebe0cf0e9 | 1 | /* t_list -- tinydtls lists |
ashleymills | 0:ff9ebe0cf0e9 | 2 | * |
ashleymills | 0:ff9ebe0cf0e9 | 3 | * Copyright (C) 2012 Olaf Bergmann <bergmann@tzi.org> |
ashleymills | 0:ff9ebe0cf0e9 | 4 | * |
ashleymills | 0:ff9ebe0cf0e9 | 5 | * Permission is hereby granted, free of charge, to any person |
ashleymills | 0:ff9ebe0cf0e9 | 6 | * obtaining a copy of this software and associated documentation |
ashleymills | 0:ff9ebe0cf0e9 | 7 | * files (the "Software"), to deal in the Software without |
ashleymills | 0:ff9ebe0cf0e9 | 8 | * restriction, including without limitation the rights to use, copy, |
ashleymills | 0:ff9ebe0cf0e9 | 9 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
ashleymills | 0:ff9ebe0cf0e9 | 10 | * of the Software, and to permit persons to whom the Software is |
ashleymills | 0:ff9ebe0cf0e9 | 11 | * furnished to do so, subject to the following conditions: |
ashleymills | 0:ff9ebe0cf0e9 | 12 | * |
ashleymills | 0:ff9ebe0cf0e9 | 13 | * The above copyright notice and this permission notice shall be |
ashleymills | 0:ff9ebe0cf0e9 | 14 | * included in all copies or substantial portions of the Software. |
ashleymills | 0:ff9ebe0cf0e9 | 15 | * |
ashleymills | 0:ff9ebe0cf0e9 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
ashleymills | 0:ff9ebe0cf0e9 | 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
ashleymills | 0:ff9ebe0cf0e9 | 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ashleymills | 0:ff9ebe0cf0e9 | 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
ashleymills | 0:ff9ebe0cf0e9 | 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
ashleymills | 0:ff9ebe0cf0e9 | 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
ashleymills | 0:ff9ebe0cf0e9 | 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
ashleymills | 0:ff9ebe0cf0e9 | 23 | * SOFTWARE. |
ashleymills | 0:ff9ebe0cf0e9 | 24 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 25 | |
ashleymills | 0:ff9ebe0cf0e9 | 26 | /** |
ashleymills | 0:ff9ebe0cf0e9 | 27 | * @file t_list.h |
ashleymills | 0:ff9ebe0cf0e9 | 28 | * @brief Wrappers for list structures and functions |
ashleymills | 0:ff9ebe0cf0e9 | 29 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 30 | |
ashleymills | 0:ff9ebe0cf0e9 | 31 | #ifndef _DTLS_LIST_H_ |
ashleymills | 0:ff9ebe0cf0e9 | 32 | #define _DTLS_LIST_H_ |
ashleymills | 0:ff9ebe0cf0e9 | 33 | |
ashleymills | 0:ff9ebe0cf0e9 | 34 | #ifndef WITH_CONTIKI |
ashleymills | 0:ff9ebe0cf0e9 | 35 | #include "uthash.h" |
ashleymills | 0:ff9ebe0cf0e9 | 36 | #include "utlist.h" |
ashleymills | 0:ff9ebe0cf0e9 | 37 | |
ashleymills | 0:ff9ebe0cf0e9 | 38 | /* We define list structures and utility functions to be compatible |
ashleymills | 0:ff9ebe0cf0e9 | 39 | * with Contiki list structures. The Contiki list API is part of the |
ashleymills | 0:ff9ebe0cf0e9 | 40 | * Contiki operating system, and therefore the following licensing |
ashleymills | 0:ff9ebe0cf0e9 | 41 | * terms apply (taken from contiki/core/lib/list.h): |
ashleymills | 0:ff9ebe0cf0e9 | 42 | * |
ashleymills | 0:ff9ebe0cf0e9 | 43 | * Copyright (c) 2004, Swedish Institute of Computer Science. |
ashleymills | 0:ff9ebe0cf0e9 | 44 | * All rights reserved. |
ashleymills | 0:ff9ebe0cf0e9 | 45 | * |
ashleymills | 0:ff9ebe0cf0e9 | 46 | * Redistribution and use in source and binary forms, with or without |
ashleymills | 0:ff9ebe0cf0e9 | 47 | * modification, are permitted provided that the following conditions |
ashleymills | 0:ff9ebe0cf0e9 | 48 | * are met: |
ashleymills | 0:ff9ebe0cf0e9 | 49 | * 1. Redistributions of source code must retain the above copyright |
ashleymills | 0:ff9ebe0cf0e9 | 50 | * notice, this list of conditions and the following disclaimer. |
ashleymills | 0:ff9ebe0cf0e9 | 51 | * 2. Redistributions in binary form must reproduce the above copyright |
ashleymills | 0:ff9ebe0cf0e9 | 52 | * notice, this list of conditions and the following disclaimer in the |
ashleymills | 0:ff9ebe0cf0e9 | 53 | * documentation and/or other materials provided with the distribution. |
ashleymills | 0:ff9ebe0cf0e9 | 54 | * 3. Neither the name of the Institute nor the names of its contributors |
ashleymills | 0:ff9ebe0cf0e9 | 55 | * may be used to endorse or promote products derived from this software |
ashleymills | 0:ff9ebe0cf0e9 | 56 | * without specific prior written permission. |
ashleymills | 0:ff9ebe0cf0e9 | 57 | * |
ashleymills | 0:ff9ebe0cf0e9 | 58 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
ashleymills | 0:ff9ebe0cf0e9 | 59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ashleymills | 0:ff9ebe0cf0e9 | 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
ashleymills | 0:ff9ebe0cf0e9 | 61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
ashleymills | 0:ff9ebe0cf0e9 | 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ashleymills | 0:ff9ebe0cf0e9 | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
ashleymills | 0:ff9ebe0cf0e9 | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ashleymills | 0:ff9ebe0cf0e9 | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
ashleymills | 0:ff9ebe0cf0e9 | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
ashleymills | 0:ff9ebe0cf0e9 | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
ashleymills | 0:ff9ebe0cf0e9 | 68 | * SUCH DAMAGE. |
ashleymills | 0:ff9ebe0cf0e9 | 69 | * |
ashleymills | 0:ff9ebe0cf0e9 | 70 | * This file is part of the Contiki operating system. |
ashleymills | 0:ff9ebe0cf0e9 | 71 | * |
ashleymills | 0:ff9ebe0cf0e9 | 72 | * Author: Adam Dunkels <adam@sics.se> |
ashleymills | 0:ff9ebe0cf0e9 | 73 | * |
ashleymills | 0:ff9ebe0cf0e9 | 74 | * $ Id: list.h,v 1.5 2010/09/13 13:31:00 adamdunkels Exp $ |
ashleymills | 0:ff9ebe0cf0e9 | 75 | */ |
ashleymills | 0:ff9ebe0cf0e9 | 76 | |
ashleymills | 0:ff9ebe0cf0e9 | 77 | typedef void **list_t; |
ashleymills | 0:ff9ebe0cf0e9 | 78 | struct list { |
ashleymills | 0:ff9ebe0cf0e9 | 79 | struct list *next; |
ashleymills | 0:ff9ebe0cf0e9 | 80 | }; |
ashleymills | 0:ff9ebe0cf0e9 | 81 | |
ashleymills | 0:ff9ebe0cf0e9 | 82 | #define LIST_CONCAT(s1, s2) s1##s2 |
ashleymills | 0:ff9ebe0cf0e9 | 83 | |
ashleymills | 0:ff9ebe0cf0e9 | 84 | #define LIST_STRUCT(name) \ |
ashleymills | 0:ff9ebe0cf0e9 | 85 | void *LIST_CONCAT(name, _list); \ |
ashleymills | 0:ff9ebe0cf0e9 | 86 | list_t name |
ashleymills | 0:ff9ebe0cf0e9 | 87 | |
ashleymills | 0:ff9ebe0cf0e9 | 88 | #define LIST_STRUCT_INIT(struct_ptr, name) { \ |
ashleymills | 0:ff9ebe0cf0e9 | 89 | (struct_ptr)->name = &((struct_ptr)->LIST_CONCAT(name,_list)); \ |
ashleymills | 0:ff9ebe0cf0e9 | 90 | (struct_ptr)->LIST_CONCAT(name,_list) = NULL; \ |
ashleymills | 0:ff9ebe0cf0e9 | 91 | } |
ashleymills | 0:ff9ebe0cf0e9 | 92 | |
ashleymills | 0:ff9ebe0cf0e9 | 93 | static inline void * |
ashleymills | 0:ff9ebe0cf0e9 | 94 | list_head(list_t list) { |
ashleymills | 0:ff9ebe0cf0e9 | 95 | return *list; |
ashleymills | 0:ff9ebe0cf0e9 | 96 | } |
ashleymills | 0:ff9ebe0cf0e9 | 97 | |
ashleymills | 0:ff9ebe0cf0e9 | 98 | static inline void |
ashleymills | 0:ff9ebe0cf0e9 | 99 | list_remove(list_t list, void *item) { |
ashleymills | 0:ff9ebe0cf0e9 | 100 | LL_DELETE(*(struct list **)list, (struct list *)item); |
ashleymills | 0:ff9ebe0cf0e9 | 101 | } |
ashleymills | 0:ff9ebe0cf0e9 | 102 | |
ashleymills | 0:ff9ebe0cf0e9 | 103 | static inline void |
ashleymills | 0:ff9ebe0cf0e9 | 104 | list_add(list_t list, void *item) { |
ashleymills | 0:ff9ebe0cf0e9 | 105 | list_remove(list, item); |
ashleymills | 0:ff9ebe0cf0e9 | 106 | LL_APPEND(*(struct list **)list, (struct list *)item); |
ashleymills | 0:ff9ebe0cf0e9 | 107 | } |
ashleymills | 0:ff9ebe0cf0e9 | 108 | |
ashleymills | 0:ff9ebe0cf0e9 | 109 | static inline void |
ashleymills | 0:ff9ebe0cf0e9 | 110 | list_push(list_t list, void *item) { |
ashleymills | 0:ff9ebe0cf0e9 | 111 | LL_PREPEND(*(struct list **)list, (struct list *)item); |
ashleymills | 0:ff9ebe0cf0e9 | 112 | } |
ashleymills | 0:ff9ebe0cf0e9 | 113 | |
ashleymills | 0:ff9ebe0cf0e9 | 114 | static inline void * |
ashleymills | 0:ff9ebe0cf0e9 | 115 | list_pop(list_t list) { |
ashleymills | 0:ff9ebe0cf0e9 | 116 | struct list *l; |
ashleymills | 0:ff9ebe0cf0e9 | 117 | l = (struct list*)*list; |
ashleymills | 0:ff9ebe0cf0e9 | 118 | if(l) |
ashleymills | 0:ff9ebe0cf0e9 | 119 | list_remove(list, l); |
ashleymills | 0:ff9ebe0cf0e9 | 120 | |
ashleymills | 0:ff9ebe0cf0e9 | 121 | return l; |
ashleymills | 0:ff9ebe0cf0e9 | 122 | } |
ashleymills | 0:ff9ebe0cf0e9 | 123 | |
ashleymills | 0:ff9ebe0cf0e9 | 124 | static inline void |
ashleymills | 0:ff9ebe0cf0e9 | 125 | list_insert(list_t list, void *previtem, void *newitem) { |
ashleymills | 0:ff9ebe0cf0e9 | 126 | if(previtem == NULL) { |
ashleymills | 0:ff9ebe0cf0e9 | 127 | list_push(list, newitem); |
ashleymills | 0:ff9ebe0cf0e9 | 128 | } else { |
ashleymills | 0:ff9ebe0cf0e9 | 129 | ((struct list *)newitem)->next = ((struct list *)previtem)->next; |
ashleymills | 0:ff9ebe0cf0e9 | 130 | ((struct list *)previtem)->next = (struct list*)newitem; |
ashleymills | 0:ff9ebe0cf0e9 | 131 | } |
ashleymills | 0:ff9ebe0cf0e9 | 132 | } |
ashleymills | 0:ff9ebe0cf0e9 | 133 | |
ashleymills | 0:ff9ebe0cf0e9 | 134 | static inline void * |
ashleymills | 0:ff9ebe0cf0e9 | 135 | list_item_next(void *item) |
ashleymills | 0:ff9ebe0cf0e9 | 136 | { |
ashleymills | 0:ff9ebe0cf0e9 | 137 | return item == NULL? NULL: ((struct list *)item)->next; |
ashleymills | 0:ff9ebe0cf0e9 | 138 | } |
ashleymills | 0:ff9ebe0cf0e9 | 139 | |
ashleymills | 0:ff9ebe0cf0e9 | 140 | #else /* WITH_CONTIKI */ |
ashleymills | 0:ff9ebe0cf0e9 | 141 | #include "list.h" |
ashleymills | 0:ff9ebe0cf0e9 | 142 | #endif /* WITH_CONTIKI */ |
ashleymills | 0:ff9ebe0cf0e9 | 143 | |
ashleymills | 0:ff9ebe0cf0e9 | 144 | #endif /* _DTLS_LIST_H_ */ |
ashleymills | 0:ff9ebe0cf0e9 | 145 |