1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
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.
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.
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.
20 * Author: Alexander Larsson <alexl@redhat.com>
23 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
24 #error "Only <gio/gio.h> can be included directly."
27 #ifndef __G_OUTPUT_STREAM_H__
28 #define __G_OUTPUT_STREAM_H__
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>
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))
46 * GOutputStreamSpliceFlags:
47 * @G_OUTPUT_STREAM_SPLICE_FLAGS_NONE: Do not close either stream.
48 * @G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_SOURCE: Close the source stream after the splice.
49 * @G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_TARGET: Close the target stream after the splice.
51 * GOutputStreamSpliceFlags determine how streams should be spliced.
54 G_OUTPUT_STREAM_SPLICE_FLAGS_NONE = 0,
55 G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_SOURCE = 1 << 0,
56 G_OUTPUT_STREAM_SPLICE_FLAGS_CLOSE_TARGET = 1 << 1
57 } GOutputStreamSpliceFlags;
62 * Base class for writing output.
64 * All classes derived from GOutputStream should implement synchronous
65 * writing, splicing, flushing and closing streams, but may implement
66 * asynchronous versions.
68 typedef struct _GOutputStream GOutputStream;
69 typedef struct _GOutputStreamClass GOutputStreamClass;
70 typedef struct _GOutputStreamPrivate GOutputStreamPrivate;
74 GObject parent_instance;
77 GOutputStreamPrivate *priv;
81 struct _GOutputStreamClass
83 GObjectClass parent_class;
87 gssize (* write_fn)(GOutputStream *stream,
90 GCancellable *cancellable,
92 gssize (* splice) (GOutputStream *stream,
94 GOutputStreamSpliceFlags flags,
95 GCancellable *cancellable,
97 gboolean (* flush) (GOutputStream *stream,
98 GCancellable *cancellable,
100 gboolean (* close_fn)(GOutputStream *stream,
101 GCancellable *cancellable,
104 /* Async ops: (optional in derived classes) */
106 void (* write_async) (GOutputStream *stream,
110 GCancellable *cancellable,
111 GAsyncReadyCallback callback,
113 gssize (* write_finish) (GOutputStream *stream,
114 GAsyncResult *result,
116 void (* splice_async) (GOutputStream *stream,
117 GInputStream *source,
118 GOutputStreamSpliceFlags flags,
120 GCancellable *cancellable,
121 GAsyncReadyCallback callback,
123 gssize (* splice_finish)(GOutputStream *stream,
124 GAsyncResult *result,
126 void (* flush_async) (GOutputStream *stream,
128 GCancellable *cancellable,
129 GAsyncReadyCallback callback,
131 gboolean (* flush_finish) (GOutputStream *stream,
132 GAsyncResult *result,
134 void (* close_async) (GOutputStream *stream,
136 GCancellable *cancellable,
137 GAsyncReadyCallback callback,
139 gboolean (* close_finish) (GOutputStream *stream,
140 GAsyncResult *result,
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);
155 GType g_output_stream_get_type (void) G_GNUC_CONST;
157 gssize g_output_stream_write (GOutputStream *stream,
160 GCancellable *cancellable,
162 gboolean g_output_stream_write_all (GOutputStream *stream,
165 gsize *bytes_written,
166 GCancellable *cancellable,
168 gssize g_output_stream_splice (GOutputStream *stream,
169 GInputStream *source,
170 GOutputStreamSpliceFlags flags,
171 GCancellable *cancellable,
173 gboolean g_output_stream_flush (GOutputStream *stream,
174 GCancellable *cancellable,
176 gboolean g_output_stream_close (GOutputStream *stream,
177 GCancellable *cancellable,
179 void g_output_stream_write_async (GOutputStream *stream,
183 GCancellable *cancellable,
184 GAsyncReadyCallback callback,
186 gssize g_output_stream_write_finish (GOutputStream *stream,
187 GAsyncResult *result,
189 void g_output_stream_splice_async (GOutputStream *stream,
190 GInputStream *source,
191 GOutputStreamSpliceFlags flags,
193 GCancellable *cancellable,
194 GAsyncReadyCallback callback,
196 gssize g_output_stream_splice_finish (GOutputStream *stream,
197 GAsyncResult *result,
199 void g_output_stream_flush_async (GOutputStream *stream,
201 GCancellable *cancellable,
202 GAsyncReadyCallback callback,
204 gboolean g_output_stream_flush_finish (GOutputStream *stream,
205 GAsyncResult *result,
207 void g_output_stream_close_async (GOutputStream *stream,
209 GCancellable *cancellable,
210 GAsyncReadyCallback callback,
212 gboolean g_output_stream_close_finish (GOutputStream *stream,
213 GAsyncResult *result,
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,
220 void g_output_stream_clear_pending (GOutputStream *stream);
225 #endif /* __G_OUTPUT_STREAM_H__ */