More trivial doc fixes
[platform/upstream/glib.git] / gio / gfilteroutputstream.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Christian Kellner <gicmo@gnome.org> 
21  */
22
23 #include <config.h>
24 #include "gfilteroutputstream.h"
25 #include "goutputstream.h"
26 #include "glibintl.h"
27
28 /**
29  * SECTION:gfilteroutputstream
30  * @short_description: Filter Output Stream
31  *
32  **/
33
34 enum {
35   PROP_0,
36   PROP_BASE_STREAM
37 };
38
39 static void     g_filter_output_stream_set_property (GObject      *object,
40                                                      guint         prop_id,
41                                                      const GValue *value,
42                                                      GParamSpec   *pspec);
43
44 static void     g_filter_output_stream_get_property (GObject    *object,
45                                                      guint       prop_id,
46                                                      GValue     *value,
47                                                      GParamSpec *pspec);
48 static void     g_filter_output_stream_dispose      (GObject *object);
49
50
51 static gssize   g_filter_output_stream_write        (GOutputStream *stream,
52                                                      const void    *buffer,
53                                                      gsize          count,
54                                                      GCancellable  *cancellable,
55                                                      GError       **error);
56 static gboolean g_filter_output_stream_flush        (GOutputStream    *stream,
57                                                      GCancellable  *cancellable,
58                                                      GError          **error);
59 static gboolean g_filter_output_stream_close        (GOutputStream  *stream,
60                                                      GCancellable   *cancellable,
61                                                      GError        **error);
62 static void     g_filter_output_stream_write_async  (GOutputStream        *stream,
63                                                      const void           *buffer,
64                                                      gsize                 count,
65                                                      int                   io_priority,
66                                                      GCancellable         *cancellable,
67                                                      GAsyncReadyCallback   callback,
68                                                      gpointer              data);
69 static gssize   g_filter_output_stream_write_finish (GOutputStream        *stream,
70                                                      GAsyncResult         *result,
71                                                      GError              **error);
72 static void     g_filter_output_stream_flush_async  (GOutputStream        *stream,
73                                                      int                   io_priority,
74                                                      GCancellable         *cancellable,
75                                                      GAsyncReadyCallback   callback,
76                                                      gpointer              data);
77 static gboolean g_filter_output_stream_flush_finish (GOutputStream        *stream,
78                                                      GAsyncResult         *result,
79                                                      GError              **error);
80 static void     g_filter_output_stream_close_async  (GOutputStream        *stream,
81                                                      int                   io_priority,
82                                                      GCancellable         *cancellable,
83                                                      GAsyncReadyCallback   callback,
84                                                      gpointer              data);
85 static gboolean g_filter_output_stream_close_finish (GOutputStream        *stream,
86                                                      GAsyncResult         *result,
87                                                      GError              **error);
88
89
90
91 G_DEFINE_TYPE (GFilterOutputStream, g_filter_output_stream, G_TYPE_OUTPUT_STREAM)
92
93
94
95 static void
96 g_filter_output_stream_class_init (GFilterOutputStreamClass *klass)
97 {
98   GObjectClass *object_class;
99   GOutputStreamClass *ostream_class;
100
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;
105     
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;
116
117   g_object_class_install_property (object_class,
118                                    PROP_BASE_STREAM,
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));
125
126 }
127
128 static void
129 g_filter_output_stream_set_property (GObject         *object,
130                                      guint            prop_id,
131                                      const GValue    *value,
132                                      GParamSpec      *pspec)
133 {
134   GFilterOutputStream *filter_stream;
135   GObject *obj;
136
137   filter_stream = G_FILTER_OUTPUT_STREAM (object);
138
139   switch (prop_id) 
140     {
141     case PROP_BASE_STREAM:
142       obj = g_value_dup_object (value);
143       filter_stream->base_stream = G_OUTPUT_STREAM (obj);
144       break;
145
146     default:
147       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148       break;
149     }
150
151 }
152
153 static void
154 g_filter_output_stream_get_property (GObject    *object,
155                                      guint       prop_id,
156                                      GValue     *value,
157                                      GParamSpec *pspec)
158 {
159   GFilterOutputStream *filter_stream;
160
161   filter_stream = G_FILTER_OUTPUT_STREAM (object);
162
163   switch (prop_id)
164     {
165     case PROP_BASE_STREAM:
166       g_value_set_object (value, filter_stream->base_stream);
167       break;
168
169     default:
170       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171       break;
172     }
173
174 }
175
176 static void
177 g_filter_output_stream_dispose (GObject *object)
178 {
179   GFilterOutputStream        *stream;
180
181   stream = G_FILTER_OUTPUT_STREAM (object);
182
183   G_OBJECT_CLASS (g_filter_output_stream_parent_class)->dispose (object);
184   
185   if (stream->base_stream)
186     {
187       g_object_unref (stream->base_stream);
188       stream->base_stream = NULL;
189     }
190 }
191
192
193 static void
194 g_filter_output_stream_init (GFilterOutputStream *stream)
195 {
196 }
197
198 /**
199  * g_filter_output_stream_get_base_stream:
200  * @stream: a #GFilterOutputStream.
201  * 
202  * Gets the base stream for the filter stream.
203  *
204  * Returns: a #GOutputStream.
205  **/
206 GOutputStream *
207 g_filter_output_stream_get_base_stream (GFilterOutputStream *stream)
208 {
209   g_return_val_if_fail (G_IS_FILTER_OUTPUT_STREAM (stream), NULL);
210
211   return stream->base_stream;
212 }
213
214 static gssize
215 g_filter_output_stream_write (GOutputStream *stream,
216                               const void *buffer,
217                               gsize          count,
218                               GCancellable  *cancellable,
219                               GError       **error)
220 {
221   GFilterOutputStream *filter_stream;
222   gssize nwritten;
223
224   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
225
226   nwritten = g_output_stream_write (filter_stream->base_stream,
227                                     buffer,
228                                     count,
229                                     cancellable,
230                                     error);
231
232   return nwritten;
233 }
234
235 static gboolean
236 g_filter_output_stream_flush (GOutputStream    *stream,
237                               GCancellable  *cancellable,
238                               GError          **error)
239 {
240   GFilterOutputStream *filter_stream;
241   gboolean res;
242
243   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
244
245   res = g_output_stream_flush (filter_stream->base_stream,
246                                cancellable,
247                                error);
248
249   return res;
250 }
251
252 static gboolean
253 g_filter_output_stream_close (GOutputStream  *stream,
254                               GCancellable   *cancellable,
255                               GError        **error)
256 {
257   GFilterOutputStream *filter_stream;
258   gboolean res;
259
260   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
261
262   res = g_output_stream_close (filter_stream->base_stream,
263                                cancellable,
264                                error);
265
266   return res;
267 }
268
269 static void
270 g_filter_output_stream_write_async (GOutputStream        *stream,
271                                     const void           *buffer,
272                                     gsize                 count,
273                                     int                   io_priority,
274                                     GCancellable         *cancellable,
275                                     GAsyncReadyCallback   callback,
276                                     gpointer              data)
277 {
278   GFilterOutputStream *filter_stream;
279
280   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
281
282   g_output_stream_write_async (filter_stream->base_stream,
283                                buffer,
284                                count,
285                                io_priority,
286                                cancellable,
287                                callback,
288                                data);
289
290 }
291
292 static gssize
293 g_filter_output_stream_write_finish (GOutputStream        *stream,
294                                      GAsyncResult         *result,
295                                      GError              **error)
296 {
297   GFilterOutputStream *filter_stream;
298   gssize nwritten;
299
300   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
301
302   nwritten = g_output_stream_write_finish (filter_stream->base_stream,
303                                            result,
304                                            error);
305
306   return nwritten;
307 }
308
309 static void
310 g_filter_output_stream_flush_async (GOutputStream        *stream,
311                                     int                   io_priority,
312                                     GCancellable         *cancellable,
313                                     GAsyncReadyCallback   callback,
314                                     gpointer              data)
315 {
316   GFilterOutputStream *filter_stream;
317
318   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
319
320   g_output_stream_flush_async (filter_stream->base_stream,
321                                io_priority,
322                                cancellable,
323                                callback,
324                                data);
325 }
326
327 static gboolean
328 g_filter_output_stream_flush_finish (GOutputStream        *stream,
329                                      GAsyncResult         *result,
330                                      GError              **error)
331 {
332   GFilterOutputStream *filter_stream;
333   gboolean res;
334
335   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
336
337   res = g_output_stream_flush_finish (filter_stream->base_stream,
338                                       result,
339                                       error);
340
341   return res;
342 }
343
344 static void
345 g_filter_output_stream_close_async (GOutputStream        *stream,
346                                     int                   io_priority,
347                                     GCancellable         *cancellable,
348                                     GAsyncReadyCallback   callback,
349                                     gpointer              data)
350 {
351   GFilterOutputStream *filter_stream;
352
353   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
354
355   g_output_stream_close_async (filter_stream->base_stream,
356                                io_priority,
357                                cancellable,
358                                callback,
359                                data);
360 }
361
362 static gboolean
363 g_filter_output_stream_close_finish (GOutputStream        *stream,
364                                      GAsyncResult         *result,
365                                      GError              **error)
366 {
367   GFilterOutputStream *filter_stream;
368   gboolean res;
369
370   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
371
372   res = g_output_stream_close_finish (filter_stream->base_stream,
373                                       result,
374                                       error);
375
376   return res;
377 }
378
379
380 /* vim: ts=2 sw=2 et */