JackUtils 0.5
Provides simplified Jack API for clients :)
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
Jack Utils FIFO Buffer API

Data Structures

struct  ju_buff_s
 FIFO Buffer internal structure. More...
 

Typedefs

typedef struct ju_buff_s ju_buff_t
 typedef wrapper around buffer structure
 

Functions

JBU_API void() ju_buff_init (ju_buff_t *b, size_t s)
 Initializes buffer structure. More...
 
JBU_API void() ju_buff_uninit (ju_buff_t *b)
 Deinitializes buffer structure. More...
 
JBU_API void() ju_buff_resize (ju_buff_t *b, size_t s)
 Resizes buffer structure. More...
 
JBU_API void() ju_buff_check_size (ju_buff_t *b, size_t s)
 Check size of buffer with requested, and resizes if there is not enough spce. More...
 
JBU_API void ju_buff_except (ju_buff_t *b, int(*cb)(ju_buff_t *, ju_ssize_t))
 Underflow/owerflow exception handling. More...
 
JBU_API size_t() ju_buff_size (ju_buff_t *b)
 Returns buffer summary size (used and unused). More...
 
JBU_API size_t() ju_buff_used (ju_buff_t *b)
 Returns size of buffer busy part. More...
 
JBU_API size_t() ju_buff_space (ju_buff_t *b)
 Returns size of buffer empity part. More...
 
JBU_API size_t() ju_buff_append (ju_buff_t *b, const void *src, size_t size)
 Adds data from array to te end of the buffer. More...
 
JBU_API size_t() ju_buff_fill (ju_buff_t *b, const void *src, size_t size, size_t n)
 Adds data from src array copied N times to the end of the buffer. More...
 
JBU_API size_t() ju_buff_remove (ju_buff_t *, void *dst, size_t size)
 Removes data from start of buffer to the dst array. More...
 
JBU_API void() ju_buff_move (ju_buff_t *, ju_ssize_t v)
 Moves buffer data forwards or backwards... More...
 
JBU_API size_t() ju_buff_read (ju_buff_t *, int fd, size_t)
 Similar to ju_buff_append(), but reads values from the file by descriptor.
 
JBU_API size_t() ju_buff_write (ju_buff_t *, int fd, size_t)
 Similar to ju_buff_remove(), but writes values to the the file by descriptor.
 
JBU_API void *() ju_buff_data (ju_buff_t *b)
 Returns buffer data from the beginning. More...
 
JBU_API void() ju_buff_lock (ju_buff_t *b)
 Locks buffer. More...
 
JBU_API void() ju_buff_unlock (ju_buff_t *b)
 Unlocks buffer. More...
 

Detailed Description

Function Documentation

◆ ju_buff_append()

JBU_API size_t() ju_buff_append ( ju_buff_t b,
const void *  src,
size_t  size 
)

Adds data from array to te end of the buffer.

Parameters
bbuffer.
srcsource array of bytes.
sizesize of the source array.
Returns
count of appended bytes

References ju_buff_space().

◆ ju_buff_check_size()

JBU_API void() ju_buff_check_size ( ju_buff_t b,
size_t  s 
)

Check size of buffer with requested, and resizes if there is not enough spce.

Parameters
bpointer on buffer structure.
srequested size of the buffer.

◆ ju_buff_data()

JBU_API void *() ju_buff_data ( ju_buff_t b)

Returns buffer data from the beginning.

Parameters
bbuffer
Returns
pointer on the data at the beginning of the buffer

◆ ju_buff_except()

JBU_API void ju_buff_except ( ju_buff_t b,
int(*)(ju_buff_t *, ju_ssize_t cb 
)

Underflow/owerflow exception handling.

Sets cb callback to be runned when exeption happens with buffer underflow(-) or owerflow(+) value. Callback may MOVE buffer data backward to give space for new data in case of owerflow(default), or do nothing. In case of underflow, callback may add zeros to buffer, or do nothing(default).

Or even callback may print error message, and do some stuff of course :) Callback underflow/overflow value will NEVER BE MORE THAN SIZE OF BUFFER!

if you did something, it's a good sign to return 0, else return nonzero value from callback;

Parameters
bbuffer
cbnew exception handler callback

◆ ju_buff_fill()

JBU_API size_t() ju_buff_fill ( ju_buff_t b,
const void *  src,
size_t  size,
size_t  n 
)

Adds data from src array copied N times to the end of the buffer.

Parameters
bbuffer.
srcsource array of bytes.
sizesize of the source array.
nhow much array duplicates?
Returns
count of appended bytes

References ju_buff_space().

◆ ju_buff_init()

JBU_API void() ju_buff_init ( ju_buff_t b,
size_t  s 
)

Initializes buffer structure.

Parameters
bpointer on buffer structure.
ssize of the buffer.

◆ ju_buff_lock()

JBU_API void() ju_buff_lock ( ju_buff_t b)

Locks buffer.

Parameters
bbuffer

If buffer is already locked, this function waits until it unlocks, lock it again and returns. This operation is atomary and threadsafe.

Don't forget to unlock buffer when you're done reading/writing and other buffer operations. Locking already locked buffer in the same thread causes to the DEADLOCK.

◆ ju_buff_move()

JBU_API void() ju_buff_move ( ju_buff_t b,
ju_ssize_t  v 
)

Moves buffer data forwards or backwards...

Parameters
bbuffer.
vmove steps with sign (+ forward) (-backward)

◆ ju_buff_remove()

JBU_API size_t() ju_buff_remove ( ju_buff_t b,
void *  dst,
size_t  size 
)

Removes data from start of buffer to the dst array.

Parameters
bbuffer.
dstdestination array of bytes.
sizehow many elements to put into the array.
Returns
count of removed bytes

References ju_buff_move().

◆ ju_buff_resize()

JBU_API void() ju_buff_resize ( ju_buff_t b,
size_t  s 
)

Resizes buffer structure.

Buffer must be initialized before!

Parameters
bpointer on buffer structure.
ssize of the buffer.

◆ ju_buff_size()

JBU_API size_t() ju_buff_size ( ju_buff_t b)

Returns buffer summary size (used and unused).

Parameters
bbuffer
Returns
buffer size

◆ ju_buff_space()

JBU_API size_t() ju_buff_space ( ju_buff_t b)

Returns size of buffer empity part.

Parameters
bbuffer
Returns
buffer free space size

◆ ju_buff_uninit()

JBU_API void() ju_buff_uninit ( ju_buff_t b)

Deinitializes buffer structure.

Parameters
bpointer on buffer structure.

◆ ju_buff_unlock()

JBU_API void() ju_buff_unlock ( ju_buff_t b)

Unlocks buffer.

Parameters
bbuffer

◆ ju_buff_used()

JBU_API size_t() ju_buff_used ( ju_buff_t b)

Returns size of buffer busy part.

Parameters
bbuffer
Returns
buffer used part size