gio/ docs/reference/gio Merged gio-standalone into glib.
[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 typedef enum {
42   G_OUTPUT_STREAM_SPLICE_FLAGS_NONE = 0,
43   G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_SOURCE = 1 << 0,
44   G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_TARGET = 1 << 1
45 } GOutputStreamSpliceFlags;
46
47 typedef struct _GOutputStream         GOutputStream;
48 typedef struct _GOutputStreamClass    GOutputStreamClass;
49 typedef struct _GOutputStreamPrivate  GOutputStreamPrivate;
50
51 struct _GOutputStream
52 {
53   GObject parent;
54   
55   /*< private >*/
56   GOutputStreamPrivate *priv;
57 };
58
59
60 struct _GOutputStreamClass
61 {
62   GObjectClass parent_class;
63
64   /* Sync ops: */
65   
66   gssize      (* write)  (GOutputStream *stream,
67                           const void *buffer,
68                           gsize count,
69                           GCancellable *cancellable,
70                           GError **error);
71   gssize      (* splice) (GOutputStream *stream,
72                           GInputStream  *source,
73                           GOutputStreamSpliceFlags   flags,
74                           GCancellable  *cancellable,
75                           GError       **error);
76   gboolean    (* flush)  (GOutputStream *stream,
77                           GCancellable  *cancellable,
78                           GError       **error);
79   gboolean    (* close)  (GOutputStream *stream,
80                           GCancellable  *cancellable,
81                           GError       **error);
82   
83   /* Async ops: (optional in derived classes) */
84
85   void     (* write_async)  (GOutputStream       *stream,
86                              const void          *buffer,
87                              gsize                count,
88                              int                  io_priority,
89                              GCancellable        *cancellable,
90                              GAsyncReadyCallback  callback,
91                              gpointer             user_data);
92   gssize   (* write_finish) (GOutputStream       *stream,
93                              GAsyncResult        *result,
94                              GError             **error);
95   void     (* splice_async) (GOutputStream       *stream,
96                              GInputStream        *source,
97                              GOutputStreamSpliceFlags flags,
98                              int                  io_priority,
99                              GCancellable        *cancellable,
100                              GAsyncReadyCallback  callback,
101                              gpointer             data);
102   gssize   (* splice_finish)(GOutputStream       *stream,
103                              GAsyncResult        *result,
104                              GError             **error);
105   void     (* flush_async)  (GOutputStream       *stream,
106                              int                  io_priority,
107                              GCancellable        *cancellable,
108                              GAsyncReadyCallback  callback,
109                              gpointer             user_data);
110   gboolean (* flush_finish) (GOutputStream       *stream,
111                              GAsyncResult        *result,
112                              GError             **error);
113   void     (* close_async)  (GOutputStream       *stream,
114                              int                  io_priority,
115                              GCancellable        *cancellable,
116                              GAsyncReadyCallback  callback,
117                              gpointer             user_data);
118   gboolean (* close_finish) (GOutputStream       *stream,
119                              GAsyncResult        *result,
120                              GError             **error);
121
122   /* Padding for future expansion */
123   void (*_g_reserved1) (void);
124   void (*_g_reserved2) (void);
125   void (*_g_reserved3) (void);
126   void (*_g_reserved4) (void);
127   void (*_g_reserved5) (void);
128   void (*_g_reserved6) (void);
129   void (*_g_reserved7) (void);
130   void (*_g_reserved8) (void);
131 };
132
133 GType g_output_stream_get_type (void) G_GNUC_CONST;
134   
135 gssize   g_output_stream_write         (GOutputStream             *stream,
136                                         const void                *buffer,
137                                         gsize                      count,
138                                         GCancellable              *cancellable,
139                                         GError                   **error);
140 gboolean g_output_stream_write_all     (GOutputStream             *stream,
141                                         const void                *buffer,
142                                         gsize                      count,
143                                         gsize                     *bytes_written,
144                                         GCancellable              *cancellable,
145                                         GError                   **error);
146 gssize   g_output_stream_splice        (GOutputStream             *stream,
147                                         GInputStream              *source,
148                                         GOutputStreamSpliceFlags   flags,
149                                         GCancellable              *cancellable,
150                                         GError                   **error);
151 gboolean g_output_stream_flush         (GOutputStream             *stream,
152                                         GCancellable              *cancellable,
153                                         GError                   **error);
154 gboolean g_output_stream_close         (GOutputStream             *stream,
155                                         GCancellable              *cancellable,
156                                         GError                   **error);
157 void     g_output_stream_write_async   (GOutputStream             *stream,
158                                         const void                *buffer,
159                                         gsize                      count,
160                                         int                        io_priority,
161                                         GCancellable              *cancellable,
162                                         GAsyncReadyCallback        callback,
163                                         gpointer                   user_data);
164 gssize   g_output_stream_write_finish  (GOutputStream             *stream,
165                                         GAsyncResult              *result,
166                                         GError                   **error);
167 void     g_output_stream_splice_async  (GOutputStream             *stream,
168                                         GInputStream              *source,
169                                         GOutputStreamSpliceFlags   flags,
170                                         int                        io_priority,
171                                         GCancellable              *cancellable,
172                                         GAsyncReadyCallback        callback,
173                                         gpointer                   user_data);
174 gssize   g_output_stream_splice_finish (GOutputStream             *stream,
175                                         GAsyncResult              *result,
176                                         GError                   **error);
177 void     g_output_stream_flush_async   (GOutputStream             *stream,
178                                         int                        io_priority,
179                                         GCancellable              *cancellable,
180                                         GAsyncReadyCallback        callback,
181                                         gpointer                   user_data);
182 gboolean g_output_stream_flush_finish  (GOutputStream             *stream,
183                                         GAsyncResult              *result,
184                                         GError                   **error);
185 void     g_output_stream_close_async   (GOutputStream             *stream,
186                                         int                        io_priority,
187                                         GCancellable              *cancellable,
188                                         GAsyncReadyCallback        callback,
189                                         gpointer                   user_data);
190 gboolean g_output_stream_close_finish  (GOutputStream             *stream,
191                                         GAsyncResult              *result,
192                                         GError                   **error);
193
194 gboolean g_output_stream_is_closed     (GOutputStream             *stream);
195 gboolean g_output_stream_has_pending   (GOutputStream             *stream);
196 void     g_output_stream_set_pending   (GOutputStream             *stream,
197                                         gboolean                   pending);
198
199
200 G_END_DECLS
201
202 #endif /* __G_OUTPUT_STREAM_H__ */