~ubuntu-branches/ubuntu/utopic/mpd/utopic-proposed

« back to all changes in this revision

Viewing changes to src/util/fifo_buffer.h

  • Committer: Package Import Robot
  • Author(s): Steve Kowalik
  • Date: 2013-11-12 18:17:40 UTC
  • mfrom: (2.2.36 sid)
  • Revision ID: package-import@ubuntu.com-20131112181740-72aa4zihehoobedp
Tags: 0.18.3-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Add libmp3lame-dev to Build-Depends, and enable LAME.
  - Read the user for the daemon from the config file in the init script.
  - Move avahi-daemon from Suggests to Recommends.
  - Added apport hook to include user configuration file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2011 The Music Player Daemon Project
 
3
 * http://www.musicpd.org
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
9
 * - Redistributions of source code must retain the above copyright
 
10
 * notice, this list of conditions and the following disclaimer.
 
11
 *
 
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.
 
16
 *
 
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.
 
29
 */
 
30
 
 
31
/** \file
 
32
 *
 
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.
 
37
 *
 
38
 * This library is not thread safe.
 
39
 */
 
40
 
 
41
#ifndef MPD_FIFO_BUFFER_H
 
42
#define MPD_FIFO_BUFFER_H
 
43
 
 
44
#include <stdbool.h>
 
45
#include <stddef.h>
 
46
 
 
47
struct fifo_buffer;
 
48
 
 
49
#ifdef __cplusplus
 
50
extern "C" {
 
51
#endif
 
52
 
 
53
/**
 
54
 * Creates a new #fifo_buffer object.  Free this object with
 
55
 * fifo_buffer_free().
 
56
 *
 
57
 * @param size the size of the buffer in bytes
 
58
 * @return the new #fifo_buffer object
 
59
 */
 
60
struct fifo_buffer *
 
61
fifo_buffer_new(size_t size);
 
62
 
 
63
void
 
64
fifo_buffer_init(struct fifo_buffer *buffer, size_t size);
 
65
 
 
66
/**
 
67
 * Change the capacity of the #fifo_buffer, while preserving existing
 
68
 * data.
 
69
 *
 
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
 
74
 */
 
75
struct fifo_buffer *
 
76
fifo_buffer_realloc(struct fifo_buffer *buffer, size_t new_size);
 
77
 
 
78
/**
 
79
 * Frees the resources consumed by this #fifo_buffer object.
 
80
 */
 
81
void
 
82
fifo_buffer_free(struct fifo_buffer *buffer);
 
83
 
 
84
/**
 
85
 * Return the capacity of the buffer, i.e. the size that was passed to
 
86
 * fifo_buffer_new().
 
87
 */
 
88
size_t
 
89
fifo_buffer_capacity(const struct fifo_buffer *buffer);
 
90
 
 
91
/**
 
92
 * Return the number of bytes currently stored in the buffer.
 
93
 */
 
94
size_t
 
95
fifo_buffer_available(const struct fifo_buffer *buffer);
 
96
 
 
97
/**
 
98
 * Clears all data currently in this #fifo_buffer object.  This does
 
99
 * not overwrite the actuall buffer; it just resets the internal
 
100
 * pointers.
 
101
 */
 
102
void
 
103
fifo_buffer_clear(struct fifo_buffer *buffer);
 
104
 
 
105
/**
 
106
 * Reads from the beginning of the buffer.  To remove consumed data
 
107
 * from the buffer, call fifo_buffer_consume().
 
108
 *
 
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
 
112
 * buffer is empty
 
113
 */
 
114
const void *
 
115
fifo_buffer_read(const struct fifo_buffer *buffer, size_t *length_r);
 
116
 
 
117
/**
 
118
 * Marks data at the beginning of the buffer as "consumed".
 
119
 *
 
120
 * @param buffer the #fifo_buffer object
 
121
 * @param length the number of bytes which were consumed
 
122
 */
 
123
void
 
124
fifo_buffer_consume(struct fifo_buffer *buffer, size_t length);
 
125
 
 
126
/**
 
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().
 
130
 *
 
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
 
134
 * is already full
 
135
 */
 
136
void *
 
137
fifo_buffer_write(struct fifo_buffer *buffer, size_t *max_length_r);
 
138
 
 
139
/**
 
140
 * Commits the write operation initiated by fifo_buffer_write().
 
141
 *
 
142
 * @param buffer the #fifo_buffer object
 
143
 * @param length the number of bytes which were written
 
144
 */
 
145
void
 
146
fifo_buffer_append(struct fifo_buffer *buffer, size_t length);
 
147
 
 
148
/**
 
149
 * Checks if the buffer is empty.
 
150
 */
 
151
bool
 
152
fifo_buffer_is_empty(struct fifo_buffer *buffer);
 
153
 
 
154
/**
 
155
 * Checks if the buffer is full.
 
156
 */
 
157
bool
 
158
fifo_buffer_is_full(struct fifo_buffer *buffer);
 
159
 
 
160
#ifdef __cplusplus
 
161
}
 
162
#endif
 
163
 
 
164
#endif