Bumps documentation to 93% symbol coverage, touching most
[platform/upstream/glib.git] / gio / goutputstream.h
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: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #ifndef __G_OUTPUT_STREAM_H__
24 #define __G_OUTPUT_STREAM_H__
25
26 #include <glib-object.h>
27 #include <gio/gioerror.h>
28 #include <gio/gasyncresult.h>
29 #include <gio/gcancellable.h>
30 #include <gio/ginputstream.h>
31
32 G_BEGIN_DECLS
33
34 #define G_TYPE_OUTPUT_STREAM         (g_output_stream_get_type ())
35 #define G_OUTPUT_STREAM(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_OUTPUT_STREAM, GOutputStream))
36 #define G_OUTPUT_STREAM_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_OUTPUT_STREAM, GOutputStreamClass))
37 #define G_IS_OUTPUT_STREAM(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_OUTPUT_STREAM))
38 #define G_IS_OUTPUT_STREAM_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_OUTPUT_STREAM))
39 #define G_OUTPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_OUTPUT_STREAM, GOutputStreamClass))
40
41 /**
42  * GOutputStreamSpliceFlags:
43  * @G_OUTPUT_STREAM_SPLICE_FLAGS_NONE:
44  * @G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_SOURCE:
45  * @G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_TARGET:
46  * 
47  * 
48  **/
49 typedef enum {
50   G_OUTPUT_STREAM_SPLICE_FLAGS_NONE = 0,
51   G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_SOURCE = 1 << 0,
52   G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_TARGET = 1 << 1
53 } GOutputStreamSpliceFlags;
54
55 /**
56  * GOutputStream:
57  * 
58  * Base class for writing output. 
59  * 
60  * All classes derived from GOutputStream should implement synchronous 
61  * writing, splicing, flushing and closing streams, but may implement
62  * asynchronous versions.
63  **/
64 typedef struct _GOutputStream         GOutputStream;
65 typedef struct _GOutputStreamClass    GOutputStreamClass;
66 typedef struct _GOutputStreamPrivate  GOutputStreamPrivate;
67
68 struct _GOutputStream
69 {
70   GObject parent;
71   
72   /*< private >*/
73   GOutputStreamPrivate *priv;
74 };
75
76
77 struct _GOutputStreamClass
78 {
79   GObjectClass parent_class;
80
81   /* Sync ops: */
82   
83   gssize      (* write)  (GOutputStream *stream,
84                           const void *buffer,
85                           gsize count,
86                           GCancellable *cancellable,
87                           GError **error);
88   gssize      (* splice) (GOutputStream *stream,
89                           GInputStream  *source,
90                           GOutputStreamSpliceFlags   flags,
91                           GCancellable  *cancellable,
92                           GError       **error);
93   gboolean    (* flush)  (GOutputStream *stream,
94                           GCancellable  *cancellable,
95                           GError       **error);
96   gboolean    (* close)  (GOutputStream *stream,
97                           GCancellable  *cancellable,
98                           GError       **error);
99   
100   /* Async ops: (optional in derived classes) */
101
102   void     (* write_async)  (GOutputStream       *stream,
103                              const void          *buffer,
104                              gsize                count,
105                              int                  io_priority,
106                              GCancellable        *cancellable,
107                              GAsyncReadyCallback  callback,
108                              gpointer             user_data);
109   gssize   (* write_finish) (GOutputStream       *stream,
110                              GAsyncResult        *result,
111                              GError             **error);
112   void     (* splice_async) (GOutputStream       *stream,
113                              GInputStream        *source,
114                              GOutputStreamSpliceFlags flags,
115                              int                  io_priority,
116                              GCancellable        *cancellable,
117                              GAsyncReadyCallback  callback,
118                              gpointer             data);
119   gssize   (* splice_finish)(GOutputStream       *stream,
120                              GAsyncResult        *result,
121                              GError             **error);
122   void     (* flush_async)  (GOutputStream       *stream,
123                              int                  io_priority,
124                              GCancellable        *cancellable,
125                              GAsyncReadyCallback  callback,
126                              gpointer             user_data);
127   gboolean (* flush_finish) (GOutputStream       *stream,
128                              GAsyncResult        *result,
129                              GError             **error);
130   void     (* close_async)  (GOutputStream       *stream,
131                              int                  io_priority,
132                              GCancellable        *cancellable,
133                              GAsyncReadyCallback  callback,
134                              gpointer             user_data);
135   gboolean (* close_finish) (GOutputStream       *stream,
136                              GAsyncResult        *result,
137                              GError             **error);
138
139   /*< private >*/
140   /* Padding for future expansion */
141   void (*_g_reserved1) (void);
142   void (*_g_reserved2) (void);
143   void (*_g_reserved3) (void);
144   void (*_g_reserved4) (void);
145   void (*_g_reserved5) (void);
146   void (*_g_reserved6) (void);
147   void (*_g_reserved7) (void);
148   void (*_g_reserved8) (void);
149 };
150
151 GType g_output_stream_get_type (void) G_GNUC_CONST;
152   
153 gssize   g_output_stream_write         (GOutputStream             *stream,
154                                         const void                *buffer,
155                                         gsize                      count,
156                                         GCancellable              *cancellable,
157                                         GError                   **error);
158 gboolean g_output_stream_write_all     (GOutputStream             *stream,
159                                         const void                *buffer,
160                                         gsize                      count,
161                                         gsize                     *bytes_written,
162                                         GCancellable              *cancellable,
163                                         GError                   **error);
164 gssize   g_output_stream_splice        (GOutputStream             *stream,
165                                         GInputStream              *source,
166                                         GOutputStreamSpliceFlags   flags,
167                                         GCancellable              *cancellable,
168                                         GError                   **error);
169 gboolean g_output_stream_flush         (GOutputStream             *stream,
170                                         GCancellable              *cancellable,
171                                         GError                   **error);
172 gboolean g_output_stream_close         (GOutputStream             *stream,
173                                         GCancellable              *cancellable,
174                                         GError                   **error);
175 void     g_output_stream_write_async   (GOutputStream             *stream,
176                                         const void                *buffer,
177                                         gsize                      count,
178                                         int                        io_priority,
179                                         GCancellable              *cancellable,
180                                         GAsyncReadyCallback        callback,
181                                         gpointer                   user_data);
182 gssize   g_output_stream_write_finish  (GOutputStream             *stream,
183                                         GAsyncResult              *result,
184                                         GError                   **error);
185 void     g_output_stream_splice_async  (GOutputStream             *stream,
186                                         GInputStream              *source,
187                                         GOutputStreamSpliceFlags   flags,
188                                         int                        io_priority,
189                                         GCancellable              *cancellable,
190                                         GAsyncReadyCallback        callback,
191                                         gpointer                   user_data);
192 gssize   g_output_stream_splice_finish (GOutputStream             *stream,
193                                         GAsyncResult              *result,
194                                         GError                   **error);
195 void     g_output_stream_flush_async   (GOutputStream             *stream,
196                                         int                        io_priority,
197                                         GCancellable              *cancellable,
198                                         GAsyncReadyCallback        callback,
199                                         gpointer                   user_data);
200 gboolean g_output_stream_flush_finish  (GOutputStream             *stream,
201                                         GAsyncResult              *result,
202                                         GError                   **error);
203 void     g_output_stream_close_async   (GOutputStream             *stream,
204                                         int                        io_priority,
205                                         GCancellable              *cancellable,
206                                         GAsyncReadyCallback        callback,
207                                         gpointer                   user_data);
208 gboolean g_output_stream_close_finish  (GOutputStream             *stream,
209                                         GAsyncResult              *result,
210                                         GError                   **error);
211
212 gboolean g_output_stream_is_closed     (GOutputStream             *stream);
213 gboolean g_output_stream_has_pending   (GOutputStream             *stream);
214 void     g_output_stream_set_pending   (GOutputStream             *stream,
215                                         gboolean                   pending);
216
217
218 G_END_DECLS
219
220 #endif /* __G_OUTPUT_STREAM_H__ */