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 (C) 1999-2008 Novell, Inc. (www.novell.com)
10 * This library is free software you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include <glib/gi18n-lib.h>
29 #include "camel-stream-null.h"
31 static void camel_stream_null_seekable_init (GSeekableIface *iface);
33 G_DEFINE_TYPE_WITH_CODE (CamelStreamNull, camel_stream_null, CAMEL_TYPE_STREAM,
34 G_IMPLEMENT_INTERFACE (G_TYPE_SEEKABLE, camel_stream_null_seekable_init))
37 stream_null_write (CamelStream *stream,
40 GCancellable *cancellable,
43 CAMEL_STREAM_NULL (stream)->written += n;
49 stream_null_eos (CamelStream *stream)
55 stream_null_tell (GSeekable *seekable)
61 stream_null_can_seek (GSeekable *seekable)
67 stream_null_seek (GSeekable *seekable,
70 GCancellable *cancellable,
73 if (type != G_SEEK_SET || offset != 0) {
75 error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
76 _("Only reset to beginning is supported with CamelHttpStream"));
80 CAMEL_STREAM_NULL (seekable)->written = 0;
86 stream_null_can_truncate (GSeekable *seekable)
92 stream_null_truncate_fn (GSeekable *seekable,
94 GCancellable *cancellable,
97 /* XXX Don't bother translating this. Camel never calls it. */
99 error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
100 "Truncation is not supported");
106 camel_stream_null_class_init (CamelStreamNullClass *class)
108 CamelStreamClass *stream_class;
110 stream_class = CAMEL_STREAM_CLASS (class);
111 stream_class->write = stream_null_write;
112 stream_class->eos = stream_null_eos;
116 camel_stream_null_seekable_init (GSeekableIface *iface)
118 iface->tell = stream_null_tell;
119 iface->can_seek = stream_null_can_seek;
120 iface->seek = stream_null_seek;
121 iface->can_truncate = stream_null_can_truncate;
122 iface->truncate_fn = stream_null_truncate_fn;
126 camel_stream_null_init (CamelStreamNull *stream_null)
131 * camel_stream_null_new:
133 * Returns a null stream. A null stream is always at eof, and
134 * always returns success for all reads and writes.
136 * Returns: a new #CamelStreamNull
139 camel_stream_null_new (void)
141 return g_object_new (CAMEL_TYPE_STREAM_NULL, NULL);