2
* Copyright (C) 2003-2011 The Music Player Daemon Project
3
* http://www.musicpd.org
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
12
* - Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in the
14
* documentation and/or other materials provided with the
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
* OF THE POSSIBILITY OF SUCH DAMAGE.
33
* This is a general purpose FIFO buffer library. You may append data
34
* at the end, while another instance reads data from the beginning.
35
* It is optimized for zero-copy usage: you get pointers to the real
36
* buffer, where you may operate on.
38
* This library is not thread safe.
41
#ifndef MPD_FIFO_BUFFER_H
42
#define MPD_FIFO_BUFFER_H
54
* Creates a new #fifo_buffer object. Free this object with
57
* @param size the size of the buffer in bytes
58
* @return the new #fifo_buffer object
61
fifo_buffer_new(size_t size);
64
fifo_buffer_init(struct fifo_buffer *buffer, size_t size);
67
* Change the capacity of the #fifo_buffer, while preserving existing
70
* @param buffer the old buffer, may be NULL
71
* @param new_size the requested new size of the #fifo_buffer; must
72
* not be smaller than the data which is stored in the old buffer
73
* @return the new buffer, may be NULL if the requested new size is 0
76
fifo_buffer_realloc(struct fifo_buffer *buffer, size_t new_size);
79
* Frees the resources consumed by this #fifo_buffer object.
82
fifo_buffer_free(struct fifo_buffer *buffer);
85
* Return the capacity of the buffer, i.e. the size that was passed to
89
fifo_buffer_capacity(const struct fifo_buffer *buffer);
92
* Return the number of bytes currently stored in the buffer.
95
fifo_buffer_available(const struct fifo_buffer *buffer);
98
* Clears all data currently in this #fifo_buffer object. This does
99
* not overwrite the actuall buffer; it just resets the internal
103
fifo_buffer_clear(struct fifo_buffer *buffer);
106
* Reads from the beginning of the buffer. To remove consumed data
107
* from the buffer, call fifo_buffer_consume().
109
* @param buffer the #fifo_buffer object
110
* @param length_r the maximum amount to read is returned here
111
* @return a pointer to the beginning of the buffer, or NULL if the
115
fifo_buffer_read(const struct fifo_buffer *buffer, size_t *length_r);
118
* Marks data at the beginning of the buffer as "consumed".
120
* @param buffer the #fifo_buffer object
121
* @param length the number of bytes which were consumed
124
fifo_buffer_consume(struct fifo_buffer *buffer, size_t length);
127
* Prepares writing to the buffer. This returns a buffer which you
128
* can write to. To commit the write operation, call
129
* fifo_buffer_append().
131
* @param buffer the #fifo_buffer object
132
* @param max_length_r the maximum amount to write is returned here
133
* @return a pointer to the end of the buffer, or NULL if the buffer
137
fifo_buffer_write(struct fifo_buffer *buffer, size_t *max_length_r);
140
* Commits the write operation initiated by fifo_buffer_write().
142
* @param buffer the #fifo_buffer object
143
* @param length the number of bytes which were written
146
fifo_buffer_append(struct fifo_buffer *buffer, size_t length);
149
* Checks if the buffer is empty.
152
fifo_buffer_is_empty(struct fifo_buffer *buffer);
155
* Checks if the buffer is full.
158
fifo_buffer_is_full(struct fifo_buffer *buffer);