Bug 561807 – inotify_sub.c :: dup_dirname() fails to remove trailing '/'
[glib.git] / gio / gfilteroutputstream.c
blob9881ab1803d1a54ac462402cce480c40fd2d3a3e
1 /* GIO - GLib Input, Output and Streaming Library
2 *
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>
23 #include "config.h"
24 #include "gfilteroutputstream.h"
25 #include "goutputstream.h"
26 #include "glibintl.h"
28 #include "gioalias.h"
30 /**
31 * SECTION:gfilteroutputstream
32 * @short_description: Filter Output Stream
33 * @include: gio/gio.h
35 **/
37 enum {
38 PROP_0,
39 PROP_BASE_STREAM
42 static void g_filter_output_stream_set_property (GObject *object,
43 guint prop_id,
44 const GValue *value,
45 GParamSpec *pspec);
47 static void g_filter_output_stream_get_property (GObject *object,
48 guint prop_id,
49 GValue *value,
50 GParamSpec *pspec);
51 static void g_filter_output_stream_dispose (GObject *object);
54 static gssize g_filter_output_stream_write (GOutputStream *stream,
55 const void *buffer,
56 gsize count,
57 GCancellable *cancellable,
58 GError **error);
59 static gboolean g_filter_output_stream_flush (GOutputStream *stream,
60 GCancellable *cancellable,
61 GError **error);
62 static gboolean g_filter_output_stream_close (GOutputStream *stream,
63 GCancellable *cancellable,
64 GError **error);
65 static void g_filter_output_stream_write_async (GOutputStream *stream,
66 const void *buffer,
67 gsize count,
68 int io_priority,
69 GCancellable *cancellable,
70 GAsyncReadyCallback callback,
71 gpointer data);
72 static gssize g_filter_output_stream_write_finish (GOutputStream *stream,
73 GAsyncResult *result,
74 GError **error);
75 static void g_filter_output_stream_flush_async (GOutputStream *stream,
76 int io_priority,
77 GCancellable *cancellable,
78 GAsyncReadyCallback callback,
79 gpointer data);
80 static gboolean g_filter_output_stream_flush_finish (GOutputStream *stream,
81 GAsyncResult *result,
82 GError **error);
83 static void g_filter_output_stream_close_async (GOutputStream *stream,
84 int io_priority,
85 GCancellable *cancellable,
86 GAsyncReadyCallback callback,
87 gpointer data);
88 static gboolean g_filter_output_stream_close_finish (GOutputStream *stream,
89 GAsyncResult *result,
90 GError **error);
94 G_DEFINE_TYPE (GFilterOutputStream, g_filter_output_stream, G_TYPE_OUTPUT_STREAM)
98 static void
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,
121 PROP_BASE_STREAM,
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));
131 static void
132 g_filter_output_stream_set_property (GObject *object,
133 guint prop_id,
134 const GValue *value,
135 GParamSpec *pspec)
137 GFilterOutputStream *filter_stream;
138 GObject *obj;
140 filter_stream = G_FILTER_OUTPUT_STREAM (object);
142 switch (prop_id)
144 case PROP_BASE_STREAM:
145 obj = g_value_dup_object (value);
146 filter_stream->base_stream = G_OUTPUT_STREAM (obj);
147 break;
149 default:
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
151 break;
156 static void
157 g_filter_output_stream_get_property (GObject *object,
158 guint prop_id,
159 GValue *value,
160 GParamSpec *pspec)
162 GFilterOutputStream *filter_stream;
164 filter_stream = G_FILTER_OUTPUT_STREAM (object);
166 switch (prop_id)
168 case PROP_BASE_STREAM:
169 g_value_set_object (value, filter_stream->base_stream);
170 break;
172 default:
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
174 break;
179 static void
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;
196 static void
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.
209 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;
217 static gssize
218 g_filter_output_stream_write (GOutputStream *stream,
219 const void *buffer,
220 gsize count,
221 GCancellable *cancellable,
222 GError **error)
224 GFilterOutputStream *filter_stream;
225 gssize nwritten;
227 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
229 nwritten = g_output_stream_write (filter_stream->base_stream,
230 buffer,
231 count,
232 cancellable,
233 error);
235 return nwritten;
238 static gboolean
239 g_filter_output_stream_flush (GOutputStream *stream,
240 GCancellable *cancellable,
241 GError **error)
243 GFilterOutputStream *filter_stream;
244 gboolean res;
246 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
248 res = g_output_stream_flush (filter_stream->base_stream,
249 cancellable,
250 error);
252 return res;
255 static gboolean
256 g_filter_output_stream_close (GOutputStream *stream,
257 GCancellable *cancellable,
258 GError **error)
260 GFilterOutputStream *filter_stream;
261 gboolean res;
263 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
265 res = g_output_stream_close (filter_stream->base_stream,
266 cancellable,
267 error);
269 return res;
272 static void
273 g_filter_output_stream_write_async (GOutputStream *stream,
274 const void *buffer,
275 gsize count,
276 int io_priority,
277 GCancellable *cancellable,
278 GAsyncReadyCallback callback,
279 gpointer data)
281 GFilterOutputStream *filter_stream;
283 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
285 g_output_stream_write_async (filter_stream->base_stream,
286 buffer,
287 count,
288 io_priority,
289 cancellable,
290 callback,
291 data);
295 static gssize
296 g_filter_output_stream_write_finish (GOutputStream *stream,
297 GAsyncResult *result,
298 GError **error)
300 GFilterOutputStream *filter_stream;
301 gssize nwritten;
303 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
305 nwritten = g_output_stream_write_finish (filter_stream->base_stream,
306 result,
307 error);
309 return nwritten;
312 static void
313 g_filter_output_stream_flush_async (GOutputStream *stream,
314 int io_priority,
315 GCancellable *cancellable,
316 GAsyncReadyCallback callback,
317 gpointer data)
319 GFilterOutputStream *filter_stream;
321 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
323 g_output_stream_flush_async (filter_stream->base_stream,
324 io_priority,
325 cancellable,
326 callback,
327 data);
330 static gboolean
331 g_filter_output_stream_flush_finish (GOutputStream *stream,
332 GAsyncResult *result,
333 GError **error)
335 GFilterOutputStream *filter_stream;
336 gboolean res;
338 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
340 res = g_output_stream_flush_finish (filter_stream->base_stream,
341 result,
342 error);
344 return res;
347 static void
348 g_filter_output_stream_close_async (GOutputStream *stream,
349 int io_priority,
350 GCancellable *cancellable,
351 GAsyncReadyCallback callback,
352 gpointer data)
354 GFilterOutputStream *filter_stream;
356 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
358 g_output_stream_close_async (filter_stream->base_stream,
359 io_priority,
360 cancellable,
361 callback,
362 data);
365 static gboolean
366 g_filter_output_stream_close_finish (GOutputStream *stream,
367 GAsyncResult *result,
368 GError **error)
370 GFilterOutputStream *filter_stream;
371 gboolean res;
373 filter_stream = G_FILTER_OUTPUT_STREAM (stream);
375 res = g_output_stream_close_finish (filter_stream->base_stream,
376 result,
377 error);
379 return res;
382 #define __G_FILTER_OUTPUT_STREAM_C__
383 #include "gioaliasdef.c"