Astarte Device SDK ESP32
ESP32 device SDK for the Astarte platform
astarte_list.h
1
/*
2
* (C) Copyright 2018, Davide Bettio, davide@uninstall.it.
3
*
4
* SPDX-License-Identifier: LGPL-2.1+ OR Apache-2.0
5
*/
6
7
#ifndef _ASTARTE_LIST_H_
8
#define _ASTARTE_LIST_H_
9
10
#include <stdbool.h>
11
#include <stdlib.h>
12
13
struct
astarte_list_head_t
14
{
15
struct
astarte_list_head_t
*next;
16
struct
astarte_list_head_t
*prev;
17
};
18
19
struct
astarte_ptr_list_entry_t
20
{
21
struct
astarte_list_head_t
head;
22
const
void
*value;
23
};
24
31
#define GET_LIST_ENTRY(list_item, type, list_head_member) \
32
((type *) (((char *) (list_item)) - ((unsigned long) &((type *) 0)->list_head_member)))
33
39
#define LIST_FOR_EACH(item, head) for (item = (head)->next; item != (head); item = item->next)
40
47
#define MUTABLE_LIST_FOR_EACH(item, tmp, head) \
48
for (item = (head)->next, tmp = item->next; item != (head); item = tmp, tmp = item->next)
49
58
static
inline
void
astarte_list_insert(
struct
astarte_list_head_t
*new_item,
59
struct
astarte_list_head_t
*prev_head,
struct
astarte_list_head_t
*next_head)
60
{
61
new_item->prev = prev_head;
62
new_item->next = next_head;
63
next_head->prev = new_item;
64
prev_head->next = new_item;
65
}
66
76
static
inline
void
astarte_list_append(
77
struct
astarte_list_head_t
*head,
struct
astarte_list_head_t
*new_item)
78
{
79
astarte_list_insert(new_item, head->prev, head);
80
}
81
89
static
inline
void
astarte_list_prepend(
90
struct
astarte_list_head_t
*head,
struct
astarte_list_head_t
*new_item)
91
{
92
astarte_list_insert(new_item, head, head->next);
93
}
94
103
static
inline
void
astarte_list_remove(
struct
astarte_list_head_t
*remove_item)
104
{
105
remove_item->prev->next = remove_item->next;
106
remove_item->next->prev = remove_item->prev;
107
}
108
115
static
inline
void
astarte_list_init(
struct
astarte_list_head_t
*head)
116
{
117
head->prev = head;
118
head->next = head;
119
}
120
127
static
inline
bool
astarte_list_is_empty(
struct
astarte_list_head_t
*list_item)
128
{
129
return
(list_item->next == list_item) && (list_item->prev == list_item);
130
}
131
139
static
inline
struct
astarte_list_head_t
*astarte_list_first(
struct
astarte_list_head_t
*head)
140
{
141
return
head->next;
142
}
143
151
static
inline
struct
astarte_list_head_t
*astarte_list_last(
struct
astarte_list_head_t
*head)
152
{
153
return
head->prev;
154
}
155
156
#endif
astarte_list_head_t
Definition:
astarte_list.h:14
astarte_ptr_list_entry_t
Definition:
astarte_list.h:20
include
astarte_list.h
Generated by
1.9.1