blob: cfc56dc0c8218442902167400fc3ff46d99060af [file] [log] [blame]
Katerina Barone-Adesi3309a432013-02-21 05:16:29 +00001#ifndef _STRRB_H
2#define _STRRB_H
3
4/* (C) 2012-2013 by Katerina Barone-Adesi <kat.obsc@gmail.com>
5 * 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
9 * the Free Software Foundation; either version 3 of the License, or
10 * (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
23/*! \defgroup osmo_strrb Osmocom ringbuffers for log strings
24 * @{
25 */
26
27/*! \file strrb.h
28 * \brief Osmocom string ringbuffer handling routines
29 */
30
31#include <unistd.h>
32#include <stdbool.h>
33#include <stdint.h>
34
35#include <osmocom/core/talloc.h>
36
37/*! \brief A structure representing an osmocom string ringbuffer */
38
39#define RB_MAX_MESSAGE_SIZE 240
40struct osmo_strrb {
41 uint16_t start; /*!< \brief index of the first slot */
42 uint16_t end; /*!< \brief index of the last slot */
43 uint16_t size; /*!< \brief max number of messages to store */
44 char **buffer; /*!< \brief storage for messages */
45};
46
47struct osmo_strrb *osmo_strrb_create(TALLOC_CTX * ctx, size_t rb_size);
48bool osmo_strrb_is_empty(const struct osmo_strrb *rb);
49const char *osmo_strrb_get_nth(const struct osmo_strrb *rb,
50 unsigned int string_index);
51bool _osmo_strrb_is_bufindex_valid(const struct osmo_strrb *rb,
52 unsigned int offset);
53size_t osmo_strrb_elements(const struct osmo_strrb *rb);
54int osmo_strrb_add(struct osmo_strrb *rb, const char *data);
55
56/*! @} */
57
58#endif /* _STRRB_H */