1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-stream.c : abstract class for a stream */
7 * Copyright (C) 1999 Bertrand Guiheneuf <Bertrand.Guiheneuf@inria.fr> .
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
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.
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
25 #include "camel-stream.h"
27 static CamelStreamClass *parent_class = NULL;
30 /* Returns the class for a CamelMimeMessage */
31 #define CS_CLASS(so) CAMEL_STREAM_CLASS (GTK_OBJECT(so)->klass)
34 default_camel_flush (CamelStream *stream)
40 default_camel_close (CamelStream *stream)
46 camel_stream_class_init (CamelStreamClass *camel_stream_class)
49 parent_class = gtk_type_class (gtk_object_get_type ());
51 /* virtual method definition */
52 camel_stream_class->read = NULL;
53 camel_stream_class->write = NULL;
54 camel_stream_class->flush = default_camel_flush;
55 camel_stream_class->available = NULL;
56 camel_stream_class->eos = NULL;
57 camel_stream_class->close = default_camel_close;
59 /* virtual method overload */
63 camel_stream_get_type (void)
65 static GtkType camel_stream_type = 0;
67 if (!camel_stream_type) {
68 GtkTypeInfo camel_stream_info =
72 sizeof (CamelStreamClass),
73 (GtkClassInitFunc) camel_stream_class_init,
74 (GtkObjectInitFunc) NULL,
75 /* reserved_1 */ NULL,
76 /* reserved_2 */ NULL,
77 (GtkClassInitFunc) NULL,
80 camel_stream_type = gtk_type_unique (gtk_object_get_type (), &camel_stream_info);
83 return camel_stream_type;
88 * @stream: a CamelStream.
89 * @buffer: buffer where bytes pulled from the stream are stored.
90 * @n: max number of bytes to read.
92 * Read at most @n bytes from the @stream object and stores them
93 * in the buffer pointed at by @buffer.
95 * Return value: number of bytes actually read.
98 camel_stream_read (CamelStream *stream, gchar *buffer, gint n)
100 CS_CLASS (stream)->read (stream, buffer, n);
104 * camel_stream_write:
105 * @stream: a CamelStream object.
106 * @buffer: buffer to write.
107 * @n: number of bytes to write
109 * Write @n bytes from the buffer pointed at by @buffer into @stream.
111 * Return value: the number of bytes actually written
115 camel_stream_write (CamelStream *stream, gchar *buffer, gint n)
117 return CS_CLASS (stream)->write (stream, buffer, n);
121 * camel_stream_flush:
122 * @stream: a CamelStream object
124 * Flushes the contents of the stream to its backing store.
127 camel_stream_flush (CamelStream *stream)
129 return CS_CLASS (stream)->flush (stream);
133 * camel_stream_available:
134 * @stream: a CamelStream object
136 * Return value: the number of bytes available.
139 camel_stream_available (CamelStream *stream)
141 return CS_CLASS (stream)->available (stream);
146 * @stream: a CamelStream object
148 * Test if there are bytes left to read on the @stream object.
150 * Return value: %TRUE if all the contents on the stream has been read, or
151 * %FALSE if information is still available.
154 camel_stream_eos (CamelStream *stream)
156 return CS_CLASS (stream)->eos (stream);
162 * @stream: a CamelStream object.
164 * Close the @stream object.
167 camel_stream_close (CamelStream *stream)
169 CS_CLASS (stream)->close (stream);
172 /***************** Utility functions ********************/
175 * came_stream_write_strings:
176 * @stream: a CamelStream object.
177 * @...: A %NULL terminated list of strings.
179 * This is a utility function that writes the list of
180 * strings into the @stream object.
183 camel_stream_write_strings (CamelStream *stream, ... )
188 va_start(args, stream);
189 string = va_arg (args, char *);
192 camel_stream_write_string (stream, string);
193 string = va_arg (args, char *);