dbus-list.h
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* dbus-list.h Generic linked list utility (internal to D-Bus implementation)
*
* Copyright (C) 2002, 2003 Red Hat, Inc.
*
* SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
*
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef DBUS_LIST_H
#define DBUS_LIST_H
#include <dbus/dbus-internals.h>
#include <dbus/dbus-memory.h>
#include <dbus/dbus-types.h>
#include <dbus/dbus-sysdeps.h>
DBUS_BEGIN_DECLS
struct DBusList
{
DBusList *prev;
DBusList *next;
void *data;
};
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_append (DBusList **list,
void *data);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_prepend (DBusList **list,
void *data);
dbus_bool_t _dbus_list_insert_before (DBusList **list,
DBusList *before_this_link,
void *data);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_insert_after (DBusList **list,
DBusList *after_this_link,
void *data);
DBUS_PRIVATE_EXPORT
void _dbus_list_insert_before_link (DBusList **list,
DBusList *before_this_link,
DBusList *link);
DBUS_PRIVATE_EXPORT
void _dbus_list_insert_after_link (DBusList **list,
DBusList *after_this_link,
DBusList *link);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_remove (DBusList **list,
void *data);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_remove_last (DBusList **list,
void *data);
DBUS_PRIVATE_EXPORT
void _dbus_list_remove_link (DBusList **list,
DBusList *link);
DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_find_last (DBusList **list,
void *data);
DBUS_PRIVATE_EXPORT
void _dbus_list_clear (DBusList **list);
DBUS_PRIVATE_EXPORT
void _dbus_list_clear_full (DBusList **list,
DBusFreeFunction function);
DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_get_first_link (DBusList **list);
DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_get_last_link (DBusList **list);
DBUS_PRIVATE_EXPORT
void* _dbus_list_get_last (DBusList **list);
DBUS_PRIVATE_EXPORT
void* _dbus_list_get_first (DBusList **list);
DBUS_PRIVATE_EXPORT
void* _dbus_list_pop_first (DBusList **list);
DBUS_PRIVATE_EXPORT
void* _dbus_list_pop_last (DBusList **list);
DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_pop_first_link (DBusList **list);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_copy (DBusList **list,
DBusList **dest);
DBUS_PRIVATE_EXPORT
int _dbus_list_get_length (DBusList **list);
DBUS_PRIVATE_EXPORT
DBusList* _dbus_list_alloc_link (void *data);
DBUS_PRIVATE_EXPORT
void _dbus_list_free_link (DBusList *link);
DBUS_PRIVATE_EXPORT
void _dbus_list_unlink (DBusList **list,
DBusList *link);
DBUS_PRIVATE_EXPORT
void _dbus_list_append_link (DBusList **list,
DBusList *link);
DBUS_PRIVATE_EXPORT
void _dbus_list_prepend_link (DBusList **list,
DBusList *link);
DBUS_PRIVATE_EXPORT
dbus_bool_t _dbus_list_length_is_one (DBusList **list);
DBUS_PRIVATE_EXPORT
void _dbus_list_foreach (DBusList **list,
DBusForeachFunction function,
void *data);
#define _dbus_list_get_next_link(list, link) ((link)->next == *(list) ? NULL : (link)->next)
#define _dbus_list_get_prev_link(list, link) ((link) == *(list) ? NULL : (link)->prev)
/* if DBUS_ENABLE_STATS */
DBUS_PRIVATE_EXPORT
void _dbus_list_get_stats (dbus_uint32_t *in_use_p,
dbus_uint32_t *in_free_list_p,
dbus_uint32_t *allocated_p);
DBUS_END_DECLS
#endif /* DBUS_LIST_H */
DBusForeachFunction
void(* DBusForeachFunction)(void *element, void *data)
Used to iterate over each item in a collection, such as a DBusList.
Definition dbus-internals.h:347
_dbus_list_get_first_link
DBUS_PRIVATE_EXPORT DBusList * _dbus_list_get_first_link(DBusList **list)
Gets the first link in the list.
Definition dbus-list.c:597
_dbus_list_insert_before_link
DBUS_PRIVATE_EXPORT void _dbus_list_insert_before_link(DBusList **list, DBusList *before_this_link, DBusList *link)
Inserts a link into the list before the given existing link.
Definition dbus-list.c:379
_dbus_list_copy
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_copy(DBusList **list, DBusList **dest)
Copies a list.
Definition dbus-list.c:727
_dbus_list_pop_first_link
DBUS_PRIVATE_EXPORT DBusList * _dbus_list_pop_first_link(DBusList **list)
Removes the first link in the list and returns it.
Definition dbus-list.c:658
_dbus_list_length_is_one
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_length_is_one(DBusList **list)
Check whether length is exactly one.
Definition dbus-list.c:813
_dbus_list_get_last
DBUS_PRIVATE_EXPORT void * _dbus_list_get_last(DBusList **list)
Gets the last data in the list.
Definition dbus-list.c:626
_dbus_list_remove
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_remove(DBusList **list, void *data)
Removes a value from the list.
Definition dbus-list.c:418
_dbus_list_append_link
DBUS_PRIVATE_EXPORT void _dbus_list_append_link(DBusList **list, DBusList *link)
Appends a link to the list.
Definition dbus-list.c:318
_dbus_list_insert_after_link
DBUS_PRIVATE_EXPORT void _dbus_list_insert_after_link(DBusList **list, DBusList *after_this_link, DBusList *link)
Inserts a link into the list after the given existing link.
Definition dbus-list.c:397
_dbus_list_clear_full
DBUS_PRIVATE_EXPORT void _dbus_list_clear_full(DBusList **list, DBusFreeFunction function)
Free every link and every element in the list.
Definition dbus-list.c:570
_dbus_list_insert_after
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_insert_after(DBusList **list, DBusList *after_this_link, void *data)
Inserts data into the list after the given existing link.
Definition dbus-list.c:351
_dbus_list_remove_link
DBUS_PRIVATE_EXPORT void _dbus_list_remove_link(DBusList **list, DBusList *link)
Removes a link from the list.
Definition dbus-list.c:530
_dbus_list_get_first
DBUS_PRIVATE_EXPORT void * _dbus_list_get_first(DBusList **list)
Gets the first data in the list.
Definition dbus-list.c:642
_dbus_list_get_last_link
DBUS_PRIVATE_EXPORT DBusList * _dbus_list_get_last_link(DBusList **list)
Gets the last link in the list.
Definition dbus-list.c:610
_dbus_list_unlink
DBUS_PRIVATE_EXPORT void _dbus_list_unlink(DBusList **list, DBusList *link)
Removes the given link from the list, but doesn't free it.
Definition dbus-list.c:502
_dbus_list_find_last
DBUS_PRIVATE_EXPORT DBusList * _dbus_list_find_last(DBusList **list, void *data)
Finds a value in the list.
Definition dbus-list.c:475
_dbus_list_pop_last
DBUS_PRIVATE_EXPORT void * _dbus_list_pop_last(DBusList **list)
Removes the last value in the list and returns it.
Definition dbus-list.c:702
_dbus_list_free_link
DBUS_PRIVATE_EXPORT void _dbus_list_free_link(DBusList *link)
Frees a linked list node allocated with _dbus_list_alloc_link.
Definition dbus-list.c:257
_dbus_list_pop_first
DBUS_PRIVATE_EXPORT void * _dbus_list_pop_first(DBusList **list)
Removes the first value in the list and returns it.
Definition dbus-list.c:679
_dbus_list_foreach
DBUS_PRIVATE_EXPORT void _dbus_list_foreach(DBusList **list, DBusForeachFunction function, void *data)
Calls the given function for each element in the list.
Definition dbus-list.c:789
_dbus_list_get_length
DBUS_PRIVATE_EXPORT int _dbus_list_get_length(DBusList **list)
Gets the length of a list.
Definition dbus-list.c:760
_dbus_list_clear
DBUS_PRIVATE_EXPORT void _dbus_list_clear(DBusList **list)
Frees all links in the list and sets the list head to NULL.
Definition dbus-list.c:545
_dbus_list_prepend_link
DBUS_PRIVATE_EXPORT void _dbus_list_prepend_link(DBusList **list, DBusList *link)
Prepends a link to the list.
Definition dbus-list.c:336
_dbus_list_prepend
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_prepend(DBusList **list, void *data)
Prepends a value to the list.
Definition dbus-list.c:295
_dbus_list_alloc_link
DBUS_PRIVATE_EXPORT DBusList * _dbus_list_alloc_link(void *data)
Allocates a linked list node.
Definition dbus-list.c:245
_dbus_list_remove_last
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_remove_last(DBusList **list, void *data)
Removes a value from the list.
Definition dbus-list.c:449
_dbus_list_append
DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_list_append(DBusList **list, void *data)
Appends a value to the list.
Definition dbus-list.c:273
DBUS_BEGIN_DECLS
#define DBUS_BEGIN_DECLS
Macro used prior to declaring functions in the D-Bus header files.
Definition dbus-macros.h:36
DBUS_END_DECLS
#define DBUS_END_DECLS
Macro used after declaring functions in the D-Bus header files.
Definition dbus-macros.h:37
DBusFreeFunction
void(* DBusFreeFunction)(void *memory)
The type of a function which frees a block of memory.
Definition dbus-memory.h:65
dbus_uint32_t
unsigned int dbus_uint32_t
A 32-bit unsigned integer on all platforms.
Definition dbus-arch-deps.h:45
dbus_bool_t
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition dbus-types.h:37
DBusList
A node in a linked list.
Definition dbus-list.h:37
DBusList::data
void * data
Data stored at this element.
Definition dbus-list.h:40
DBusList::next
DBusList * next
Next list node.
Definition dbus-list.h:39
DBusList::prev
DBusList * prev
Previous list node.
Definition dbus-list.h:38