Libtrap: Internal development docs  0.11.7
Macros | Functions
Input IFC

Macros

#define TB_FILL_START(rdb, bl, res)
 
#define TB_FILL_END(rdb, bl, s)
 

Functions

int tb_getmess (trap_buffer_t *tb, const void **data, uint16_t *size)
 
void tb_first_rd_block (trap_buffer_t *tb)
 
void tb_next_rd_block (trap_buffer_t *tb)
 

Detailed Description

A set of functions used for input IFC (module receives messages).

Macro Definition Documentation

◆ TB_FILL_END

#define TB_FILL_END (   rdb,
  bl,
 
)
Value:
do { \
bl->data->size = s; \
bl->write_data += s; \
bl->read_data = bl->data->data; \
tb_block_unlock(bl); \
} while (0)

Unlock the current free block after writing its content.

It MUST NOT be called when TB_FILL_START() returned TB_FULL.

Parameters
[in]rdbPointer to the buffer.
[in]blPointer to block (tb_block_t *bl).
[in]sSize of data written into the block. This will be set into header.

Definition at line 386 of file trap_buffer.h.

◆ TB_FILL_START

#define TB_FILL_START (   rdb,
  bl,
  res 
)
Value:
do { \
tb_lock(rdb); \
(*bl) = rdb->cur_wr_block; \
tb_block_lock(*bl); \
if (tb_isblockfree(*bl) == TB_SUCCESS) { \
tb_next_wr_block(rdb); \
(res) = TB_SUCCESS; \
} else { \
/* current block is not free, we must unlock and wait */ \
tb_block_unlock(*bl); \
(res) = TB_FULL; \
} \
tb_unlock(rdb); \
} while (0)
#define TB_SUCCESS
Definition: trap_buffer.h:53
#define TB_FULL
Definition: trap_buffer.h:55
int tb_isblockfree(tb_block_t *bl)
Definition: trap_buffer.c:137

Lock the current free block for writing its content.

After this code, it is possible to write size and data into bl. See TB_FILL_END() for unlocking the block.

Pseudocode: trap_buffer_t *b = tb_init(10, 100000); tb_block_t *bl; TB_FILL_START(b, &bl, res); if (res == TB_SUCCESS) { s = recv(...); TB_FILL_END(b, bl, s); }

Parameters
[in]rdbPointer to the buffer.
[out]blPointer to block (tb_block_t **bl).
[out]resResult of TB_FILL_START(), it is set to TB_SUCCESS or TB_FULL.

Definition at line 362 of file trap_buffer.h.

Function Documentation

◆ tb_first_rd_block()

void tb_first_rd_block ( trap_buffer_t tb)

Move to the first block for reading.

This function moves cur_block pointer to the first block.

Parameters
[in]tbPointer to the buffer.

Definition at line 123 of file trap_buffer.c.

◆ tb_getmess()

int tb_getmess ( trap_buffer_t tb,
const void **  data,
uint16_t *  size 
)

Get message from buffer.

Parameters
[in]tbPointer to the buffer.
[out]dataPointer to read message.
[out]sizeSize of read message.
Returns
TB_SUCCESS or TB_USED_NEWBLOCK when the message was read successfuly, TB_EMPTY when there is no message in the buffer to read. TB_USED_NEWBLOCK indicates that the current block was changed

Definition at line 323 of file trap_buffer.c.

◆ tb_next_rd_block()

void tb_next_rd_block ( trap_buffer_t tb)

Move to the next block for reading.

This function moves cur_block pointer to the next block (it overflows after nblocks).

Parameters
[in]tbPointer to the buffer.

Definition at line 113 of file trap_buffer.c.