Standardize all protocol header guard macros.
[pidgin-git.git] / libpurple / circularbuffer.h
blob94292ec3e3843585bf69feeeee9ede2332eda456
1 /* Purple is the legal property of its developers, whose names are too numerous
2 * to list here. Please refer to the COPYRIGHT file distributed with this
3 * source distribution.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 #ifndef PURPLE_CIRCULAR_BUFFER_H
21 #define PURPLE_CIRCULAR_BUFFER_H
22 /**
23 * SECTION:circularbuffer
24 * @section_id: libpurple-circularbuffer
25 * @short_description: <filename>circularbuffer.h</filename>
26 * @title: Buffer Utility Functions
29 #include <glib.h>
30 #include <glib-object.h>
32 G_BEGIN_DECLS
34 #define PURPLE_TYPE_CIRCULAR_BUFFER (purple_circular_buffer_get_type())
36 G_DECLARE_DERIVABLE_TYPE(PurpleCircularBuffer, purple_circular_buffer, PURPLE,
37 CIRCULAR_BUFFER, GObject)
39 struct _PurpleCircularBufferClass {
40 /*< private >*/
41 GObjectClass parent;
43 void (*grow)(PurpleCircularBuffer *buffer, gsize len);
44 void (*append)(PurpleCircularBuffer *buffer, gconstpointer src, gsize len);
45 gsize (*max_read_size)(PurpleCircularBuffer *buffer);
46 gboolean (*mark_read)(PurpleCircularBuffer *buffer, gsize len);
48 void (*purple_reserved1)(void);
49 void (*purple_reserved2)(void);
50 void (*purple_reserved3)(void);
51 void (*purple_reserved4)(void);
54 /**
55 * purple_circular_buffer_new:
56 * @growsize: The amount that the buffer should grow the first time data
57 * is appended and every time more space is needed. Pass in
58 * "0" to use the default of 256 bytes.
60 * Creates a new circular buffer. This will not allocate any memory for the
61 * actual buffer until data is appended to it.
63 * Returns: The new PurpleCircularBuffer.
65 PurpleCircularBuffer *purple_circular_buffer_new(gsize growsize);
67 /**
68 * purple_circular_buffer_append:
69 * @buffer: The PurpleCircularBuffer to which to append the data
70 * @src: pointer to the data to copy into the buffer
71 * @len: number of bytes to copy into the buffer
73 * Append data to the PurpleCircularBuffer. This will grow the internal
74 * buffer to fit the added data, if needed.
76 void purple_circular_buffer_append(PurpleCircularBuffer *buffer, gconstpointer src, gsize len);
78 /**
79 * purple_circular_buffer_get_max_read:
80 * @buffer: the PurpleCircularBuffer for which to determine the maximum
81 * contiguous bytes that can be read.
83 * Determine the maximum number of contiguous bytes that can be read from the
84 * PurpleCircularBuffer.
85 * Note: This may not be the total number of bytes that are buffered - a
86 * subsequent call after calling purple_circular_buffer_mark_read() may indicate
87 * more data is available to read.
89 * Returns: the number of bytes that can be read from the PurpleCircularBuffer
91 gsize purple_circular_buffer_get_max_read(PurpleCircularBuffer *buffer);
93 /**
94 * purple_circular_buffer_mark_read:
95 * @buffer: The PurpleCircularBuffer to mark bytes read from
96 * @len: The number of bytes to mark as read
98 * Mark the number of bytes that have been read from the buffer.
100 * Returns: TRUE if we successfully marked the bytes as having been read, FALSE
101 * otherwise.
103 gboolean purple_circular_buffer_mark_read(PurpleCircularBuffer *buffer, gsize len);
106 * purple_circular_buffer_grow:
107 * @buffer: The PurpleCircularBuffer to grow.
108 * @len: The number of bytes the buffer should be able to hold.
110 * Increases the buffer size by a multiple of grow size, so that it can hold at
111 * least 'len' bytes.
113 void purple_circular_buffer_grow(PurpleCircularBuffer *buffer, gsize len);
116 * purple_circular_buffer_get_grow_size:
117 * @buffer: The PurpleCircularBuffer from which to get grow size.
119 * Returns the number of bytes by which the buffer grows when more space is
120 * needed.
122 * Returns: The grow size of the buffer.
124 gsize purple_circular_buffer_get_grow_size(PurpleCircularBuffer *buffer);
127 * purple_circular_buffer_get_used:
128 * @buffer: The PurpleCircularBuffer from which to get used count.
130 * Returns the number of bytes of this buffer that contain unread data.
132 * Returns: The number of bytes that contain unread data.
134 gsize purple_circular_buffer_get_used(PurpleCircularBuffer *buffer);
137 * purple_circular_buffer_get_output:
138 * @buffer: The PurpleCircularBuffer from which to get the output pointer.
140 * Returns the output pointer of the buffer, where unread data is available.
141 * Use purple_circular_buffer_get_max_read() to determine the number of
142 * contiguous bytes that can be read from this output. After reading the data,
143 * call purple_circular_buffer_mark_read() to mark the retrieved data as read.
145 * Returns: The output pointer for the buffer.
147 const gchar *purple_circular_buffer_get_output(PurpleCircularBuffer *buffer);
150 * purple_circular_buffer_reset:
151 * @buffer: The PurpleCircularBuffer to reset.
153 * Resets the buffer contents.
155 void purple_circular_buffer_reset(PurpleCircularBuffer *buffer);
157 G_END_DECLS
159 #endif /* PURPLE_CIRCULAR_BUFFER_H */