Mon, 09 Sep 2013 14:47:22 +0200
Request API: allow action_count = 0
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
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 |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* Purple is the legal property of its developers, whose names are too numerous |
| 13201 | 7 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 8 | * source distribution. | |
| 9 | * | |
| 10 | * This program is free software; you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation; either version 2 of the License, or | |
| 13 | * (at your option) any later version. | |
| 14 | * | |
| 15 | * This program is distributed in the hope that it will be useful, | |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | * GNU General Public License for more details. | |
| 19 | * | |
| 20 | * You should have received a copy of the GNU General Public License | |
| 21 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 13201 | 23 | */ |
|
14013
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
24 | #ifndef _CIRCBUFFER_H |
|
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
25 | #define _CIRCBUFFER_H |
|
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
26 | |
|
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
27 | #include <glib.h> |
| 13201 | 28 | |
| 15884 | 29 | typedef struct _PurpleCircBuffer { |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
30 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
31 | /** A pointer to the starting address of our chunk of memory. */ |
| 13201 | 32 | gchar *buffer; |
|
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 | /** The incremental amount to increase this buffer by when |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
35 | * the buffer is not big enough to hold incoming data, in bytes. */ |
| 13201 | 36 | gsize growsize; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
37 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
38 | /** The length of this buffer, in bytes. */ |
| 13201 | 39 | gsize buflen; |
|
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 number of bytes of this buffer that contain unread data. */ |
| 13201 | 42 | gsize bufused; |
|
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 | /** A pointer to the next byte where new incoming data is |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
45 | * buffered to. */ |
| 13201 | 46 | gchar *inptr; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
47 | |
|
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
48 | /** 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
|
49 | * read by the consumer. */ |
| 13201 | 50 | gchar *outptr; |
|
13230
44b216532ea2
[gaim-migrate @ 15594]
Mark Doliner <markdoliner@pidgin.im>
parents:
13213
diff
changeset
|
51 | |
| 15884 | 52 | } PurpleCircBuffer; |
| 13201 | 53 | |
|
32787
7072f190d6ad
Use G_BEGIN/END_DECLS in public libpurple files. This was
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20147
diff
changeset
|
54 | G_BEGIN_DECLS |
|
7072f190d6ad
Use G_BEGIN/END_DECLS in public libpurple files. This was
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20147
diff
changeset
|
55 | |
| 13201 | 56 | /** |
| 57 | * Creates a new circular buffer. This will not allocate any memory for the | |
| 58 | * actual buffer until data is appended to it. | |
| 59 | * | |
|
13213
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
60 | * @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
|
61 | * is appended and every time more space is needed. Pass in |
|
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
62 | * "0" to use the default of 256 bytes. |
| 13201 | 63 | * |
| 15884 | 64 | * @return The new PurpleCircBuffer. This should be freed with |
| 65 | * purple_circ_buffer_destroy when you are done with it | |
| 13201 | 66 | */ |
| 15884 | 67 | PurpleCircBuffer *purple_circ_buffer_new(gsize growsize); |
| 13201 | 68 | |
| 69 | /** | |
| 15884 | 70 | * Dispose of the PurpleCircBuffer and free any memory used by it (including any |
| 13201 | 71 | * memory used by the internal buffer). |
| 72 | * | |
| 15884 | 73 | * @param buf The PurpleCircBuffer to free |
| 13201 | 74 | */ |
| 15884 | 75 | void purple_circ_buffer_destroy(PurpleCircBuffer *buf); |
| 13201 | 76 | |
| 77 | /** | |
| 15884 | 78 | * Append data to the PurpleCircBuffer. This will grow the internal |
|
13213
8dcf2385a862
[gaim-migrate @ 15576]
Mark Doliner <markdoliner@pidgin.im>
parents:
13201
diff
changeset
|
79 | * buffer to fit the added data, if needed. |
| 13201 | 80 | * |
| 15884 | 81 | * @param buf The PurpleCircBuffer to which to append the data |
| 13201 | 82 | * @param src pointer to the data to copy into the buffer |
| 83 | * @param len number of bytes to copy into the buffer | |
| 84 | */ | |
| 15884 | 85 | void purple_circ_buffer_append(PurpleCircBuffer *buf, gconstpointer src, gsize len); |
| 13201 | 86 | |
| 87 | /** | |
| 88 | * Determine the maximum number of contiguous bytes that can be read from the | |
| 15884 | 89 | * PurpleCircBuffer. |
| 13201 | 90 | * Note: This may not be the total number of bytes that are buffered - a |
| 15884 | 91 | * subsequent call after calling purple_circ_buffer_mark_read() may indicate more |
| 13201 | 92 | * data is available to read. |
| 93 | * | |
| 15884 | 94 | * @param buf the PurpleCircBuffer for which to determine the maximum contiguous |
| 13201 | 95 | * bytes that can be read. |
| 96 | * | |
| 15884 | 97 | * @return the number of bytes that can be read from the PurpleCircBuffer |
| 13201 | 98 | */ |
| 15884 | 99 | gsize purple_circ_buffer_get_max_read(const PurpleCircBuffer *buf); |
| 13201 | 100 | |
| 101 | /** | |
| 102 | * Mark the number of bytes that have been read from the buffer. | |
| 103 | * | |
| 15884 | 104 | * @param buf The PurpleCircBuffer to mark bytes read from |
| 13201 | 105 | * @param len The number of bytes to mark as read |
| 106 | * | |
| 107 | * @return TRUE if we successfully marked the bytes as having been read, FALSE | |
| 108 | * otherwise. | |
| 109 | */ | |
| 15884 | 110 | gboolean purple_circ_buffer_mark_read(PurpleCircBuffer *buf, gsize len); |
| 13201 | 111 | |
|
32787
7072f190d6ad
Use G_BEGIN/END_DECLS in public libpurple files. This was
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
20147
diff
changeset
|
112 | G_END_DECLS |
| 13201 | 113 | |
|
14013
86dac5633bd9
[gaim-migrate @ 16496]
Mark Doliner <markdoliner@pidgin.im>
parents:
13233
diff
changeset
|
114 | #endif /* _CIRCBUFFER_H */ |