Bumps documentation to 93% symbol coverage, touching most
[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 GOutputStream *
199 g_filter_output_stream_get_base_stream (GFilterOutputStream *stream)
200 {
201   g_return_val_if_fail (G_IS_FILTER_OUTPUT_STREAM (stream), NULL);
202
203   return stream->base_stream;
204 }
205
206 static gssize
207 g_filter_output_stream_write (GOutputStream *stream,
208                               const void *buffer,
209                               gsize          count,
210                               GCancellable  *cancellable,
211                               GError       **error)
212 {
213   GFilterOutputStream *filter_stream;
214   gssize nwritten;
215
216   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
217
218   nwritten = g_output_stream_write (filter_stream->base_stream,
219                                     buffer,
220                                     count,
221                                     cancellable,
222                                     error);
223
224   return nwritten;
225 }
226
227 static gboolean
228 g_filter_output_stream_flush (GOutputStream    *stream,
229                               GCancellable  *cancellable,
230                               GError          **error)
231 {
232   GFilterOutputStream *filter_stream;
233   gboolean res;
234
235   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
236
237   res = g_output_stream_flush (filter_stream->base_stream,
238                                cancellable,
239                                error);
240
241   return res;
242 }
243
244 static gboolean
245 g_filter_output_stream_close (GOutputStream  *stream,
246                               GCancellable   *cancellable,
247                               GError        **error)
248 {
249   GFilterOutputStream *filter_stream;
250   gboolean res;
251
252   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
253
254   res = g_output_stream_close (filter_stream->base_stream,
255                                cancellable,
256                                error);
257
258   return res;
259 }
260
261 static void
262 g_filter_output_stream_write_async (GOutputStream        *stream,
263                                     const void           *buffer,
264                                     gsize                 count,
265                                     int                   io_priority,
266                                     GCancellable         *cancellable,
267                                     GAsyncReadyCallback   callback,
268                                     gpointer              data)
269 {
270   GFilterOutputStream *filter_stream;
271
272   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
273
274   g_output_stream_write_async (filter_stream->base_stream,
275                                buffer,
276                                count,
277                                io_priority,
278                                cancellable,
279                                callback,
280                                data);
281
282 }
283
284 static gssize
285 g_filter_output_stream_write_finish (GOutputStream        *stream,
286                                      GAsyncResult         *result,
287                                      GError              **error)
288 {
289   GFilterOutputStream *filter_stream;
290   gssize nwritten;
291
292   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
293
294   nwritten = g_output_stream_write_finish (filter_stream->base_stream,
295                                            result,
296                                            error);
297
298   return nwritten;
299 }
300
301 static void
302 g_filter_output_stream_flush_async (GOutputStream        *stream,
303                                     int                   io_priority,
304                                     GCancellable         *cancellable,
305                                     GAsyncReadyCallback   callback,
306                                     gpointer              data)
307 {
308   GFilterOutputStream *filter_stream;
309
310   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
311
312   g_output_stream_flush_async (filter_stream->base_stream,
313                                io_priority,
314                                cancellable,
315                                callback,
316                                data);
317 }
318
319 static gboolean
320 g_filter_output_stream_flush_finish (GOutputStream        *stream,
321                                      GAsyncResult         *result,
322                                      GError              **error)
323 {
324   GFilterOutputStream *filter_stream;
325   gboolean res;
326
327   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
328
329   res = g_output_stream_flush_finish (filter_stream->base_stream,
330                                       result,
331                                       error);
332
333   return res;
334 }
335
336 static void
337 g_filter_output_stream_close_async (GOutputStream        *stream,
338                                     int                   io_priority,
339                                     GCancellable         *cancellable,
340                                     GAsyncReadyCallback   callback,
341                                     gpointer              data)
342 {
343   GFilterOutputStream *filter_stream;
344
345   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
346
347   g_output_stream_close_async (filter_stream->base_stream,
348                                io_priority,
349                                cancellable,
350                                callback,
351                                data);
352 }
353
354 static gboolean
355 g_filter_output_stream_close_finish (GOutputStream        *stream,
356                                      GAsyncResult         *result,
357                                      GError              **error)
358 {
359   GFilterOutputStream *filter_stream;
360   gboolean res;
361
362   filter_stream = G_FILTER_OUTPUT_STREAM (stream);
363
364   res = g_output_stream_close_finish (filter_stream->base_stream,
365                                       result,
366                                       error);
367
368   return res;
369 }
370
371
372 /* vim: ts=2 sw=2 et */