configure.ac: Move OggVorbis Encoder to Encoder Plugins.
[mpd-mk.git] / src / fifo_buffer.h
blob661dfd57e79cc9f965eafe0e539c6c2f1b411cc3
1 /*
2 * Copyright (C) 2003-2010 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
7 * are met:
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
15 * distribution.
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.
31 /** \file
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
44 #include <stdbool.h>
45 #include <stddef.h>
47 struct fifo_buffer;
49 /**
50 * Creates a new #fifo_buffer object. Free this object with
51 * fifo_buffer_free().
53 * @param size the size of the buffer in bytes
54 * @return the new #fifo_buffer object
56 struct fifo_buffer *
57 fifo_buffer_new(size_t size);
59 /**
60 * Frees the resources consumed by this #fifo_buffer object.
62 void
63 fifo_buffer_free(struct fifo_buffer *buffer);
65 /**
66 * Clears all data currently in this #fifo_buffer object. This does
67 * not overwrite the actuall buffer; it just resets the internal
68 * pointers.
70 void
71 fifo_buffer_clear(struct fifo_buffer *buffer);
73 /**
74 * Reads from the beginning of the buffer. To remove consumed data
75 * from the buffer, call fifo_buffer_consume().
77 * @param buffer the #fifo_buffer object
78 * @param length_r the maximum amount to read is returned here
79 * @return a pointer to the beginning of the buffer, or NULL if the
80 * buffer is empty
82 const void *
83 fifo_buffer_read(const struct fifo_buffer *buffer, size_t *length_r);
85 /**
86 * Marks data at the beginning of the buffer as "consumed".
88 * @param buffer the #fifo_buffer object
89 * @param length the number of bytes which were consumed
91 void
92 fifo_buffer_consume(struct fifo_buffer *buffer, size_t length);
94 /**
95 * Prepares writing to the buffer. This returns a buffer which you
96 * can write to. To commit the write operation, call
97 * fifo_buffer_append().
99 * @param buffer the #fifo_buffer object
100 * @param max_length_r the maximum amount to write is returned here
101 * @return a pointer to the end of the buffer, or NULL if the buffer
102 * is already full
104 void *
105 fifo_buffer_write(struct fifo_buffer *buffer, size_t *max_length_r);
108 * Commits the write operation initiated by fifo_buffer_write().
110 * @param buffer the #fifo_buffer object
111 * @param length the number of bytes which were written
113 void
114 fifo_buffer_append(struct fifo_buffer *buffer, size_t length);
117 * Checks if the buffer is empty.
119 bool
120 fifo_buffer_is_empty(struct fifo_buffer *buffer);
123 * Checks if the buffer is full.
125 bool
126 fifo_buffer_is_full(struct fifo_buffer *buffer);
128 #endif