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