Sun, 15 Apr 2007 02:10:37 +0000
propagate from branch 'im.pidgin.gaim' (head b2836a24d81e7a1bd1d21b3aea8794b094391344)
to branch 'im.pidgin.rlaager.merging.soc-msnp13-to-svn18164' (head 463b4fa9f067b279f843520d95a822adc86a0a1b)
| 13201 | 1 | /* |
|
14013
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
2 | * @file circbuffer.h Buffer Utility Functions |
| 13201 | 3 | * @ingroup core |
| 4 | * | |
| 5 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 6 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 7 | * source distribution. | |
| 8 | * | |
| 9 | * This program is free software; you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation; either version 2 of the License, or | |
| 12 | * (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, | |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | * GNU General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 22 | */ | |
|
14013
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
23 | #ifndef _CIRCBUFFER_H |
|
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
24 | #define _CIRCBUFFER_H |
|
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
25 | |
|
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
26 | #include <glib.h> |
| 13201 | 27 | |
| 28 | #ifdef __cplusplus | |
| 29 | extern "C" { | |
| 30 | #endif | |
| 31 | ||
| 32 | typedef struct _GaimCircBuffer { | |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
33 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
34 | /** A pointer to the starting address of our chunk of memory. */ |
| 13201 | 35 | gchar *buffer; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
36 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
37 | /** The incremental amount to increase this buffer by when |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
38 | * the buffer is not big enough to hold incoming data, in bytes. */ |
| 13201 | 39 | gsize growsize; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
40 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
41 | /** The length of this buffer, in bytes. */ |
| 13201 | 42 | gsize buflen; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
43 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
44 | /** The number of bytes of this buffer that contain unread data. */ |
| 13201 | 45 | gsize bufused; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
46 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
47 | /** A pointer to the next byte where new incoming data is |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
48 | * buffered to. */ |
| 13201 | 49 | gchar *inptr; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
50 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
51 | /** A pointer to the next byte of buffered data that should be |
|
13233
1a55c46f0a24
[gaim-migrate @ 15597]
Mark Doliner <markdoliner@pidgin.im>
parents:
13230
diff
changeset
|
52 | * read by the consumer. */ |
| 13201 | 53 | gchar *outptr; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
54 | |
| 13201 | 55 | } GaimCircBuffer; |
| 56 | ||
| 57 | /** | |
| 58 | * Creates a new circular buffer. This will not allocate any memory for the | |
| 59 | * actual buffer until data is appended to it. | |
| 60 | * | |
|
13213
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
61 | * @param growsize The amount that the buffer should grow the first time data |
|
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
62 | * is appended and every time more space is needed. Pass in |
|
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
63 | * "0" to use the default of 256 bytes. |
| 13201 | 64 | * |
| 65 | * @return The new GaimCircBuffer. This should be freed with | |
| 66 | * gaim_circ_buffer_destroy when you are done with it | |
| 67 | */ | |
| 68 | GaimCircBuffer *gaim_circ_buffer_new(gsize growsize); | |
| 69 | ||
| 70 | /** | |
| 71 | * Dispose of the GaimCircBuffer and free any memory used by it (including any | |
| 72 | * memory used by the internal buffer). | |
| 73 | * | |
| 74 | * @param buf The GaimCircBuffer to free | |
| 75 | */ | |
| 76 | void gaim_circ_buffer_destroy(GaimCircBuffer *buf); | |
| 77 | ||
| 78 | /** | |
|
13213
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
79 | * Append data to the GaimCircBuffer. This will grow the internal |
|
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
80 | * buffer to fit the added data, if needed. |
| 13201 | 81 | * |
| 82 | * @param buf The GaimCircBuffer to which to append the data | |
| 83 | * @param src pointer to the data to copy into the buffer | |
| 84 | * @param len number of bytes to copy into the buffer | |
| 85 | */ | |
| 86 | void gaim_circ_buffer_append(GaimCircBuffer *buf, gconstpointer src, gsize len); | |
| 87 | ||
| 88 | /** | |
| 89 | * Determine the maximum number of contiguous bytes that can be read from the | |
| 90 | * GaimCircBuffer. | |
| 91 | * Note: This may not be the total number of bytes that are buffered - a | |
| 92 | * subsequent call after calling gaim_circ_buffer_mark_read() may indicate more | |
| 93 | * data is available to read. | |
| 94 | * | |
| 95 | * @param buf the GaimCircBuffer for which to determine the maximum contiguous | |
| 96 | * bytes that can be read. | |
| 97 | * | |
| 98 | * @return the number of bytes that can be read from the GaimCircBuffer | |
| 99 | */ | |
| 100 | gsize gaim_circ_buffer_get_max_read(GaimCircBuffer *buf); | |
| 101 | ||
| 102 | /** | |
| 103 | * Mark the number of bytes that have been read from the buffer. | |
| 104 | * | |
| 105 | * @param buf The GaimCircBuffer to mark bytes read from | |
| 106 | * @param len The number of bytes to mark as read | |
| 107 | * | |
| 108 | * @return TRUE if we successfully marked the bytes as having been read, FALSE | |
| 109 | * otherwise. | |
| 110 | */ | |
| 111 | gboolean gaim_circ_buffer_mark_read(GaimCircBuffer *buf, gsize len); | |
| 112 | ||
| 113 | #ifdef __cplusplus | |
| 114 | } | |
| 115 | #endif | |
| 116 | ||
|
14013
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
117 | #endif /* _CIRCBUFFER_H */ |