blob: 7507cf418ead434d1d33edb4d3679df4cfd56baa [file] [log] [blame]
Sylvain Munaut12ba7782014-06-16 10:13:40 +02001#pragma once
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00002
3/* (C) 2012-2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
Harald Welte33e940b2014-10-26 20:52:25 +01008 * the Free Software Foundation; either version 2 of the License, or
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22/*! \defgroup osmo_strrb Osmocom ringbuffers for log strings
23 * @{
24 */
25
26/*! \file strrb.h
27 * \brief Osmocom string ringbuffer handling routines
28 */
29
30#include <unistd.h>
31#include <stdbool.h>
32#include <stdint.h>
33
34#include <osmocom/core/talloc.h>
35
36/*! \brief A structure representing an osmocom string ringbuffer */
37
38#define RB_MAX_MESSAGE_SIZE 240
39struct osmo_strrb {
40 uint16_t start; /*!< \brief index of the first slot */
41 uint16_t end; /*!< \brief index of the last slot */
42 uint16_t size; /*!< \brief max number of messages to store */
43 char **buffer; /*!< \brief storage for messages */
44};
45
46struct osmo_strrb *osmo_strrb_create(TALLOC_CTX * ctx, size_t rb_size);
47bool osmo_strrb_is_empty(const struct osmo_strrb *rb);
48const char *osmo_strrb_get_nth(const struct osmo_strrb *rb,
49 unsigned int string_index);
50bool _osmo_strrb_is_bufindex_valid(const struct osmo_strrb *rb,
51 unsigned int offset);
52size_t osmo_strrb_elements(const struct osmo_strrb *rb);
53int osmo_strrb_add(struct osmo_strrb *rb, const char *data);
54
55/*! @} */