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