Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / src / shared / queue.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2012-2014  Intel Corporation. All rights reserved.
6  *
7  *
8  *  This library is free software; you can redistribute it and/or
9  *  modify it under the terms of the GNU Lesser General Public
10  *  License as published by the Free Software Foundation; either
11  *  version 2.1 of the License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #include <stdbool.h>
25
26 typedef void (*queue_destroy_func_t)(void *data);
27
28 struct queue;
29
30 struct queue_entry {
31         void *data;
32         struct queue_entry *next;
33 };
34
35 struct queue *queue_new(void);
36 void queue_destroy(struct queue *queue, queue_destroy_func_t destroy);
37
38 bool queue_push_tail(struct queue *queue, void *data);
39 bool queue_push_head(struct queue *queue, void *data);
40 bool queue_push_after(struct queue *queue, void *entry, void *data);
41 void *queue_pop_head(struct queue *queue);
42 void *queue_peek_head(struct queue *queue);
43 void *queue_peek_tail(struct queue *queue);
44
45 typedef void (*queue_foreach_func_t)(void *data, void *user_data);
46
47 void queue_foreach(struct queue *queue, queue_foreach_func_t function,
48                                                         void *user_data);
49
50 typedef bool (*queue_match_func_t)(const void *data, const void *match_data);
51
52 void *queue_find(struct queue *queue, queue_match_func_t function,
53                                                         const void *match_data);
54
55 bool queue_remove(struct queue *queue, void *data);
56 void *queue_remove_if(struct queue *queue, queue_match_func_t function,
57                                                         void *user_data);
58 unsigned int queue_remove_all(struct queue *queue, queue_match_func_t function,
59                                 void *user_data, queue_destroy_func_t destroy);
60
61 const struct queue_entry *queue_get_entries(struct queue *queue);
62
63 unsigned int queue_length(struct queue *queue);
64 bool queue_isempty(struct queue *queue);