3 * AT chat library with GLib integration
5 * Copyright (C) 2008-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef __GATCHAT_RINGBUFFER_H
23 #define __GATCHAT_RINGBUFFER_H
30 unsigned char *buffer;
37 * Creates a new ring buffer with capacity size
39 struct ring_buffer *ring_buffer_new(unsigned int size);
42 * Frees the resources allocated for the ring buffer
44 void ring_buffer_free(struct ring_buffer *buf);
47 * Returns the capacity of the ring buffer
49 int ring_buffer_capacity(struct ring_buffer *buf);
52 * Resets the ring buffer, all data inside the buffer is lost
54 void ring_buffer_reset(struct ring_buffer *buf);
57 * Writes data of size len into the ring buffer buf. Returns -1 if the
58 * write failed or the number of bytes written
60 int ring_buffer_write(struct ring_buffer *buf, const void *data,
64 * Advances the write counter by len, this is meant to be used with
65 * the ring_buffer_write_ptr function. Returns the number of bytes
66 * actually advanced (the capacity of the buffer)
68 int ring_buffer_write_advance(struct ring_buffer *buf, unsigned int len);
71 * Returns the write pointer. Careful not to write past the end of the
72 * buffer. Use the ring_buffer_avail_no_wrap function,
73 * ring_buffer_write_advance.
75 unsigned char *ring_buffer_write_ptr(struct ring_buffer *buf);
78 * Returns the number of free bytes available in the buffer
80 int ring_buffer_avail(struct ring_buffer *buf);
83 * Returns the number of free bytes available in the buffer without wrapping
85 int ring_buffer_avail_no_wrap(struct ring_buffer *buf);
88 * Reads data from the ring buffer buf into memory region pointed to by data.
89 * A maximum of len bytes will be read. Returns -1 if the read failed or
90 * the number of bytes read
92 int ring_buffer_read(struct ring_buffer *buf, void *data,
96 * Returns the read pointer with read offset specified by offset. No bounds
97 * checking is performed. Be careful not to read past the end of the buffer.
98 * Use the ring_buffer_len_no_wrap function, and ring_buffer_drain.
100 unsigned char *ring_buffer_read_ptr(struct ring_buffer *buf,
101 unsigned int offset);
104 * Returns the number of bytes currently available to be read in the buffer
106 int ring_buffer_len(struct ring_buffer *buf);
109 * Returns the number of bytes currently available to be read in the buffer
112 int ring_buffer_len_no_wrap(struct ring_buffer *buf);
115 * Drains the ring buffer of len bytes. Returns the number of bytes the
116 * read counter was actually advanced.
118 int ring_buffer_drain(struct ring_buffer *buf, unsigned int len);
124 #endif /* __GATCHAT_RINGBUFFER_H */