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