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 "gfilteroutputstream.h"
25 #include "goutputstream.h"
29 * SECTION:gfilteroutputstream
30 * @short_description: Filter Output Stream
39 static void g_filter_output_stream_set_property (GObject *object,
44 static void g_filter_output_stream_get_property (GObject *object,
48 static void g_filter_output_stream_dispose (GObject *object);
51 static gssize g_filter_output_stream_write (GOutputStream *stream,
54 GCancellable *cancellable,
56 static gboolean g_filter_output_stream_flush (GOutputStream *stream,
57 GCancellable *cancellable,
59 static gboolean g_filter_output_stream_close (GOutputStream *stream,
60 GCancellable *cancellable,
62 static void g_filter_output_stream_write_async (GOutputStream *stream,
66 GCancellable *cancellable,
67 GAsyncReadyCallback callback,
69 static gssize g_filter_output_stream_write_finish (GOutputStream *stream,
72 static void g_filter_output_stream_flush_async (GOutputStream *stream,
74 GCancellable *cancellable,
75 GAsyncReadyCallback callback,
77 static gboolean g_filter_output_stream_flush_finish (GOutputStream *stream,
80 static void g_filter_output_stream_close_async (GOutputStream *stream,
82 GCancellable *cancellable,
83 GAsyncReadyCallback callback,
85 static gboolean g_filter_output_stream_close_finish (GOutputStream *stream,
91 G_DEFINE_TYPE (GFilterOutputStream, g_filter_output_stream, G_TYPE_OUTPUT_STREAM)
96 g_filter_output_stream_class_init (GFilterOutputStreamClass *klass)
98 GObjectClass *object_class;
99 GOutputStreamClass *ostream_class;
101 object_class = G_OBJECT_CLASS (klass);
102 object_class->get_property = g_filter_output_stream_get_property;
103 object_class->set_property = g_filter_output_stream_set_property;
104 object_class->dispose = g_filter_output_stream_dispose;
106 ostream_class = G_OUTPUT_STREAM_CLASS (klass);
107 ostream_class->write = g_filter_output_stream_write;
108 ostream_class->flush = g_filter_output_stream_flush;
109 ostream_class->close = g_filter_output_stream_close;
110 ostream_class->write_async = g_filter_output_stream_write_async;
111 ostream_class->write_finish = g_filter_output_stream_write_finish;
112 ostream_class->flush_async = g_filter_output_stream_flush_async;
113 ostream_class->flush_finish = g_filter_output_stream_flush_finish;
114 ostream_class->close_async = g_filter_output_stream_close_async;
115 ostream_class->close_finish = g_filter_output_stream_close_finish;
117 g_object_class_install_property (object_class,
119 g_param_spec_object ("base-stream",
120 P_("The Filter Base Stream"),
121 P_("The underlying base stream the io ops will be done on"),
122 G_TYPE_OUTPUT_STREAM,
123 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
124 G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
129 g_filter_output_stream_set_property (GObject *object,
134 GFilterOutputStream *filter_stream;
137 filter_stream = G_FILTER_OUTPUT_STREAM (object);
141 case PROP_BASE_STREAM:
142 obj = g_value_dup_object (value);
143 filter_stream->base_stream = G_OUTPUT_STREAM (obj);
147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
154 g_filter_output_stream_get_property (GObject *object,
159 GFilterOutputStream *filter_stream;
161 filter_stream = G_FILTER_OUTPUT_STREAM (object);
165 case PROP_BASE_STREAM:
166 g_value_set_object (value, filter_stream->base_stream);
170 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
177 g_filter_output_stream_dispose (GObject *object)
179 GFilterOutputStream *stream;
181 stream = G_FILTER_OUTPUT_STREAM (object);
183 G_OBJECT_CLASS (g_filter_output_stream_parent_class)->dispose (object);
185 if (stream->base_stream)
187 g_object_unref (stream->base_stream);
188 stream->base_stream = NULL;
194 g_filter_output_stream_init (GFilterOutputStream *stream)
199 g_filter_output_stream_get_base_stream (GFilterOutputStream *stream)
201 g_return_val_if_fail (G_IS_FILTER_OUTPUT_STREAM (stream), NULL);
203 return stream->base_stream;
207 g_filter_output_stream_write (GOutputStream *stream,
210 GCancellable *cancellable,
213 GFilterOutputStream *filter_stream;
216 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
218 nwritten = g_output_stream_write (filter_stream->base_stream,
228 g_filter_output_stream_flush (GOutputStream *stream,
229 GCancellable *cancellable,
232 GFilterOutputStream *filter_stream;
235 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
237 res = g_output_stream_flush (filter_stream->base_stream,
245 g_filter_output_stream_close (GOutputStream *stream,
246 GCancellable *cancellable,
249 GFilterOutputStream *filter_stream;
252 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
254 res = g_output_stream_close (filter_stream->base_stream,
262 g_filter_output_stream_write_async (GOutputStream *stream,
266 GCancellable *cancellable,
267 GAsyncReadyCallback callback,
270 GFilterOutputStream *filter_stream;
272 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
274 g_output_stream_write_async (filter_stream->base_stream,
285 g_filter_output_stream_write_finish (GOutputStream *stream,
286 GAsyncResult *result,
289 GFilterOutputStream *filter_stream;
292 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
294 nwritten = g_output_stream_write_finish (filter_stream->base_stream,
302 g_filter_output_stream_flush_async (GOutputStream *stream,
304 GCancellable *cancellable,
305 GAsyncReadyCallback callback,
308 GFilterOutputStream *filter_stream;
310 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
312 g_output_stream_flush_async (filter_stream->base_stream,
320 g_filter_output_stream_flush_finish (GOutputStream *stream,
321 GAsyncResult *result,
324 GFilterOutputStream *filter_stream;
327 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
329 res = g_output_stream_flush_finish (filter_stream->base_stream,
337 g_filter_output_stream_close_async (GOutputStream *stream,
339 GCancellable *cancellable,
340 GAsyncReadyCallback callback,
343 GFilterOutputStream *filter_stream;
345 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
347 g_output_stream_close_async (filter_stream->base_stream,
355 g_filter_output_stream_close_finish (GOutputStream *stream,
356 GAsyncResult *result,
359 GFilterOutputStream *filter_stream;
362 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
364 res = g_output_stream_close_finish (filter_stream->base_stream,
372 /* vim: ts=2 sw=2 et */