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.1 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, see <http://www.gnu.org/licenses/>.
17 *
18 * Author: Alexander Larsson <alexl@redhat.com>
19 */
20
21#ifndef __G_OUTPUT_STREAM_H__
22#define __G_OUTPUT_STREAM_H__
23
24#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
25#error "Only <gio/gio.h> can be included directly."
26#endif
27
28#include <gio/giotypes.h>
29
30G_BEGIN_DECLS
31
32#define G_TYPE_OUTPUT_STREAM (g_output_stream_get_type ())
33#define G_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_OUTPUT_STREAM, GOutputStream))
34#define G_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_OUTPUT_STREAM, GOutputStreamClass))
35#define G_IS_OUTPUT_STREAM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_OUTPUT_STREAM))
36#define G_IS_OUTPUT_STREAM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_OUTPUT_STREAM))
37#define G_OUTPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_OUTPUT_STREAM, GOutputStreamClass))
38
39/**
40 * GOutputStream:
41 *
42 * Base class for writing output.
43 *
44 * All classes derived from GOutputStream should implement synchronous
45 * writing, splicing, flushing and closing streams, but may implement
46 * asynchronous versions.
47 **/
48typedef struct _GOutputStreamClass GOutputStreamClass;
49typedef struct _GOutputStreamPrivate GOutputStreamPrivate;
50
51struct _GOutputStream
52{
53 GObject parent_instance;
54
55 /*< private >*/
56 GOutputStreamPrivate *priv;
57};
58
59
60struct _GOutputStreamClass
61{
62 GObjectClass parent_class;
63
64 /* Sync ops: */
65
66 gssize (* write_fn) (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_fn) (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 user_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 /*< private >*/
123 /* Padding for future expansion */
124 void (*_g_reserved1) (void);
125 void (*_g_reserved2) (void);
126 void (*_g_reserved3) (void);
127 void (*_g_reserved4) (void);
128 void (*_g_reserved5) (void);
129 void (*_g_reserved6) (void);
130 void (*_g_reserved7) (void);
131 void (*_g_reserved8) (void);
132};
133
134GLIB_AVAILABLE_IN_ALL
135GType g_output_stream_get_type (void) G_GNUC_CONST;
136
137GLIB_AVAILABLE_IN_ALL
138gssize g_output_stream_write (GOutputStream *stream,
139 const void *buffer,
140 gsize count,
141 GCancellable *cancellable,
142 GError **error);
143GLIB_AVAILABLE_IN_ALL
144gboolean g_output_stream_write_all (GOutputStream *stream,
145 const void *buffer,
146 gsize count,
147 gsize *bytes_written,
148 GCancellable *cancellable,
149 GError **error);
150GLIB_AVAILABLE_IN_2_40
151gboolean g_output_stream_printf (GOutputStream *stream,
152 gsize *bytes_written,
153 GCancellable *cancellable,
154 GError **error,
155 const gchar *format,
156 ...) G_GNUC_PRINTF (5, 6);
157GLIB_AVAILABLE_IN_2_40
158gboolean g_output_stream_vprintf (GOutputStream *stream,
159 gsize *bytes_written,
160 GCancellable *cancellable,
161 GError **error,
162 const gchar *format,
163 va_list args) G_GNUC_PRINTF (5, 0);
164GLIB_AVAILABLE_IN_2_34
165gssize g_output_stream_write_bytes (GOutputStream *stream,
166 GBytes *bytes,
167 GCancellable *cancellable,
168 GError **error);
169GLIB_AVAILABLE_IN_ALL
170gssize g_output_stream_splice (GOutputStream *stream,
171 GInputStream *source,
172 GOutputStreamSpliceFlags flags,
173 GCancellable *cancellable,
174 GError **error);
175GLIB_AVAILABLE_IN_ALL
176gboolean g_output_stream_flush (GOutputStream *stream,
177 GCancellable *cancellable,
178 GError **error);
179GLIB_AVAILABLE_IN_ALL
180gboolean g_output_stream_close (GOutputStream *stream,
181 GCancellable *cancellable,
182 GError **error);
183GLIB_AVAILABLE_IN_ALL
184void g_output_stream_write_async (GOutputStream *stream,
185 const void *buffer,
186 gsize count,
187 int io_priority,
188 GCancellable *cancellable,
189 GAsyncReadyCallback callback,
190 gpointer user_data);
191GLIB_AVAILABLE_IN_ALL
192gssize g_output_stream_write_finish (GOutputStream *stream,
193 GAsyncResult *result,
194 GError **error);
195
196GLIB_AVAILABLE_IN_2_44
197void g_output_stream_write_all_async (GOutputStream *stream,
198 const void *buffer,
199 gsize count,
200 int io_priority,
201 GCancellable *cancellable,
202 GAsyncReadyCallback callback,
203 gpointer user_data);
204
205GLIB_AVAILABLE_IN_2_44
206gboolean g_output_stream_write_all_finish (GOutputStream *stream,
207 GAsyncResult *result,
208 gsize *bytes_written,
209 GError **error);
210
211GLIB_AVAILABLE_IN_2_34
212void g_output_stream_write_bytes_async (GOutputStream *stream,
213 GBytes *bytes,
214 int io_priority,
215 GCancellable *cancellable,
216 GAsyncReadyCallback callback,
217 gpointer user_data);
218GLIB_AVAILABLE_IN_2_34
219gssize g_output_stream_write_bytes_finish (GOutputStream *stream,
220 GAsyncResult *result,
221 GError **error);
222GLIB_AVAILABLE_IN_ALL
223void g_output_stream_splice_async (GOutputStream *stream,
224 GInputStream *source,
225 GOutputStreamSpliceFlags flags,
226 int io_priority,
227 GCancellable *cancellable,
228 GAsyncReadyCallback callback,
229 gpointer user_data);
230GLIB_AVAILABLE_IN_ALL
231gssize g_output_stream_splice_finish (GOutputStream *stream,
232 GAsyncResult *result,
233 GError **error);
234GLIB_AVAILABLE_IN_ALL
235void g_output_stream_flush_async (GOutputStream *stream,
236 int io_priority,
237 GCancellable *cancellable,
238 GAsyncReadyCallback callback,
239 gpointer user_data);
240GLIB_AVAILABLE_IN_ALL
241gboolean g_output_stream_flush_finish (GOutputStream *stream,
242 GAsyncResult *result,
243 GError **error);
244GLIB_AVAILABLE_IN_ALL
245void g_output_stream_close_async (GOutputStream *stream,
246 int io_priority,
247 GCancellable *cancellable,
248 GAsyncReadyCallback callback,
249 gpointer user_data);
250GLIB_AVAILABLE_IN_ALL
251gboolean g_output_stream_close_finish (GOutputStream *stream,
252 GAsyncResult *result,
253 GError **error);
254
255GLIB_AVAILABLE_IN_ALL
256gboolean g_output_stream_is_closed (GOutputStream *stream);
257GLIB_AVAILABLE_IN_ALL
258gboolean g_output_stream_is_closing (GOutputStream *stream);
259GLIB_AVAILABLE_IN_ALL
260gboolean g_output_stream_has_pending (GOutputStream *stream);
261GLIB_AVAILABLE_IN_ALL
262gboolean g_output_stream_set_pending (GOutputStream *stream,
263 GError **error);
264GLIB_AVAILABLE_IN_ALL
265void g_output_stream_clear_pending (GOutputStream *stream);
266
267
268G_END_DECLS
269
270#endif /* __G_OUTPUT_STREAM_H__ */
271