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 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 <glib/gi18n-lib.h>
31 #include "camel-stream-null.h"
33 static void camel_stream_null_seekable_init (GSeekableIface *interface);
35 G_DEFINE_TYPE_WITH_CODE (CamelStreamNull, camel_stream_null, CAMEL_TYPE_STREAM,
36 G_IMPLEMENT_INTERFACE (G_TYPE_SEEKABLE, camel_stream_null_seekable_init))
39 stream_null_write (CamelStream *stream,
42 GCancellable *cancellable,
45 CAMEL_STREAM_NULL (stream)->written += n;
51 stream_null_eos (CamelStream *stream)
57 stream_null_tell (GSeekable *seekable)
63 stream_null_can_seek (GSeekable *seekable)
69 stream_null_seek (GSeekable *seekable,
72 GCancellable *cancellable,
75 if (type != G_SEEK_SET || offset != 0) {
77 error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
78 _("Only reset to beginning is supported with CamelHttpStream"));
82 CAMEL_STREAM_NULL (seekable)->written = 0;
88 stream_null_can_truncate (GSeekable *seekable)
94 stream_null_truncate_fn (GSeekable *seekable,
96 GCancellable *cancellable,
99 /* XXX Don't bother translating this. Camel never calls it. */
100 g_set_error_literal (
101 error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
102 "Truncation is not supported");
108 camel_stream_null_class_init (CamelStreamNullClass *class)
110 CamelStreamClass *stream_class;
112 stream_class = CAMEL_STREAM_CLASS (class);
113 stream_class->write = stream_null_write;
114 stream_class->eos = stream_null_eos;
118 camel_stream_null_seekable_init (GSeekableIface *interface)
120 interface->tell = stream_null_tell;
121 interface->can_seek = stream_null_can_seek;
122 interface->seek = stream_null_seek;
123 interface->can_truncate = stream_null_can_truncate;
124 interface->truncate_fn = stream_null_truncate_fn;
128 camel_stream_null_init (CamelStreamNull *stream_null)
133 * camel_stream_null_new:
135 * Returns a null stream. A null stream is always at eof, and
136 * always returns success for all reads and writes.
138 * Returns: a new #CamelStreamNull
141 camel_stream_null_new (void)
143 return g_object_new (CAMEL_TYPE_STREAM_NULL, NULL);