Callback multiplexer

cb_mux provides utilities for storing, retrieving, and managing callback information in a singly linked list. More...

Detailed Description

cb_mux provides utilities for storing, retrieving, and managing callback information in a singly linked list.

If an API provides the ability to call multiple callbacks, cb_mux can simplify handling of an arbitrary number of callbacks by requiring memory for a cb_mux entry to be passed along with other arguments. The cb_mux entry is then attached to a list using cb_mux_add. The code implementing that API can manage the list using the various utility functions that cb_mux provides.

Files

file  cb_mux.h
 cb_mux interface definitions
 

Data Structures

struct  cb_mux
 cb_mux list entry structure More...
 

Typedefs

typedef unsigned int cb_mux_cbid_t
 cb_mux identifier type
 
typedef void(* cb_mux_cb_t) (void *)
 cb_mux callback type
 
typedef struct cb_mux cb_mux_t
 cb_mux list entry structure
 
typedef void(* cb_mux_iter_t) (cb_mux_t *, void *)
 cb_mux iterate function callback type for cb_mux_iter
 

Functions

void cb_mux_add (cb_mux_t **head, cb_mux_t *entry)
 Add a new entry to the end of a cb_mux list. More...
 
void cb_mux_del (cb_mux_t **head, cb_mux_t *entry)
 Remove a entry from a cb_mux list. More...
 
cb_mux_tcb_mux_find_cbid (cb_mux_t *head, cb_mux_cbid_t cbid_val)
 Find an entry in the list by ID. More...
 
cb_mux_tcb_mux_find_low (cb_mux_t *head)
 Find the entry with the lowest ID. More...
 
cb_mux_tcb_mux_find_high (cb_mux_t *head)
 Find the entry with the highest ID. More...
 
cb_mux_cbid_t cb_mux_find_free_id (cb_mux_t *head)
 Find the lowest unused ID. More...
 
void cb_mux_iter (cb_mux_t *head, cb_mux_iter_t func, void *arg)
 Run a function on every item in the cb_mux list. More...
 

Function Documentation

◆ cb_mux_add()

void cb_mux_add ( cb_mux_t **  head,
cb_mux_t entry 
)

Add a new entry to the end of a cb_mux list.

Parameters
[in]headdouble pointer to first list entry
[in]entryentry to add

◆ cb_mux_del()

void cb_mux_del ( cb_mux_t **  head,
cb_mux_t entry 
)

Remove a entry from a cb_mux list.

Parameters
[in]headdouble pointer to first list entry
[in]entryentry to remove

◆ cb_mux_find_cbid()

cb_mux_t* cb_mux_find_cbid ( cb_mux_t head,
cb_mux_cbid_t  cbid_val 
)

Find an entry in the list by ID.

Parameters
[in]headpointer to first list entry
[in]cbid_valID to find
Returns
pointer to the list entry

◆ cb_mux_find_free_id()

cb_mux_cbid_t cb_mux_find_free_id ( cb_mux_t head)

Find the lowest unused ID.

Returns highest possible ID on failure

Parameters
[in]headpointer to first list entry
Returns
lowest unused ID

◆ cb_mux_find_high()

cb_mux_t* cb_mux_find_high ( cb_mux_t head)

Find the entry with the highest ID.

If there are multiple hits, this returns the oldest.

Parameters
[in]headpointer to first list entry
Returns
pointer to the list entry

◆ cb_mux_find_low()

cb_mux_t* cb_mux_find_low ( cb_mux_t head)

Find the entry with the lowest ID.

If there are multiple hits, this returns the oldest.

Parameters
[in]headpointer to first list entry
Returns
pointer to the list entry

◆ cb_mux_iter()

void cb_mux_iter ( cb_mux_t head,
cb_mux_iter_t  func,
void *  arg 
)

Run a function on every item in the cb_mux list.

Parameters
[in]headpointer to first list entry
[in]funcfunction to run on each entry
[in]argargument for the function