gkdbus: Fix underflow and unreachable code bug
[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  * SPDX-License-Identifier: LGPL-2.1-or-later
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General
18  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #ifndef __G_OUTPUT_STREAM_H__
24 #define __G_OUTPUT_STREAM_H__
25
26 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
27 #error "Only <gio/gio.h> can be included directly."
28 #endif
29
30 #include <gio/giotypes.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 /**
42  * GOutputStream:
43  *
44  * Base class for writing output.
45  *
46  * All classes derived from GOutputStream should implement synchronous
47  * writing, splicing, flushing and closing streams, but may implement
48  * asynchronous versions.
49  **/
50 typedef struct _GOutputStreamClass    GOutputStreamClass;
51 typedef struct _GOutputStreamPrivate  GOutputStreamPrivate;
52
53 struct _GOutputStream
54 {
55   GObject parent_instance;
56
57   /*< private >*/
58   GOutputStreamPrivate *priv;
59 };
60
61
62 struct _GOutputStreamClass
63 {
64   GObjectClass parent_class;
65
66   /* Sync ops: */
67
68   gssize      (* write_fn)      (GOutputStream            *stream,
69                                  const void               *buffer,
70                                  gsize                     count,
71                                  GCancellable             *cancellable,
72                                  GError                  **error);
73   gssize      (* splice)        (GOutputStream            *stream,
74                                  GInputStream             *source,
75                                  GOutputStreamSpliceFlags  flags,
76                                  GCancellable             *cancellable,
77                                  GError                  **error);
78   gboolean    (* flush)         (GOutputStream            *stream,
79                                  GCancellable             *cancellable,
80                                  GError                  **error);
81   gboolean    (* close_fn)      (GOutputStream            *stream,
82                                  GCancellable             *cancellable,
83                                  GError                  **error);
84
85   /* Async ops: (optional in derived classes) */
86
87   void        (* write_async)   (GOutputStream            *stream,
88                                  const void               *buffer,
89                                  gsize                     count,
90                                  int                       io_priority,
91                                  GCancellable             *cancellable,
92                                  GAsyncReadyCallback       callback,
93                                  gpointer                  user_data);
94   gssize      (* write_finish)  (GOutputStream            *stream,
95                                  GAsyncResult             *result,
96                                  GError                  **error);
97   void        (* splice_async)  (GOutputStream            *stream,
98                                  GInputStream             *source,
99                                  GOutputStreamSpliceFlags  flags,
100                                  int                       io_priority,
101                                  GCancellable             *cancellable,
102                                  GAsyncReadyCallback       callback,
103                                  gpointer                  user_data);
104   gssize      (* splice_finish) (GOutputStream            *stream,
105                                  GAsyncResult             *result,
106                                  GError                  **error);
107   void        (* flush_async)   (GOutputStream            *stream,
108                                  int                       io_priority,
109                                  GCancellable             *cancellable,
110                                  GAsyncReadyCallback       callback,
111                                  gpointer                  user_data);
112   gboolean    (* flush_finish)  (GOutputStream            *stream,
113                                  GAsyncResult             *result,
114                                  GError                  **error);
115   void        (* close_async)   (GOutputStream            *stream,
116                                  int                       io_priority,
117                                  GCancellable             *cancellable,
118                                  GAsyncReadyCallback       callback,
119                                  gpointer                  user_data);
120   gboolean    (* close_finish)  (GOutputStream            *stream,
121                                  GAsyncResult             *result,
122                                  GError                  **error);
123
124   gboolean    (* writev_fn)     (GOutputStream            *stream,
125                                  const GOutputVector      *vectors,
126                                  gsize                     n_vectors,
127                                  gsize                    *bytes_written,
128                                  GCancellable             *cancellable,
129                                  GError                  **error);
130
131   void        (* writev_async)  (GOutputStream            *stream,
132                                  const GOutputVector      *vectors,
133                                  gsize                     n_vectors,
134                                  int                       io_priority,
135                                  GCancellable             *cancellable,
136                                  GAsyncReadyCallback       callback,
137                                  gpointer                  user_data);
138
139   gboolean    (* writev_finish) (GOutputStream            *stream,
140                                  GAsyncResult             *result,
141                                  gsize                    *bytes_written,
142                                  GError                  **error);
143
144   /*< private >*/
145   /* Padding for future expansion */
146   void (*_g_reserved4) (void);
147   void (*_g_reserved5) (void);
148   void (*_g_reserved6) (void);
149   void (*_g_reserved7) (void);
150   void (*_g_reserved8) (void);
151 };
152
153 GIO_AVAILABLE_IN_ALL
154 GType    g_output_stream_get_type      (void) G_GNUC_CONST;
155
156 GIO_AVAILABLE_IN_ALL
157 gssize   g_output_stream_write         (GOutputStream             *stream,
158                                         const void                *buffer,
159                                         gsize                      count,
160                                         GCancellable              *cancellable,
161                                         GError                   **error);
162 GIO_AVAILABLE_IN_ALL
163 gboolean g_output_stream_write_all     (GOutputStream             *stream,
164                                         const void                *buffer,
165                                         gsize                      count,
166                                         gsize                     *bytes_written,
167                                         GCancellable              *cancellable,
168                                         GError                   **error);
169
170 GIO_AVAILABLE_IN_2_60
171 gboolean g_output_stream_writev        (GOutputStream             *stream,
172                                         const GOutputVector       *vectors,
173                                         gsize                      n_vectors,
174                                         gsize                     *bytes_written,
175                                         GCancellable              *cancellable,
176                                         GError                   **error);
177 GIO_AVAILABLE_IN_2_60
178 gboolean g_output_stream_writev_all    (GOutputStream             *stream,
179                                         GOutputVector             *vectors,
180                                         gsize                      n_vectors,
181                                         gsize                     *bytes_written,
182                                         GCancellable              *cancellable,
183                                         GError                   **error);
184
185 GIO_AVAILABLE_IN_2_40
186 gboolean g_output_stream_printf        (GOutputStream             *stream,
187                                         gsize                     *bytes_written,
188                                         GCancellable              *cancellable,
189                                         GError                   **error,
190                                         const gchar               *format,
191                                         ...) G_GNUC_PRINTF (5, 6);
192 GIO_AVAILABLE_IN_2_40
193 gboolean g_output_stream_vprintf       (GOutputStream             *stream,
194                                         gsize                     *bytes_written,
195                                         GCancellable              *cancellable,
196                                         GError                   **error,
197                                         const gchar               *format,
198                                         va_list                    args) G_GNUC_PRINTF (5, 0);
199 GIO_AVAILABLE_IN_2_34
200 gssize   g_output_stream_write_bytes   (GOutputStream             *stream,
201                                         GBytes                    *bytes,
202                                         GCancellable              *cancellable,
203                                         GError                   **error);
204 GIO_AVAILABLE_IN_ALL
205 gssize   g_output_stream_splice        (GOutputStream             *stream,
206                                         GInputStream              *source,
207                                         GOutputStreamSpliceFlags   flags,
208                                         GCancellable              *cancellable,
209                                         GError                   **error);
210 GIO_AVAILABLE_IN_ALL
211 gboolean g_output_stream_flush         (GOutputStream             *stream,
212                                         GCancellable              *cancellable,
213                                         GError                   **error);
214 GIO_AVAILABLE_IN_ALL
215 gboolean g_output_stream_close         (GOutputStream             *stream,
216                                         GCancellable              *cancellable,
217                                         GError                   **error);
218 GIO_AVAILABLE_IN_ALL
219 void     g_output_stream_write_async   (GOutputStream             *stream,
220                                         const void                *buffer,
221                                         gsize                      count,
222                                         int                        io_priority,
223                                         GCancellable              *cancellable,
224                                         GAsyncReadyCallback        callback,
225                                         gpointer                   user_data);
226 GIO_AVAILABLE_IN_ALL
227 gssize   g_output_stream_write_finish  (GOutputStream             *stream,
228                                         GAsyncResult              *result,
229                                         GError                   **error);
230
231 GIO_AVAILABLE_IN_2_44
232 void     g_output_stream_write_all_async (GOutputStream           *stream,
233                                           const void              *buffer,
234                                           gsize                    count,
235                                           int                      io_priority,
236                                           GCancellable            *cancellable,
237                                           GAsyncReadyCallback      callback,
238                                           gpointer                 user_data);
239
240 GIO_AVAILABLE_IN_2_44
241 gboolean g_output_stream_write_all_finish (GOutputStream          *stream,
242                                            GAsyncResult           *result,
243                                            gsize                  *bytes_written,
244                                            GError                **error);
245
246 GIO_AVAILABLE_IN_2_60
247 void     g_output_stream_writev_async  (GOutputStream             *stream,
248                                         const GOutputVector       *vectors,
249                                         gsize                      n_vectors,
250                                         int                        io_priority,
251                                         GCancellable              *cancellable,
252                                         GAsyncReadyCallback        callback,
253                                         gpointer                   user_data);
254 GIO_AVAILABLE_IN_2_60
255 gboolean g_output_stream_writev_finish (GOutputStream             *stream,
256                                         GAsyncResult              *result,
257                                         gsize                     *bytes_written,
258                                         GError                   **error);
259
260 GIO_AVAILABLE_IN_2_60
261 void     g_output_stream_writev_all_async (GOutputStream           *stream,
262                                            GOutputVector           *vectors,
263                                            gsize                    n_vectors,
264                                            int                      io_priority,
265                                            GCancellable            *cancellable,
266                                            GAsyncReadyCallback      callback,
267                                            gpointer                 user_data);
268
269 GIO_AVAILABLE_IN_2_60
270 gboolean g_output_stream_writev_all_finish (GOutputStream          *stream,
271                                             GAsyncResult           *result,
272                                             gsize                  *bytes_written,
273                                             GError                **error);
274
275 GIO_AVAILABLE_IN_2_34
276 void     g_output_stream_write_bytes_async  (GOutputStream             *stream,
277                                              GBytes                    *bytes,
278                                              int                        io_priority,
279                                              GCancellable              *cancellable,
280                                              GAsyncReadyCallback        callback,
281                                              gpointer                   user_data);
282 GIO_AVAILABLE_IN_2_34
283 gssize   g_output_stream_write_bytes_finish (GOutputStream             *stream,
284                                              GAsyncResult              *result,
285                                              GError                   **error);
286 GIO_AVAILABLE_IN_ALL
287 void     g_output_stream_splice_async  (GOutputStream             *stream,
288                                         GInputStream              *source,
289                                         GOutputStreamSpliceFlags   flags,
290                                         int                        io_priority,
291                                         GCancellable              *cancellable,
292                                         GAsyncReadyCallback        callback,
293                                         gpointer                   user_data);
294 GIO_AVAILABLE_IN_ALL
295 gssize   g_output_stream_splice_finish (GOutputStream             *stream,
296                                         GAsyncResult              *result,
297                                         GError                   **error);
298 GIO_AVAILABLE_IN_ALL
299 void     g_output_stream_flush_async   (GOutputStream             *stream,
300                                         int                        io_priority,
301                                         GCancellable              *cancellable,
302                                         GAsyncReadyCallback        callback,
303                                         gpointer                   user_data);
304 GIO_AVAILABLE_IN_ALL
305 gboolean g_output_stream_flush_finish  (GOutputStream             *stream,
306                                         GAsyncResult              *result,
307                                         GError                   **error);
308 GIO_AVAILABLE_IN_ALL
309 void     g_output_stream_close_async   (GOutputStream             *stream,
310                                         int                        io_priority,
311                                         GCancellable              *cancellable,
312                                         GAsyncReadyCallback        callback,
313                                         gpointer                   user_data);
314 GIO_AVAILABLE_IN_ALL
315 gboolean g_output_stream_close_finish  (GOutputStream             *stream,
316                                         GAsyncResult              *result,
317                                         GError                   **error);
318
319 GIO_AVAILABLE_IN_ALL
320 gboolean g_output_stream_is_closed     (GOutputStream             *stream);
321 GIO_AVAILABLE_IN_ALL
322 gboolean g_output_stream_is_closing    (GOutputStream             *stream);
323 GIO_AVAILABLE_IN_ALL
324 gboolean g_output_stream_has_pending   (GOutputStream             *stream);
325 GIO_AVAILABLE_IN_ALL
326 gboolean g_output_stream_set_pending   (GOutputStream             *stream,
327                                         GError                   **error);
328 GIO_AVAILABLE_IN_ALL
329 void     g_output_stream_clear_pending (GOutputStream             *stream);
330
331
332 G_END_DECLS
333
334 #endif /* __G_OUTPUT_STREAM_H__ */