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"
31 * SECTION:gfilteroutputstream
32 * @short_description: Filter Output Stream
42 static void g_filter_output_stream_set_property (GObject
*object
,
47 static void g_filter_output_stream_get_property (GObject
*object
,
51 static void g_filter_output_stream_dispose (GObject
*object
);
54 static gssize
g_filter_output_stream_write (GOutputStream
*stream
,
57 GCancellable
*cancellable
,
59 static gboolean
g_filter_output_stream_flush (GOutputStream
*stream
,
60 GCancellable
*cancellable
,
62 static gboolean
g_filter_output_stream_close (GOutputStream
*stream
,
63 GCancellable
*cancellable
,
65 static void g_filter_output_stream_write_async (GOutputStream
*stream
,
69 GCancellable
*cancellable
,
70 GAsyncReadyCallback callback
,
72 static gssize
g_filter_output_stream_write_finish (GOutputStream
*stream
,
75 static void g_filter_output_stream_flush_async (GOutputStream
*stream
,
77 GCancellable
*cancellable
,
78 GAsyncReadyCallback callback
,
80 static gboolean
g_filter_output_stream_flush_finish (GOutputStream
*stream
,
83 static void g_filter_output_stream_close_async (GOutputStream
*stream
,
85 GCancellable
*cancellable
,
86 GAsyncReadyCallback callback
,
88 static gboolean
g_filter_output_stream_close_finish (GOutputStream
*stream
,
94 G_DEFINE_TYPE (GFilterOutputStream
, g_filter_output_stream
, G_TYPE_OUTPUT_STREAM
)
99 g_filter_output_stream_class_init (GFilterOutputStreamClass
*klass
)
101 GObjectClass
*object_class
;
102 GOutputStreamClass
*ostream_class
;
104 object_class
= G_OBJECT_CLASS (klass
);
105 object_class
->get_property
= g_filter_output_stream_get_property
;
106 object_class
->set_property
= g_filter_output_stream_set_property
;
107 object_class
->dispose
= g_filter_output_stream_dispose
;
109 ostream_class
= G_OUTPUT_STREAM_CLASS (klass
);
110 ostream_class
->write_fn
= g_filter_output_stream_write
;
111 ostream_class
->flush
= g_filter_output_stream_flush
;
112 ostream_class
->close_fn
= g_filter_output_stream_close
;
113 ostream_class
->write_async
= g_filter_output_stream_write_async
;
114 ostream_class
->write_finish
= g_filter_output_stream_write_finish
;
115 ostream_class
->flush_async
= g_filter_output_stream_flush_async
;
116 ostream_class
->flush_finish
= g_filter_output_stream_flush_finish
;
117 ostream_class
->close_async
= g_filter_output_stream_close_async
;
118 ostream_class
->close_finish
= g_filter_output_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"),
125 G_TYPE_OUTPUT_STREAM
,
126 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
|
127 G_PARAM_STATIC_NAME
|G_PARAM_STATIC_NICK
|G_PARAM_STATIC_BLURB
));
132 g_filter_output_stream_set_property (GObject
*object
,
137 GFilterOutputStream
*filter_stream
;
140 filter_stream
= G_FILTER_OUTPUT_STREAM (object
);
144 case PROP_BASE_STREAM
:
145 obj
= g_value_dup_object (value
);
146 filter_stream
->base_stream
= G_OUTPUT_STREAM (obj
);
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
157 g_filter_output_stream_get_property (GObject
*object
,
162 GFilterOutputStream
*filter_stream
;
164 filter_stream
= G_FILTER_OUTPUT_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_output_stream_dispose (GObject
*object
)
182 GFilterOutputStream
*stream
;
184 stream
= G_FILTER_OUTPUT_STREAM (object
);
186 G_OBJECT_CLASS (g_filter_output_stream_parent_class
)->dispose (object
);
188 if (stream
->base_stream
)
190 g_object_unref (stream
->base_stream
);
191 stream
->base_stream
= NULL
;
197 g_filter_output_stream_init (GFilterOutputStream
*stream
)
202 * g_filter_output_stream_get_base_stream:
203 * @stream: a #GFilterOutputStream.
205 * Gets the base stream for the filter stream.
207 * Returns: a #GOutputStream.
210 g_filter_output_stream_get_base_stream (GFilterOutputStream
*stream
)
212 g_return_val_if_fail (G_IS_FILTER_OUTPUT_STREAM (stream
), NULL
);
214 return stream
->base_stream
;
218 g_filter_output_stream_write (GOutputStream
*stream
,
221 GCancellable
*cancellable
,
224 GFilterOutputStream
*filter_stream
;
227 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
229 nwritten
= g_output_stream_write (filter_stream
->base_stream
,
239 g_filter_output_stream_flush (GOutputStream
*stream
,
240 GCancellable
*cancellable
,
243 GFilterOutputStream
*filter_stream
;
246 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
248 res
= g_output_stream_flush (filter_stream
->base_stream
,
256 g_filter_output_stream_close (GOutputStream
*stream
,
257 GCancellable
*cancellable
,
260 GFilterOutputStream
*filter_stream
;
263 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
265 res
= g_output_stream_close (filter_stream
->base_stream
,
273 g_filter_output_stream_write_async (GOutputStream
*stream
,
277 GCancellable
*cancellable
,
278 GAsyncReadyCallback callback
,
281 GFilterOutputStream
*filter_stream
;
283 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
285 g_output_stream_write_async (filter_stream
->base_stream
,
296 g_filter_output_stream_write_finish (GOutputStream
*stream
,
297 GAsyncResult
*result
,
300 GFilterOutputStream
*filter_stream
;
303 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
305 nwritten
= g_output_stream_write_finish (filter_stream
->base_stream
,
313 g_filter_output_stream_flush_async (GOutputStream
*stream
,
315 GCancellable
*cancellable
,
316 GAsyncReadyCallback callback
,
319 GFilterOutputStream
*filter_stream
;
321 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
323 g_output_stream_flush_async (filter_stream
->base_stream
,
331 g_filter_output_stream_flush_finish (GOutputStream
*stream
,
332 GAsyncResult
*result
,
335 GFilterOutputStream
*filter_stream
;
338 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
340 res
= g_output_stream_flush_finish (filter_stream
->base_stream
,
348 g_filter_output_stream_close_async (GOutputStream
*stream
,
350 GCancellable
*cancellable
,
351 GAsyncReadyCallback callback
,
354 GFilterOutputStream
*filter_stream
;
356 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
358 g_output_stream_close_async (filter_stream
->base_stream
,
366 g_filter_output_stream_close_finish (GOutputStream
*stream
,
367 GAsyncResult
*result
,
370 GFilterOutputStream
*filter_stream
;
373 filter_stream
= G_FILTER_OUTPUT_STREAM (stream
);
375 res
= g_output_stream_close_finish (filter_stream
->base_stream
,
382 #define __G_FILTER_OUTPUT_STREAM_C__
383 #include "gioaliasdef.c"