ble_gatt_client
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
queue.c File Reference

set of functions to manage queues More...

#include "util.h"
#include "queue.h"

Go to the source code of this file.

Data Structures

struct  queue
 

Functions

static struct queuequeue_ref (struct queue *queue)
 
static void queue_unref (struct queue *queue)
 
struct queuequeue_new (void)
 
void queue_destroy (struct queue *queue, queue_destroy_func_t destroy)
 
static struct queue_entryqueue_entry_ref (struct queue_entry *entry)
 
static void queue_entry_unref (struct queue_entry *entry)
 
static struct queue_entryqueue_entry_new (void *data)
 
bool queue_push_tail (struct queue *queue, void *data)
 
bool queue_push_head (struct queue *queue, void *data)
 
bool queue_push_after (struct queue *queue, void *entry, void *data)
 
void * queue_pop_head (struct queue *queue)
 
void * queue_peek_head (struct queue *queue)
 
void * queue_peek_tail (struct queue *queue)
 
void queue_foreach (struct queue *queue, queue_foreach_func_t function, void *user_data)
 
static bool direct_match (const void *a, const void *b)
 
void * queue_find (struct queue *queue, queue_match_func_t function, const void *match_data)
 
bool queue_remove (struct queue *queue, void *data)
 
void * queue_remove_if (struct queue *queue, queue_match_func_t function, void *user_data)
 
unsigned int queue_remove_all (struct queue *queue, queue_match_func_t function, void *user_data, queue_destroy_func_t destroy)
 
const struct queue_entryqueue_get_entries (struct queue *queue)
 
unsigned int queue_length (struct queue *queue)
 
bool queue_isempty (struct queue *queue)
 

Detailed Description

set of functions to manage queues

Author
Gilbert Brault

Definition in file queue.c.

Function Documentation

static bool direct_match ( const void *  a,
const void *  b 
)
static

compare a with b

Parameters
afirst parameter
bsecond parameter
Returns
true if both element match

Definition at line 362 of file queue.c.

Referenced by queue_find().

void queue_destroy ( struct queue queue,
queue_destroy_func_t  destroy 
)

destroy all queue structure elements

Parameters
queuepointer to the queue structure
destroyfunction making data deallocation

Definition at line 102 of file queue.c.

References queue_remove_all(), and queue_unref().

Referenced by attribute_destroy(), bt_att_free(), bt_gatt_client_free(), discovery_op_free(), gatt_db_destroy(), gatt_db_new(), and notify_chrc_free().

static struct queue_entry* queue_entry_new ( void *  data)
static

create a new queue, set queue->data to data, increment queue->ref_count

Parameters
data
Returns
new queue pointer

Definition at line 147 of file queue.c.

References queue_entry::data, new0, and queue_entry_ref().

Referenced by queue_push_after(), queue_push_head(), and queue_push_tail().

static struct queue_entry* queue_entry_ref ( struct queue_entry entry)
static

increment &entry->ref_count

Parameters
entry
Returns
entry

Definition at line 118 of file queue.c.

References queue_entry::ref_count.

Referenced by queue_entry_new(), and queue_foreach().

static void queue_entry_unref ( struct queue_entry entry)
static

decrement &entry->ref_count and free entry structure if ref_count == 0

Parameters
entry

Definition at line 133 of file queue.c.

References queue_entry::ref_count.

Referenced by queue_foreach(), queue_pop_head(), queue_remove(), queue_remove_all(), and queue_remove_if().

void* queue_find ( struct queue queue,
queue_match_func_t  function,
const void *  match_data 
)
Parameters
queuequeue pointer
functionfunction call to make comparison
match_datadata to match with queue entry
Returns
found entry and return pointer to user data (queued data) or NULL if not found

Definition at line 376 of file queue.c.

References queue_entry::data, direct_match(), queue::head, and queue_entry::next.

Referenced by bt_gatt_client_write_execute(), gatt_db_get_attribute(), gatt_db_get_service_with_uuid(), gatt_db_unregister(), get_reliable_request(), and register_notify().

void queue_foreach ( struct queue queue,
queue_foreach_func_t  function,
void *  user_data 
)

iterator for the queue

Parameters
queuequeue pointer
functionfunction(void *data, void *user_data) to call for each element
user_datauser pointer to pass to function

Definition at line 325 of file queue.c.

References queue_entry::data, queue::head, queue_entry::next, queue_entry_ref(), queue_entry_unref(), queue_ref(), queue_unref(), and queue::ref_count.

Referenced by disconnect_cb(), gatt_db_find_by_type(), gatt_db_find_by_type_value(), gatt_db_find_information(), gatt_db_foreach_service_in_range(), gatt_db_read_by_type(), notify_cb(), and notify_service_changed().

const struct queue_entry* queue_get_entries ( struct queue queue)

return queue head pointer

Parameters
queuequeue pointer
Returns
queue head

Definition at line 540 of file queue.c.

References queue::head.

