spandsp  0.0.6
queue.h File Reference

Go to the source code of this file.

Macros

#define QUEUE_READ_ATOMIC   0x0001
 
#define QUEUE_WRITE_ATOMIC   0x0002
 
#define QUEUE_STATE_T_SIZE(len)   (sizeof(queue_state_t) + len + 1)
 

Typedefs

typedef struct queue_state_s queue_state_t
 

Functions

int queue_empty (queue_state_t *s)
 Check if a queue is empty. More...
 
int queue_free_space (queue_state_t *s)
 Check available free space. More...
 
int queue_contents (queue_state_t *s)
 Check the contents of a queue. More...
 
void queue_flush (queue_state_t *s)
 Flush the contents of a queue. More...
 
int queue_view (queue_state_t *s, uint8_t *buf, int len)
 Copy bytes from a queue. More...
 
int queue_read (queue_state_t *s, uint8_t *buf, int len)
 Read bytes from a queue. More...
 
int queue_read_byte (queue_state_t *s)
 Read a byte from a queue. More...
 
int queue_write (queue_state_t *s, const uint8_t *buf, int len)
 Write bytes to a queue. More...
 
int queue_write_byte (queue_state_t *s, uint8_t byte)
 Write a byte to a queue. More...
 
int queue_state_test_msg (queue_state_t *s)
 Test message length. More...
 
int queue_read_msg (queue_state_t *s, uint8_t *buf, int len)
 Read a message from a queue. More...
 
int queue_write_msg (queue_state_t *s, const uint8_t *buf, int len)
 Write a message to a queue. More...
 
queue_state_tqueue_init (queue_state_t *s, int len, int flags)
 Initialise a queue. More...
 
int queue_release (queue_state_t *s)
 Release a queue. More...
 
int queue_free (queue_state_t *s)
 Delete a queue. More...
 

Macro Definition Documentation

◆ QUEUE_READ_ATOMIC

#define QUEUE_READ_ATOMIC   0x0001

Flag bit to indicate queue reads are atomic operations. This must be set if the queue is to be used with the message oriented functions.

◆ QUEUE_WRITE_ATOMIC

#define QUEUE_WRITE_ATOMIC   0x0002

Flag bit to indicate queue writes are atomic operations. This must be set if the queue is to be used with the message oriented functions.

Referenced by queue_write_byte().

Typedef Documentation

◆ queue_state_t

typedef struct queue_state_s queue_state_t

Queue descriptor. This defines the working state for a single instance of a byte stream or message oriented queue.

Function Documentation

◆ queue_contents()

int queue_contents ( queue_state_t s)

Check the contents of a queue.

Check the contents of a queue.

Parameters
sThe queue context.
Returns
The number of bytes in the queue.

◆ queue_empty()

int queue_empty ( queue_state_t s)

Check if a queue is empty.

Check if a queue is empty.

Parameters
sThe queue context.
Returns
TRUE if empty, else FALSE.

References queue_state_s::iptr, and queue_state_s::optr.

◆ queue_flush()

void queue_flush ( queue_state_t s)

Flush the contents of a queue.

Flush the contents of a queue.

Parameters
sThe queue context.

References queue_state_s::iptr, and queue_state_s::optr.

◆ queue_free()

int queue_free ( queue_state_t s)

Delete a queue.

Free a queue.

Parameters
sThe queue context.
Returns
0 if OK, else -1.

Referenced by v8_free(), and v8_release().

◆ queue_free_space()

int queue_free_space ( queue_state_t s)

Check available free space.

Check the available free space in a queue's buffer.

Parameters
sThe queue context.
Returns
The number of bytes of free space.

◆ queue_init()

queue_state_t* queue_init ( queue_state_t s,
int  len,
int  flags 
)

Initialise a queue.

Initialise a queue.

Parameters
sThe queue context. If is imperative that the context this points to is immediately followed by a buffer of the required size + 1 octet.
lenThe length of the queue's buffer.
flagsFlags controlling the operation of the queue. Valid flags are QUEUE_READ_ATOMIC and QUEUE_WRITE_ATOMIC.
Returns
A pointer to the context if OK, else NULL.

◆ queue_read()

int queue_read ( queue_state_t s,
uint8_t *  buf,
int  len 
)

Read bytes from a queue.

Read bytes from a queue.

Parameters
sThe queue context.
bufThe buffer into which the bytes will be read.
lenThe length of the buffer.
Returns
the number of bytes returned.

◆ queue_read_byte()

int queue_read_byte ( queue_state_t s)

Read a byte from a queue.

Read a byte from a queue.

Parameters
sThe queue context.
Returns
the byte, or -1 if the queue is empty.

References queue_state_s::iptr, queue_state_s::len, and queue_state_s::optr.

◆ queue_read_msg()

int queue_read_msg ( queue_state_t s,
uint8_t *  buf,
int  len 
)

Read a message from a queue.

Read a message from a queue. If the message is longer than the buffer provided, only the first len bytes of the message will be returned. The remainder of the message will be discarded.

Parameters
sThe queue context.
bufThe buffer into which the message will be read.
lenThe length of the buffer.
Returns
The number of bytes returned. If there are no messages in the queue, -1 is returned.

◆ queue_release()

int queue_release ( queue_state_t s)

Release a queue.

Release a queue.

Parameters
sThe queue context.
Returns
0 if OK, else -1.

◆ queue_state_test_msg()

int queue_state_test_msg ( queue_state_t s)

Test message length.

Test the length of the message at the head of a queue.

Parameters
sThe queue context.
Returns
The length of the next message, in byte. If there are no messages in the queue, -1 is returned.

References queue_view().

◆ queue_view()

int queue_view ( queue_state_t s,
uint8_t *  buf,
int  len 
)

Copy bytes from a queue.

Copy bytes from a queue. This is similar to queue_read, but the data remains in the queue.

Parameters
sThe queue context.
bufThe buffer into which the bytes will be read.
lenThe length of the buffer.
Returns
the number of bytes returned.

Referenced by queue_state_test_msg().

◆ queue_write()

int queue_write ( queue_state_t s,
const uint8_t *  buf,
int  len 
)

Write bytes to a queue.

Write bytes to a queue.

Parameters
sThe queue context.
bufThe buffer containing the bytes to be written.
lenThe length of the buffer.
Returns
the number of bytes actually written.

◆ queue_write_byte()

int queue_write_byte ( queue_state_t s,
uint8_t  byte 
)

Write a byte to a queue.

Write a byte to a queue.

Parameters
sThe queue context.
byteThe byte to be written.
Returns
the number of bytes actually written.

References queue_state_s::flags, queue_state_s::iptr, queue_state_s::len, queue_state_s::optr, and QUEUE_WRITE_ATOMIC.

◆ queue_write_msg()

int queue_write_msg ( queue_state_t s,
const uint8_t *  buf,
int  len 
)

Write a message to a queue.

Write a message to a queue.

Parameters
sThe queue context.
bufThe buffer from which the message will be written.
lenThe length of the message.
Returns
The number of bytes actually written.