Libtrap: Internal development docs  0.11.7
Macros | Functions
Output IFC

Macros

#define TB_FLUSH_START(wrb, bl, res)
 
#define TB_FLUSH_END(rdb, bl, s)
 

Functions

int tb_pushmess (trap_buffer_t *tb, const void *data, uint16_t size)
 
int tb_pushmess2 (trap_buffer_t *tb, const void *d1, uint16_t s1, const void *d2, uint16_t s2)
 
void tb_clear_unused (trap_buffer_t *tb)
 
void tb_next_wr_block (trap_buffer_t *tb)
 
void tb_first_wr_block (trap_buffer_t *tb)
 

Detailed Description

A set of functions used for output IFC (module sends messages).

Macro Definition Documentation

◆ TB_FLUSH_END

#define TB_FLUSH_END (   rdb,
  bl,
 
)
Value:
do { \
if (bl->refcount == 0) { \
/* block can be marked as empty for next pushmess() */ \
bl->data->size = 0; \
tb_next_rd_block(rdb); \
} \
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 296 of file trap_buffer.h.

◆ TB_FLUSH_START

#define TB_FLUSH_START (   wrb,
  bl,
  res 
)
Value:
do { \
tb_lock(wrb); \
(*bl) = wrb->cur_rd_block; \
tb_block_lock(*bl); \
if (tb_isblockfree(*bl) != TB_FULL) { \
/* current block is not free, we must unlock and wait */ \
tb_block_unlock(*bl); \
res = TB_EMPTY; \
} else { \
res = TB_FULL; \
} \
tb_unlock(wrb); \
} while (0)
#define TB_EMPTY
Definition: trap_buffer.h:57
#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 getting its content.

After this code, it is possible to read size and data from bl. See TB_FLUSH_START() 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]wrbPointer 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 273 of file trap_buffer.h.

Function Documentation

◆ tb_clear_unused()

void tb_clear_unused ( trap_buffer_t tb)

Go through all blocks and those which are not used (refcount) mark as free.

Parameters
[in]tbPointer to the TRAP buffer.

Definition at line 357 of file trap_buffer.c.

◆ tb_first_wr_block()

void tb_first_wr_block ( trap_buffer_t tb)

Move to the first block for writing.

This function moves cur_block pointer to the first block.

Parameters
[in]tbPointer to the TRAP buffer

Definition at line 130 of file trap_buffer.c.

◆ tb_next_wr_block()

void tb_next_wr_block ( trap_buffer_t tb)

Move to the next block for writing.

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

Parameters
[in]tbPointer to the TRAP buffer

Definition at line 103 of file trap_buffer.c.

◆ tb_pushmess()

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

Push message into the current block

Parameters
[in]tbPointer to the buffer.
[in]dataPointer to the message to send.
[in]sizeSize of the message to send.
Returns
TB_SUCCESS or TB_USED_NEWBLOCK when the message was stored successfuly, TB_FULL when there is no place for the message. TB_USED_NEWBLOCK indicates that the current block was changed. TB_ERROR means that size is bigger than block size.

Definition at line 262 of file trap_buffer.c.

◆ tb_pushmess2()

int tb_pushmess2 ( trap_buffer_t tb,
const void *  d1,
uint16_t  s1,
const void *  d2,
uint16_t  s2 
)

Push message (consisting of d1 and d2 parts) into the current block

Parameters
[in]tbPointer to the buffer.
[in]d1Pointer to the 1st part of the message to send.
[in]s1Size of the 1st part of the message to send.
[in]d2Pointer to the 2nd part of the message to send.
[in]s2Size of the 2nd part of the message to send.
Returns
TB_SUCCESS or TB_USED_NEWBLOCK when the message was stored successfuly, TB_FULL when there is no place for the message. TB_USED_NEWBLOCK indicates that the current block was changed. TB_ERROR means that size is bigger than block size.

Definition at line 291 of file trap_buffer.c.