Referenced by find_insert_loc(), gatt_db_read_by_group_type(), and handle_notify().

bool queue_isempty ( struct queue queue)

test if queue is empty

Parameters
queuequeue pointer
Returns

Definition at line 569 of file queue.c.

References queue::entries.

Referenced by cancel_long_write_cb(), discover_primary_cb(), gatt_db_isempty(), handle_notify(), notify_service_changed(), start_next_long_write(), and wakeup_writer().

unsigned int queue_length ( struct queue queue)

return queue length

Parameters
queuequeue pointer
Returns
return 0 or queue elements count

Definition at line 555 of file queue.c.

References queue::entries.

struct queue* queue_new ( void  )

create a new queue structure

Returns
queue reference

Definition at line 81 of file queue.c.

References queue::entries, queue::head, new0, queue_ref(), and queue::tail.

Referenced by bt_att_new(), bt_gatt_client_new(), discovery_op_create(), gatt_db_new(), new_attribute(), and notify_chrc_create().

void* queue_peek_head ( struct queue queue)

peek data from the head of the queue

Parameters
queuequeue pointer

Definition at line 297 of file queue.c.

References queue_entry::data, and queue::head.

void* queue_peek_tail ( struct queue queue)

peek data from the tail of the queue

Parameters
queuequeue pointer

Definition at line 310 of file queue.c.

References queue_entry::data, and queue::tail.

bool queue_push_after ( struct queue queue,
void *  entry,
void *  data 
)

push a queue entry allocated with data and set it after the entry

Parameters
queuequeue pointer where to allocate data
entryelement queue where to put the data after
datadata to queue
Returns

Definition at line 229 of file queue.c.

References queue_entry::data, queue::entries, queue::head, queue_entry::next, queue_entry_new(), and queue::tail.

Referenced by gatt_db_insert_service().

bool queue_push_head ( struct queue queue,
void *  data 
)

push a queue entry allocated with data and set it at the head of queue

Parameters
queuequeue pointer where to allocate data
datadata to queue
Returns

Definition at line 198 of file queue.c.

References queue::entries, queue::head, queue_entry::next, queue_entry_new(), and queue::tail.

Referenced by gatt_db_insert_service(), and handle_error_rsp().

bool queue_push_tail ( struct queue queue,
void *  data 
)
static struct queue* queue_ref ( struct queue queue)
static

increment &queue->ref_count

Parameters
queuepointer to the queue structure
Returns

Definition at line 53 of file queue.c.

References queue::ref_count.

Referenced by queue_foreach(), and queue_new().

bool queue_remove ( struct queue queue,
void *  data 
)

remove queue element holding data

Parameters
queuequeue pointer
datadata pointer
Returns
false if not found, true if element removed

Definition at line 402 of file queue.c.

References queue_entry::data, queue::entries, queue::head, queue_entry::next, queue_entry_unref(), and queue::tail.

Referenced by cancel_long_write_req(), enable_ccc_callback(), gatt_db_remove_service(), gatt_db_unregister(), read_timeout(), register_notify(), request_unref(), and write_timeout().

unsigned int queue_remove_all ( struct queue queue,
queue_match_func_t  function,
void *  user_data,
queue_destroy_func_t  destroy 
)

remove all queue element

Parameters
queuequeue pointer
functionfunction used to match data deallocation
user_datadata pointer used in deallocation function
destroyfunction for data deallocation
Returns
count of element destroyed (0 if none)

Definition at line 487 of file queue.c.

References queue_entry::data, queue::entries, queue::head, queue_entry::next, queue_entry_unref(), queue_remove_if(), and queue::tail.

Referenced by bt_att_cancel_all(), bt_att_unregister_all(), bt_gatt_client_cancel_all(), enable_ccc_callback(), gatt_client_remove_all_notify_in_range(), gatt_client_remove_notify_chrcs_in_range(), gatt_db_clear(), gatt_db_clear_range(), and queue_destroy().

void* queue_remove_if ( struct queue queue,
queue_match_func_t  function,
void *  user_data 
)

remove element match by function(void *data, void *match_data) where match_data = user_data

Parameters
queuequeue pointer
functionfunction call to make comparison
user_datadata to match queue element in function
Returns
NULL if not found or queue entry matching criteria

Definition at line 440 of file queue.c.

References queue_entry::data, queue::entries, queue::head, queue_entry::next, queue_entry_unref(), and queue::tail.

Referenced by bt_att_cancel(), bt_att_unregister(), bt_att_unregister_disconnect(), bt_gatt_client_cancel(), bt_gatt_client_unregister_notify(), gatt_db_attribute_read_result(), gatt_db_attribute_write_result(), and queue_remove_all().

static void queue_unref ( struct queue queue)
static

decrement &queue->ref_count and free queue structure if ref_count == 0

Parameters
queuepointer to the queue structure

Definition at line 68 of file queue.c.

References queue::ref_count.

Referenced by queue_destroy(), and queue_foreach().