tizen 2.3 release
[framework/connectivity/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 *queue_new(void);
31 void queue_destroy(struct queue *queue, queue_destroy_func_t destroy);
32
33 bool queue_push_tail(struct queue *queue, void *data);
34 bool queue_push_head(struct queue *queue, void *data);
35 void *queue_pop_head(struct queue *queue);
36 void *queue_peek_head(struct queue *queue);
37 void *queue_peek_tail(struct queue *queue);
38
39 typedef void (*queue_foreach_func_t)(void *data, void *user_data);
40
41 void queue_foreach(struct queue *queue, queue_foreach_func_t function,
42                                                         void *user_data);
43
44 typedef bool (*queue_match_func_t)(const void *a, const void *b);
45
46 void *queue_find(struct queue *queue, queue_match_func_t function,
47                                                         void *user_data);
48
49 void *queue_remove_if(struct queue *queue, queue_match_func_t function,
50                                                         void *user_data);
51 unsigned int queue_remove_all(struct queue *queue, queue_match_func_t function,
52                                 void *user_data, queue_destroy_func_t destroy);
53
54 unsigned int queue_length(struct queue *queue);
55 bool queue_isempty(struct queue *queue);