Frameworks/libpurple.framework/Versions/0.6.2/Headers/circbuffer.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 1739 Frameworks/libpurple.framework/Versions/0.6.0/Headers/circbuffer.h@8b0daad9656c
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
Evan@653
     1
/**
Evan@653
     2
 * @file circbuffer.h Buffer Utility Functions
Evan@653
     3
 * @ingroup core
Evan@653
     4
 */
Evan@653
     5
Evan@653
     6
/* Purple is the legal property of its developers, whose names are too numerous
Evan@653
     7
 * to list here.  Please refer to the COPYRIGHT file distributed with this
Evan@653
     8
 * source distribution.
Evan@653
     9
 *
Evan@653
    10
 * This program is free software; you can redistribute it and/or modify
Evan@653
    11
 * it under the terms of the GNU General Public License as published by
Evan@653
    12
 * the Free Software Foundation; either version 2 of the License, or
Evan@653
    13
 * (at your option) any later version.
Evan@653
    14
 *
Evan@653
    15
 * This program is distributed in the hope that it will be useful,
Evan@653
    16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Evan@653
    17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Evan@653
    18
 * GNU General Public License for more details.
Evan@653
    19
 *
Evan@653
    20
 * You should have received a copy of the GNU General Public License
Evan@653
    21
 * along with this program; if not, write to the Free Software
Evan@653
    22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
Evan@653
    23
 */
Evan@653
    24
#ifndef _CIRCBUFFER_H
Evan@653
    25
#define _CIRCBUFFER_H
Evan@653
    26
Evan@653
    27
#include <glib.h>
Evan@653
    28
Evan@653
    29
#ifdef __cplusplus
Evan@653
    30
extern "C" {
Evan@653
    31
#endif
Evan@653
    32
Evan@653
    33
typedef struct _PurpleCircBuffer {
Evan@653
    34
Evan@653
    35
	/** A pointer to the starting address of our chunk of memory. */
Evan@653
    36
	gchar *buffer;
Evan@653
    37
Evan@653
    38
	/** The incremental amount to increase this buffer by when
Evan@653
    39
	 *  the buffer is not big enough to hold incoming data, in bytes. */
Evan@653
    40
	gsize growsize;
Evan@653
    41
Evan@653
    42
	/** The length of this buffer, in bytes. */
Evan@653
    43
	gsize buflen;
Evan@653
    44
Evan@653
    45
	/** The number of bytes of this buffer that contain unread data. */
Evan@653
    46
	gsize bufused;
Evan@653
    47
Evan@653
    48
	/** A pointer to the next byte where new incoming data is
Evan@653
    49
	 *  buffered to. */
Evan@653
    50
	gchar *inptr;
Evan@653
    51
Evan@653
    52
	/** A pointer to the next byte of buffered data that should be
Evan@653
    53
	 *  read by the consumer. */
Evan@653
    54
	gchar *outptr;
Evan@653
    55
Evan@653
    56
} PurpleCircBuffer;
Evan@653
    57
Evan@653
    58
/**
Evan@653
    59
 * Creates a new circular buffer.  This will not allocate any memory for the
Evan@653
    60
 * actual buffer until data is appended to it.
Evan@653
    61
 *
Evan@653
    62
 * @param growsize The amount that the buffer should grow the first time data
Evan@653
    63
 *                 is appended and every time more space is needed.  Pass in
Evan@653
    64
 *                 "0" to use the default of 256 bytes.
Evan@653
    65
 *
Evan@653
    66
 * @return The new PurpleCircBuffer. This should be freed with
Evan@653
    67
 *         purple_circ_buffer_destroy when you are done with it
Evan@653
    68
 */
Evan@653
    69
PurpleCircBuffer *purple_circ_buffer_new(gsize growsize);
Evan@653
    70
Evan@653
    71
/**
Evan@653
    72
 * Dispose of the PurpleCircBuffer and free any memory used by it (including any
Evan@653
    73
 * memory used by the internal buffer).
Evan@653
    74
 *
Evan@653
    75
 * @param buf The PurpleCircBuffer to free
Evan@653
    76
 */
Evan@653
    77
void purple_circ_buffer_destroy(PurpleCircBuffer *buf);
Evan@653
    78
Evan@653
    79
/**
Evan@653
    80
 * Append data to the PurpleCircBuffer.  This will grow the internal
Evan@653
    81
 * buffer to fit the added data, if needed.
Evan@653
    82
 *
Evan@653
    83
 * @param buf The PurpleCircBuffer to which to append the data
Evan@653
    84
 * @param src pointer to the data to copy into the buffer
Evan@653
    85
 * @param len number of bytes to copy into the buffer
Evan@653
    86
 */
Evan@653
    87
void purple_circ_buffer_append(PurpleCircBuffer *buf, gconstpointer src, gsize len);
Evan@653
    88
Evan@653
    89
/**
Evan@653
    90
 * Determine the maximum number of contiguous bytes that can be read from the
Evan@653
    91
 * PurpleCircBuffer.
Evan@653
    92
 * Note: This may not be the total number of bytes that are buffered - a
Evan@653
    93
 * subsequent call after calling purple_circ_buffer_mark_read() may indicate more
Evan@653
    94
 * data is available to read.
Evan@653
    95
 *
Evan@653
    96
 * @param buf the PurpleCircBuffer for which to determine the maximum contiguous
Evan@653
    97
 *            bytes that can be read.
Evan@653
    98
 *
Evan@653
    99
 * @return the number of bytes that can be read from the PurpleCircBuffer
Evan@653
   100
 */
Evan@653
   101
gsize purple_circ_buffer_get_max_read(const PurpleCircBuffer *buf);
Evan@653
   102
Evan@653
   103
/**
Evan@653
   104
 * Mark the number of bytes that have been read from the buffer.
Evan@653
   105
 *
Evan@653
   106
 * @param buf The PurpleCircBuffer to mark bytes read from
Evan@653
   107
 * @param len The number of bytes to mark as read
Evan@653
   108
 *
Evan@653
   109
 * @return TRUE if we successfully marked the bytes as having been read, FALSE
Evan@653
   110
 *         otherwise.
Evan@653
   111
 */
Evan@653
   112
gboolean purple_circ_buffer_mark_read(PurpleCircBuffer *buf, gsize len);
Evan@653
   113
Evan@653
   114
#ifdef __cplusplus
Evan@653
   115
}
Evan@653
   116
#endif
Evan@653
   117
Evan@653
   118
#endif /* _CIRCBUFFER_H */