Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file strrb.h |
| 2 | * Osmocom string ringbuffer handling routines. */ |
| 3 | /* |
| 4 | * (C) 2012-2013 by Katerina Barone-Adesi <kat.obsc@gmail.com> |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 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 |
Harald Welte | 33e940b | 2014-10-26 20:52:25 +0100 | [diff] [blame] | 9 | * the Free Software Foundation; either version 2 of the License, or |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 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 | * |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 19 | #pragma once |
| 20 | |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 21 | /*! \defgroup osmo_strrb Osmocom ringbuffers for log strings |
| 22 | * @{ |
Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 23 | * \file strrb.h */ |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 24 | |
| 25 | #include <unistd.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <stdint.h> |
| 28 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 29 | /*! A structure representing an osmocom string ringbuffer */ |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 30 | |
| 31 | #define RB_MAX_MESSAGE_SIZE 240 |
| 32 | struct osmo_strrb { |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 33 | uint16_t start; /*!< index of the first slot */ |
| 34 | uint16_t end; /*!< index of the last slot */ |
| 35 | uint16_t size; /*!< max number of messages to store */ |
| 36 | char **buffer; /*!< storage for messages */ |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
Vadim Yanitskiy | 37dc995 | 2023-03-31 05:39:04 +0700 | [diff] [blame] | 39 | struct osmo_strrb *osmo_strrb_create(void *talloc_ctx, size_t rb_size); |
Katerina Barone-Adesi | 3309a43 | 2013-02-21 05:16:29 +0000 | [diff] [blame] | 40 | bool osmo_strrb_is_empty(const struct osmo_strrb *rb); |
| 41 | const char *osmo_strrb_get_nth(const struct osmo_strrb *rb, |
| 42 | unsigned int string_index); |
| 43 | bool _osmo_strrb_is_bufindex_valid(const struct osmo_strrb *rb, |
| 44 | unsigned int offset); |
| 45 | size_t osmo_strrb_elements(const struct osmo_strrb *rb); |
| 46 | int osmo_strrb_add(struct osmo_strrb *rb, const char *data); |
| 47 | |
| 48 | /*! @} */ |