\doxysection{src/core/strrb.c File Reference}
\label{strrb_8c}\index{src/core/strrb.c@{src/core/strrb.c}}


Ringbuffer implementation, tailored for logging.  


{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/strrb.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ osmo\+\_\+strrb} $\ast$ \textbf{ osmo\+\_\+strrb\+\_\+create} (void $\ast$talloc\+\_\+ctx, size\+\_\+t rb\+\_\+size)
\begin{DoxyCompactList}\small\item\em Create an empty, initialized \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+strrb\+\_\+is\+\_\+empty} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb)
\begin{DoxyCompactList}\small\item\em Check if an \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} is empty. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+strrb\+\_\+get\+\_\+nth} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb, unsigned int string\+\_\+index)
\begin{DoxyCompactList}\small\item\em Return a pointer to the Nth string in the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
bool \textbf{ \+\_\+osmo\+\_\+strrb\+\_\+is\+\_\+bufindex\+\_\+valid} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb, unsigned int bufi)
\item 
size\+\_\+t \textbf{ osmo\+\_\+strrb\+\_\+elements} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb)
\begin{DoxyCompactList}\small\item\em Count the number of log messages in an \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+strrb\+\_\+add} (struct \textbf{ osmo\+\_\+strrb} $\ast$rb, const char $\ast$\textbf{ data})
\begin{DoxyCompactList}\small\item\em Add a string to the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Ringbuffer implementation, tailored for logging. 

This is a lossy ringbuffer. It keeps up to N of the newest messages, overwriting the oldest as newer ones come in.

Ringbuffer assumptions, invarients, and notes\+:
\begin{DoxyItemize}
\item start is the index of the first used index slot in the ring buffer.
\item end is the index of the next index slot in the ring buffer.
\item start == end =$>$ buffer is empty
\item Consequence\+: the buffer can hold at most size -\/ 1 messages (if this were not the case, full and empty buffers would be indistinguishable given the conventions in this implementation).
\item Whenever the ringbuffer is full, start is advanced. The second oldest message becomes unreachable by valid indexes (end is not a valid index) and the oldest message is overwritten (if there was a message there, which is the case unless this is the first time the ringbuffer becomes full).
\end{DoxyItemize}