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 30 G_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 **/ 48 typedef struct _GOutputStreamClass GOutputStreamClass; 49 typedef struct _GOutputStreamPrivate GOutputStreamPrivate; 50 51 struct _GOutputStream 52 { 53 GObject parent_instance; 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_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 gboolean (* writev_fn) (GOutputStream *stream, 123 const GOutputVector *vectors, 124 gsize n_vectors, 125 gsize *bytes_written, 126 GCancellable *cancellable, 127 GError **error); 128 129 void (* writev_async) (GOutputStream *stream, 130 const GOutputVector *vectors, 131 gsize n_vectors, 132 int io_priority, 133 GCancellable *cancellable, 134 GAsyncReadyCallback callback, 135 gpointer user_data); 136 137 gboolean (* writev_finish) (GOutputStream *stream, 138 GAsyncResult *result, 139 gsize *bytes_written, 140 GError **error); 141 142 /*< private >*/ 143 /* Padding for future expansion */ 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 GLIB_AVAILABLE_IN_ALL 152 GType g_output_stream_get_type (void) G_GNUC_CONST; 153 154 GLIB_AVAILABLE_IN_ALL 155 gssize g_output_stream_write (GOutputStream *stream, 156 const void *buffer, 157 gsize count, 158 GCancellable *cancellable, 159 GError **error); 160 GLIB_AVAILABLE_IN_ALL 161 gboolean g_output_stream_write_all (GOutputStream *stream, 162 const void *buffer, 163 gsize count, 164 gsize *bytes_written, 165 GCancellable *cancellable, 166 GError **error); 167 168 GLIB_AVAILABLE_IN_2_60 169 gboolean g_output_stream_writev (GOutputStream *stream, 170 const GOutputVector *vectors, 171 gsize n_vectors, 172 gsize *bytes_written, 173 GCancellable *cancellable, 174 GError **error); 175 GLIB_AVAILABLE_IN_2_60 176 gboolean g_output_stream_writev_all (GOutputStream *stream, 177 GOutputVector *vectors, 178 gsize n_vectors, 179 gsize *bytes_written, 180 GCancellable *cancellable, 181 GError **error); 182 183 GLIB_AVAILABLE_IN_2_40 184 gboolean g_output_stream_printf (GOutputStream *stream, 185 gsize *bytes_written, 186 GCancellable *cancellable, 187 GError **error, 188 const gchar *format, 189 ...) G_GNUC_PRINTF (5, 6); 190 GLIB_AVAILABLE_IN_2_40 191 gboolean g_output_stream_vprintf (GOutputStream *stream, 192 gsize *bytes_written, 193 GCancellable *cancellable, 194 GError **error, 195 const gchar *format, 196 va_list args) G_GNUC_PRINTF (5, 0); 197 GLIB_AVAILABLE_IN_2_34 198 gssize g_output_stream_write_bytes (GOutputStream *stream, 199 GBytes *bytes, 200 GCancellable *cancellable, 201 GError **error); 202 GLIB_AVAILABLE_IN_ALL 203 gssize g_output_stream_splice (GOutputStream *stream, 204 GInputStream *source, 205 GOutputStreamSpliceFlags flags, 206 GCancellable *cancellable, 207 GError **error); 208 GLIB_AVAILABLE_IN_ALL 209 gboolean g_output_stream_flush (GOutputStream *stream, 210 GCancellable *cancellable, 211 GError **error); 212 GLIB_AVAILABLE_IN_ALL 213 gboolean g_output_stream_close (GOutputStream *stream, 214 GCancellable *cancellable, 215 GError **error); 216 GLIB_AVAILABLE_IN_ALL 217 void g_output_stream_write_async (GOutputStream *stream, 218 const void *buffer, 219 gsize count, 220 int io_priority, 221 GCancellable *cancellable, 222 GAsyncReadyCallback callback, 223 gpointer user_data); 224 GLIB_AVAILABLE_IN_ALL 225 gssize g_output_stream_write_finish (GOutputStream *stream, 226 GAsyncResult *result, 227 GError **error); 228 229 GLIB_AVAILABLE_IN_2_44 230 void g_output_stream_write_all_async (GOutputStream *stream, 231 const void *buffer, 232 gsize count, 233 int io_priority, 234 GCancellable *cancellable, 235 GAsyncReadyCallback callback, 236 gpointer user_data); 237 238 GLIB_AVAILABLE_IN_2_44 239 gboolean g_output_stream_write_all_finish (GOutputStream *stream, 240 GAsyncResult *result, 241 gsize *bytes_written, 242 GError **error); 243 244 GLIB_AVAILABLE_IN_2_60 245 void g_output_stream_writev_async (GOutputStream *stream, 246 const GOutputVector *vectors, 247 gsize n_vectors, 248 int io_priority, 249 GCancellable *cancellable, 250 GAsyncReadyCallback callback, 251 gpointer user_data); 252 GLIB_AVAILABLE_IN_2_60 253 gboolean g_output_stream_writev_finish (GOutputStream *stream, 254 GAsyncResult *result, 255 gsize *bytes_written, 256 GError **error); 257 258 GLIB_AVAILABLE_IN_2_60 259 void g_output_stream_writev_all_async (GOutputStream *stream, 260 GOutputVector *vectors, 261 gsize n_vectors, 262 int io_priority, 263 GCancellable *cancellable, 264 GAsyncReadyCallback callback, 265 gpointer user_data); 266 267 GLIB_AVAILABLE_IN_2_60 268 gboolean g_output_stream_writev_all_finish (GOutputStream *stream, 269 GAsyncResult *result, 270 gsize *bytes_written, 271 GError **error); 272 273 GLIB_AVAILABLE_IN_2_34 274 void g_output_stream_write_bytes_async (GOutputStream *stream, 275 GBytes *bytes, 276 int io_priority, 277 GCancellable *cancellable, 278 GAsyncReadyCallback callback, 279 gpointer user_data); 280 GLIB_AVAILABLE_IN_2_34 281 gssize g_output_stream_write_bytes_finish (GOutputStream *stream, 282 GAsyncResult *result, 283 GError **error); 284 GLIB_AVAILABLE_IN_ALL 285 void g_output_stream_splice_async (GOutputStream *stream, 286 GInputStream *source, 287 GOutputStreamSpliceFlags flags, 288 int io_priority, 289 GCancellable *cancellable, 290 GAsyncReadyCallback callback, 291 gpointer user_data); 292 GLIB_AVAILABLE_IN_ALL 293 gssize g_output_stream_splice_finish (GOutputStream *stream, 294 GAsyncResult *result, 295 GError **error); 296 GLIB_AVAILABLE_IN_ALL 297 void g_output_stream_flush_async (GOutputStream *stream, 298 int io_priority, 299 GCancellable *cancellable, 300 GAsyncReadyCallback callback, 301 gpointer user_data); 302 GLIB_AVAILABLE_IN_ALL 303 gboolean g_output_stream_flush_finish (GOutputStream *stream, 304 GAsyncResult *result, 305 GError **error); 306 GLIB_AVAILABLE_IN_ALL 307 void g_output_stream_close_async (GOutputStream *stream, 308 int io_priority, 309 GCancellable *cancellable, 310 GAsyncReadyCallback callback, 311 gpointer user_data); 312 GLIB_AVAILABLE_IN_ALL 313 gboolean g_output_stream_close_finish (GOutputStream *stream, 314 GAsyncResult *result, 315 GError **error); 316 317 GLIB_AVAILABLE_IN_ALL 318 gboolean g_output_stream_is_closed (GOutputStream *stream); 319 GLIB_AVAILABLE_IN_ALL 320 gboolean g_output_stream_is_closing (GOutputStream *stream); 321 GLIB_AVAILABLE_IN_ALL 322 gboolean g_output_stream_has_pending (GOutputStream *stream); 323 GLIB_AVAILABLE_IN_ALL 324 gboolean g_output_stream_set_pending (GOutputStream *stream, 325 GError **error); 326 GLIB_AVAILABLE_IN_ALL 327 void g_output_stream_clear_pending (GOutputStream *stream); 328 329 330 G_END_DECLS 331 332 #endif /* __G_OUTPUT_STREAM_H__ */ 333