1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
2 /* camel-stream.c : abstract class for a stream */
6 * Michael Zucchi <notzed@ximian.com>
8 * Copyright 1999, 2000 Ximian, Inc. (www.ximian.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU Lesser General Public
12 * License as published by the Free Software Foundation.
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 Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
29 #include "camel-stream-null.h"
31 static CamelObjectClass *parent_class = NULL;
33 /* Returns the class for a CamelStream */
34 #define CS_CLASS(so) CAMEL_STREAM_NULL_CLASS(CAMEL_OBJECT_GET_CLASS(so))
36 /* dummy implementations, for a NULL stream */
37 static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n) { return 0; }
38 static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n) { ((CamelStreamNull *)stream)->written += n; return n; }
39 static int stream_close (CamelStream *stream) { return 0; }
40 static int stream_flush (CamelStream *stream) { return 0; }
41 static gboolean stream_eos (CamelStream *stream) { return TRUE; }
42 static int stream_reset (CamelStream *stream) { ((CamelStreamNull *)stream)->written = 0; return 0; }
45 camel_stream_null_class_init (CamelStreamClass *camel_stream_null_class)
47 CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_stream_null_class;
49 parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
51 /* virtual method definition */
52 camel_stream_class->read = stream_read;
53 camel_stream_class->write = stream_write;
54 camel_stream_class->close = stream_close;
55 camel_stream_class->flush = stream_flush;
56 camel_stream_class->eos = stream_eos;
57 camel_stream_class->reset = stream_reset;
61 camel_stream_null_get_type (void)
63 static CamelType camel_stream_null_type = CAMEL_INVALID_TYPE;
65 if (camel_stream_null_type == CAMEL_INVALID_TYPE) {
66 camel_stream_null_type = camel_type_register( camel_stream_get_type(),
68 sizeof( CamelStreamNull ),
69 sizeof( CamelStreamNullClass ),
70 (CamelObjectClassInitFunc) camel_stream_null_class_init,
76 return camel_stream_null_type;
80 * camel_stream_null_new:
82 * Returns a null stream. A null stream is always at eof, and
83 * always returns success for all reads and writes.
85 * Returns a new #CamelStreamNull
88 camel_stream_null_new(void)
90 return (CamelStream *)camel_object_new(camel_stream_null_get_type ());