1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 * Bertrand Guiheneuf <bertrand@helixcode.com>
8 * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of the
13 * License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 #include "camel-seekable-stream.h"
31 static CamelStreamClass *parent_class=NULL;
34 /* Returns the class for a CamelSeekableStream */
35 #define CSS_CLASS(so) CAMEL_SEEKABLE_STREAM_CLASS (GTK_OBJECT(so)->klass)
37 static gint _seek (CamelSeekableStream *stream,
39 CamelStreamSeekPolicy policy);
40 static void _reset (CamelStream *stream);
44 camel_seekable_stream_class_init (CamelSeekableStreamClass *camel_seekable_stream_class)
46 CamelStreamClass *camel_stream_class = CAMEL_STREAM_CLASS (camel_seekable_stream_class);
48 parent_class = gtk_type_class (camel_stream_get_type ());
50 /* seekable stream methods */
51 camel_seekable_stream_class->seek = _seek;
53 /* camel stream methods overload */
54 camel_stream_class->reset = _reset;
58 camel_seekable_stream_get_type (void)
60 static GtkType camel_seekable_stream_type = 0;
62 if (!camel_seekable_stream_type) {
63 GtkTypeInfo camel_seekable_stream_info =
65 "CamelSeekableStream",
66 sizeof (CamelSeekableStream),
67 sizeof (CamelSeekableStreamClass),
68 (GtkClassInitFunc) camel_seekable_stream_class_init,
69 (GtkObjectInitFunc) NULL,
70 /* reserved_1 */ NULL,
71 /* reserved_2 */ NULL,
72 (GtkClassInitFunc) NULL,
75 camel_seekable_stream_type = gtk_type_unique (camel_stream_get_type (), &camel_seekable_stream_info);
78 return camel_seekable_stream_type;
85 _seek (CamelSeekableStream *stream,
87 CamelStreamSeekPolicy policy)
89 g_warning ("CamelSeekableStream::seek called on default implementation \n");
97 * @stream: a CamelStream object.
98 * @offset: offset value
99 * @policy: what to do with the offset
103 * Return value: new position, -1 if operation failed.
106 camel_seekable_stream_seek (CamelSeekableStream *stream,
108 CamelStreamSeekPolicy policy)
110 return CSS_CLASS (stream)->seek (stream, offset, policy);
117 * camel_seekable_stream_get_current_position: get the position of a stream
118 * @stream: seekable stream object
120 * Get the current position of a seekable stream.
122 * Return value: the position.
125 camel_seekable_stream_get_current_position (CamelSeekableStream *stream)
127 return stream->cur_pos;
132 /* a default implementation of reset for seekable streams */
134 _reset (CamelStream *stream)
136 CamelSeekableStream *seekable_stream;
139 seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
141 camel_seekable_stream_seek (seekable_stream, 0, CAMEL_STREAM_SET);