1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Christian Kellner <gicmo@gnome.org>
24 #include "gfilterinputstream.h"
25 #include "ginputstream.h"
31 * SECTION:gfilterinputstream
32 * @short_description: Filter Input Stream
42 static void g_filter_input_stream_set_property (GObject *object,
47 static void g_filter_input_stream_get_property (GObject *object,
51 static void g_filter_input_stream_finalize (GObject *object);
54 static gssize g_filter_input_stream_read (GInputStream *stream,
57 GCancellable *cancellable,
59 static gssize g_filter_input_stream_skip (GInputStream *stream,
61 GCancellable *cancellable,
63 static gboolean g_filter_input_stream_close (GInputStream *stream,
64 GCancellable *cancellable,
66 static void g_filter_input_stream_read_async (GInputStream *stream,
70 GCancellable *cancellable,
71 GAsyncReadyCallback callback,
73 static gssize g_filter_input_stream_read_finish (GInputStream *stream,
76 static void g_filter_input_stream_skip_async (GInputStream *stream,
79 GCancellable *cancellabl,
80 GAsyncReadyCallback callback,
82 static gssize g_filter_input_stream_skip_finish (GInputStream *stream,
85 static void g_filter_input_stream_close_async (GInputStream *stream,
87 GCancellable *cancellabl,
88 GAsyncReadyCallback callback,
90 static gboolean g_filter_input_stream_close_finish (GInputStream *stream,
94 G_DEFINE_TYPE (GFilterInputStream, g_filter_input_stream, G_TYPE_INPUT_STREAM)
98 g_filter_input_stream_class_init (GFilterInputStreamClass *klass)
100 GObjectClass *object_class;
101 GInputStreamClass *istream_class;
103 object_class = G_OBJECT_CLASS (klass);
104 object_class->get_property = g_filter_input_stream_get_property;
105 object_class->set_property = g_filter_input_stream_set_property;
106 object_class->finalize = g_filter_input_stream_finalize;
108 istream_class = G_INPUT_STREAM_CLASS (klass);
109 istream_class->read_fn = g_filter_input_stream_read;
110 istream_class->skip = g_filter_input_stream_skip;
111 istream_class->close_fn = g_filter_input_stream_close;
113 istream_class->read_async = g_filter_input_stream_read_async;
114 istream_class->read_finish = g_filter_input_stream_read_finish;
115 istream_class->skip_async = g_filter_input_stream_skip_async;
116 istream_class->skip_finish = g_filter_input_stream_skip_finish;
117 istream_class->close_async = g_filter_input_stream_close_async;
118 istream_class->close_finish = g_filter_input_stream_close_finish;
120 g_object_class_install_property (object_class,
122 g_param_spec_object ("base-stream",
123 P_("The Filter Base Stream"),
124 P_("The underlying base stream the io ops will be done on"),
126 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
127 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
132 g_filter_input_stream_set_property (GObject *object,
137 GFilterInputStream *filter_stream;
140 filter_stream = G_FILTER_INPUT_STREAM (object);
144 case PROP_BASE_STREAM:
145 obj = g_value_dup_object (value);
146 filter_stream->base_stream = G_INPUT_STREAM (obj);
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
157 g_filter_input_stream_get_property (GObject *object,
162 GFilterInputStream *filter_stream;
164 filter_stream = G_FILTER_INPUT_STREAM (object);
168 case PROP_BASE_STREAM:
169 g_value_set_object (value, filter_stream->base_stream);
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
180 g_filter_input_stream_finalize (GObject *object)
182 GFilterInputStream *stream;
184 stream = G_FILTER_INPUT_STREAM (object);
186 g_object_unref (stream->base_stream);
188 G_OBJECT_CLASS (g_filter_input_stream_parent_class)->finalize (object);
192 g_filter_input_stream_init (GFilterInputStream *stream)
198 * g_filter_input_stream_get_base_stream:
199 * @stream: a #GFilterInputStream.
201 * Gets the base stream for the filter stream.
203 * Returns: a #GInputStream.
206 g_filter_input_stream_get_base_stream (GFilterInputStream *stream)
208 g_return_val_if_fail (G_IS_FILTER_INPUT_STREAM (stream), NULL);
210 return stream->base_stream;
214 g_filter_input_stream_read (GInputStream *stream,
217 GCancellable *cancellable,
220 GFilterInputStream *filter_stream;
221 GInputStream *base_stream;
224 filter_stream = G_FILTER_INPUT_STREAM (stream);
225 base_stream = filter_stream->base_stream;
227 nread = g_input_stream_read (base_stream,
237 g_filter_input_stream_skip (GInputStream *stream,
239 GCancellable *cancellable,
242 GFilterInputStream *filter_stream;
243 GInputStream *base_stream;
246 filter_stream = G_FILTER_INPUT_STREAM (stream);
247 base_stream = filter_stream->base_stream;
249 nskipped = g_input_stream_skip (base_stream,
257 g_filter_input_stream_close (GInputStream *stream,
258 GCancellable *cancellable,
261 GFilterInputStream *filter_stream;
262 GInputStream *base_stream;
265 filter_stream = G_FILTER_INPUT_STREAM (stream);
266 base_stream = filter_stream->base_stream;
268 res = g_input_stream_close (base_stream,
276 g_filter_input_stream_read_async (GInputStream *stream,
280 GCancellable *cancellable,
281 GAsyncReadyCallback callback,
284 GFilterInputStream *filter_stream;
285 GInputStream *base_stream;
287 filter_stream = G_FILTER_INPUT_STREAM (stream);
288 base_stream = filter_stream->base_stream;
290 g_input_stream_read_async (base_stream,
300 g_filter_input_stream_read_finish (GInputStream *stream,
301 GAsyncResult *result,
304 GFilterInputStream *filter_stream;
305 GInputStream *base_stream;
308 filter_stream = G_FILTER_INPUT_STREAM (stream);
309 base_stream = filter_stream->base_stream;
311 nread = g_input_stream_read_finish (base_stream,
319 g_filter_input_stream_skip_async (GInputStream *stream,
322 GCancellable *cancellable,
323 GAsyncReadyCallback callback,
326 GFilterInputStream *filter_stream;
327 GInputStream *base_stream;
329 filter_stream = G_FILTER_INPUT_STREAM (stream);
330 base_stream = filter_stream->base_stream;
332 g_input_stream_skip_async (base_stream,
342 g_filter_input_stream_skip_finish (GInputStream *stream,
343 GAsyncResult *result,
346 GFilterInputStream *filter_stream;
347 GInputStream *base_stream;
350 filter_stream = G_FILTER_INPUT_STREAM (stream);
351 base_stream = filter_stream->base_stream;
353 nskipped = g_input_stream_skip_finish (base_stream,
361 g_filter_input_stream_close_async (GInputStream *stream,
363 GCancellable *cancellable,
364 GAsyncReadyCallback callback,
367 GFilterInputStream *filter_stream;
368 GInputStream *base_stream;
370 filter_stream = G_FILTER_INPUT_STREAM (stream);
371 base_stream = filter_stream->base_stream;
373 g_input_stream_close_async (base_stream,
381 g_filter_input_stream_close_finish (GInputStream *stream,
382 GAsyncResult *result,
385 GFilterInputStream *filter_stream;
386 GInputStream *base_stream;
389 filter_stream = G_FILTER_INPUT_STREAM (stream);
390 base_stream = filter_stream->base_stream;
392 res = g_input_stream_close_finish (stream,
399 #define __G_FILTER_INPUT_STREAM_C__
400 #include "gioaliasdef.c"