libosmocore 1.9.0.196-9975
Osmocom core library
Osmocom ringbuffers for log strings

Files

file  strrb.h
 Osmocom string ringbuffer handling routines.
 

Data Structures

struct  osmo_strrb
 

Macros

#define RB_MAX_MESSAGE_SIZE   240
 A structure representing an osmocom string ringbuffer. More...
 

Functions

struct osmo_strrbosmo_strrb_create (void *talloc_ctx, size_t rb_size)
 Create an empty, initialized osmo_strrb. More...
 
bool osmo_strrb_is_empty (const struct osmo_strrb *rb)
 Check if an osmo_strrb is empty. More...
 
const char * osmo_strrb_get_nth (const struct osmo_strrb *rb, unsigned int string_index)
 Return a pointer to the Nth string in the osmo_strrb. More...
 
bool _osmo_strrb_is_bufindex_valid (const struct osmo_strrb *rb, unsigned int offset)
 
size_t osmo_strrb_elements (const struct osmo_strrb *rb)
 Count the number of log messages in an osmo_strrb. More...
 
int osmo_strrb_add (struct osmo_strrb *rb, const char *data)
 Add a string to the osmo_strrb. More...
 

Detailed Description

Macro Definition Documentation

◆ RB_MAX_MESSAGE_SIZE

#define RB_MAX_MESSAGE_SIZE   240

A structure representing an osmocom string ringbuffer.

Function Documentation

◆ _osmo_strrb_is_bufindex_valid()

bool _osmo_strrb_is_bufindex_valid ( const struct osmo_strrb rb,
unsigned int  offset 
)

References end, osmo_strrb_is_empty(), size, and start.

Referenced by osmo_strrb_get_nth().

◆ osmo_strrb_add()

int osmo_strrb_add ( struct osmo_strrb rb,
const char *  data 
)

Add a string to the osmo_strrb.

Parameters
[in]rbThe osmo_strrb to add to.
[in]dataThe string to add.

Add a message to the osmo_strrb. Older messages will be overwritten as necessary.

Returns
0 normally, 1 as a warning (ie, if data was truncated).

References buffer, data, end, len(), RB_MAX_MESSAGE_SIZE, size, and start.

Referenced by _rb_output().

◆ osmo_strrb_create()

struct osmo_strrb * osmo_strrb_create ( void *  talloc_ctx,
size_t  rb_size 
)

Create an empty, initialized osmo_strrb.

Parameters
[in]ctxThe talloc memory context which should own this.
[in]rb_sizeThe number of message slots the osmo_strrb can hold.
Returns
A struct osmo_strrb* on success, NULL in case of error.

This function creates and initializes a ringbuffer. Note that the ringbuffer stores at most rb_size - 1 messages.

References buffer, RB_MAX_MESSAGE_SIZE, and size.

Referenced by log_target_create_rb().

◆ osmo_strrb_elements()

size_t osmo_strrb_elements ( const struct osmo_strrb rb)

Count the number of log messages in an osmo_strrb.

Parameters
[in]rbThe osmo_strrb to count the elements of.
Returns
The number of log messages in the osmo_strrb.

References end, size, and start.

Referenced by log_target_rb_used_size().

◆ osmo_strrb_get_nth()

const char * osmo_strrb_get_nth ( const struct osmo_strrb rb,
unsigned int  string_index 
)

Return a pointer to the Nth string in the osmo_strrb.

Parameters
[in]rbThe osmo_strrb to search.
[in]string_indexThe index sought (N), zero-indexed.

Return a pointer to the Nth string in the osmo_strrb. Return NULL if there is no Nth string. Note that N is zero-indexed.

Returns
A pointer to the target string on success, NULL in case of error.

References _osmo_strrb_is_bufindex_valid(), buffer, end, size, and start.

Referenced by log_target_rb_get().

◆ osmo_strrb_is_empty()

bool osmo_strrb_is_empty ( const struct osmo_strrb rb)

Check if an osmo_strrb is empty.

Parameters
[in]rbThe osmo_strrb to check.
Returns
True if the osmo_strrb is empty, false otherwise.

References end, and start.

Referenced by _osmo_strrb_is_bufindex_valid().