1 /* 2 * Copyright (c) 2002-2014 Balabit 3 * Copyright (c) 2014 Laszlo Budai 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 * As an additional exemption you are allowed to compile & link against the 20 * OpenSSL libraries as published by the OpenSSL project. See the file 21 * COPYING for details. 22 * 23 */ 24 25 #ifndef RINGBUFFER_H_INCLUDED 26 #define RINGBUFFER_H_INCLUDED 27 28 #include <glib.h> 29 30 typedef struct _RingBuffer 31 { 32 gpointer buffer; 33 guint32 head; 34 guint32 tail; 35 guint32 count; 36 guint32 capacity; 37 guint32 element_size; 38 } RingBuffer; 39 40 typedef gboolean(*RingBufferIsContinuousPredicate)(gpointer element); 41 42 void ring_buffer_init(RingBuffer *self); 43 void ring_buffer_alloc(RingBuffer *self, guint32 size_of_element, guint32 capacity); 44 gboolean ring_buffer_is_allocated(RingBuffer *self); 45 void ring_buffer_free(RingBuffer *self); 46 47 gboolean ring_buffer_is_full(RingBuffer *self); 48 gboolean ring_buffer_is_empty(RingBuffer *self); 49 50 gpointer ring_buffer_push(RingBuffer *self); 51 gpointer ring_buffer_pop(RingBuffer *self); 52 gpointer ring_buffer_tail(RingBuffer *self); 53 54 gboolean ring_buffer_drop(RingBuffer *self, guint32 n); 55 guint32 ring_buffer_capacity(RingBuffer *self); 56 guint32 ring_buffer_count(RingBuffer *self); 57 58 gpointer ring_buffer_element_at(RingBuffer *self, guint32 idx); 59 guint32 ring_buffer_get_continual_range_length(RingBuffer *self, RingBufferIsContinuousPredicate pred); 60 61 #endif 62