libosmocore  1.5.1
Osmocom core library
strrb.h
Go to the documentation of this file.
1 
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 2 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 #pragma once
24 
29 #include <unistd.h>
30 #include <stdbool.h>
31 #include <stdint.h>
32 
33 #include <osmocom/core/talloc.h>
34 
37 #define RB_MAX_MESSAGE_SIZE 240
38 struct osmo_strrb {
39  uint16_t start;
40  uint16_t end;
41  uint16_t size;
42  char **buffer;
43 };
44 
45 struct osmo_strrb *osmo_strrb_create(TALLOC_CTX * ctx, size_t rb_size);
46 bool osmo_strrb_is_empty(const struct osmo_strrb *rb);
47 const char *osmo_strrb_get_nth(const struct osmo_strrb *rb,
48  unsigned int string_index);
49 bool _osmo_strrb_is_bufindex_valid(const struct osmo_strrb *rb,
50  unsigned int offset);
51 size_t osmo_strrb_elements(const struct osmo_strrb *rb);
52 int osmo_strrb_add(struct osmo_strrb *rb, const char *data);
53 
osmo_strrb_elements
size_t osmo_strrb_elements(const struct osmo_strrb *rb)
Count the number of log messages in an osmo_strrb.
Definition: strrb.c:136
osmo_strrb::buffer
char ** buffer
storage for messages
Definition: strrb.h:42
osmo_strrb::start
uint16_t start
index of the first slot
Definition: strrb.h:39
osmo_strrb::size
uint16_t size
max number of messages to store
Definition: strrb.h:41
osmo_strrb_is_empty
bool osmo_strrb_is_empty(const struct osmo_strrb *rb)
Check if an osmo_strrb is empty.
Definition: strrb.c:92
data
uint8_t data[0]
osmo_strrb_add
int osmo_strrb_add(struct osmo_strrb *rb, const char *data)
Add a string to the osmo_strrb.
Definition: strrb.c:152
osmo_strrb_create
struct osmo_strrb * osmo_strrb_create(TALLOC_CTX *ctx, size_t rb_size)
Create an empty, initialized osmo_strrb.
Definition: strrb.c:59
_osmo_strrb_is_bufindex_valid
bool _osmo_strrb_is_bufindex_valid(const struct osmo_strrb *rb, unsigned int offset)
Definition: strrb.c:119
talloc.h
osmo_strrb_get_nth
const char * osmo_strrb_get_nth(const struct osmo_strrb *rb, unsigned int string_index)
Return a pointer to the Nth string in the osmo_strrb.
Definition: strrb.c:106
osmo_strrb::end
uint16_t end
index of the last slot
Definition: strrb.h:40
osmo_strrb
Definition: strrb.h:38