gkdbus: Fix underflow and unreachable code bug
[platform/upstream/glib.git] / gio / ginputstream.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_INPUT_STREAM_H__
24 #define __G_INPUT_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_INPUT_STREAM         (g_input_stream_get_type ())
35 #define G_INPUT_STREAM(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_INPUT_STREAM, GInputStream))
36 #define G_INPUT_STREAM_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_INPUT_STREAM, GInputStreamClass))
37 #define G_IS_INPUT_STREAM(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_INPUT_STREAM))
38 #define G_IS_INPUT_STREAM_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_INPUT_STREAM))
39 #define G_INPUT_STREAM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), G_TYPE_INPUT_STREAM, GInputStreamClass))
40
41 /**
42  * GInputStream:
43  *
44  * Base class for streaming input operations.
45  **/
46 typedef struct _GInputStreamClass    GInputStreamClass;
47 typedef struct _GInputStreamPrivate  GInputStreamPrivate;
48
49 struct _GInputStream
50 {
51   GObject parent_instance;
52
53   /*< private >*/
54   GInputStreamPrivate *priv;
55 };
56
57 struct _GInputStreamClass
58 {
59   GObjectClass parent_class;
60
61   /* Sync ops: */
62
63   gssize   (* read_fn)      (GInputStream        *stream,
64                              void                *buffer,
65                              gsize                count,
66                              GCancellable        *cancellable,
67                              GError             **error);
68   gssize   (* skip)         (GInputStream        *stream,
69                              gsize                count,
70                              GCancellable        *cancellable,
71                              GError             **error);
72   gboolean (* close_fn)     (GInputStream        *stream,
73                              GCancellable        *cancellable,
74                              GError             **error);
75
76   /* Async ops: (optional in derived classes) */
77   void     (* read_async)   (GInputStream        *stream,
78                              void                *buffer,
79                              gsize                count,
80                              int                  io_priority,
81                              GCancellable        *cancellable,
82                              GAsyncReadyCallback  callback,
83                              gpointer             user_data);
84   gssize   (* read_finish)  (GInputStream        *stream,
85                              GAsyncResult        *result,
86                              GError             **error);
87   void     (* skip_async)   (GInputStream        *stream,
88                              gsize                count,
89                              int                  io_priority,
90                              GCancellable        *cancellable,
91                              GAsyncReadyCallback  callback,
92                              gpointer             user_data);
93   gssize   (* skip_finish)  (GInputStream        *stream,
94                              GAsyncResult        *result,
95                              GError             **error);
96   void     (* close_async)  (GInputStream        *stream,
97                              int                  io_priority,
98                              GCancellable        *cancellable,
99                              GAsyncReadyCallback  callback,
100                              gpointer             user_data);
101   gboolean (* close_finish) (GInputStream        *stream,
102                              GAsyncResult        *result,
103                              GError             **error);
104
105   /*< private >*/
106   /* Padding for future expansion */
107   void (*_g_reserved1) (void);
108   void (*_g_reserved2) (void);
109   void (*_g_reserved3) (void);
110   void (*_g_reserved4) (void);
111   void (*_g_reserved5) (void);
112 };
113
114 GIO_AVAILABLE_IN_ALL
115 GType    g_input_stream_get_type      (void) G_GNUC_CONST;
116
117 GIO_AVAILABLE_IN_ALL
118 gssize   g_input_stream_read          (GInputStream          *stream,
119                                        void                  *buffer,
120                                        gsize                  count,
121                                        GCancellable          *cancellable,
122                                        GError               **error);
123 GIO_AVAILABLE_IN_ALL
124 gboolean g_input_stream_read_all      (GInputStream          *stream,
125                                        void                  *buffer,
126                                        gsize                  count,
127                                        gsize                 *bytes_read,
128                                        GCancellable          *cancellable,
129                                        GError               **error);
130 GIO_AVAILABLE_IN_2_34
131 GBytes  *g_input_stream_read_bytes    (GInputStream          *stream,
132                                        gsize                  count,
133                                        GCancellable          *cancellable,
134                                        GError               **error);
135 GIO_AVAILABLE_IN_ALL
136 gssize   g_input_stream_skip          (GInputStream          *stream,
137                                        gsize                  count,
138                                        GCancellable          *cancellable,
139                                        GError               **error);
140 GIO_AVAILABLE_IN_ALL
141 gboolean g_input_stream_close         (GInputStream          *stream,
142                                        GCancellable          *cancellable,
143                                        GError               **error);
144 GIO_AVAILABLE_IN_ALL
145 void     g_input_stream_read_async    (GInputStream          *stream,
146                                        void                  *buffer,
147                                        gsize                  count,
148                                        int                    io_priority,
149                                        GCancellable          *cancellable,
150                                        GAsyncReadyCallback    callback,
151                                        gpointer               user_data);
152 GIO_AVAILABLE_IN_ALL
153 gssize   g_input_stream_read_finish   (GInputStream          *stream,
154                                        GAsyncResult          *result,
155                                        GError               **error);
156
157 GIO_AVAILABLE_IN_2_44
158 void     g_input_stream_read_all_async    (GInputStream          *stream,
159                                            void                  *buffer,
160                                            gsize                  count,
161                                            int                    io_priority,
162                                            GCancellable          *cancellable,
163                                            GAsyncReadyCallback    callback,
164                                            gpointer               user_data);
165 GIO_AVAILABLE_IN_2_44
166 gboolean g_input_stream_read_all_finish   (GInputStream          *stream,
167                                            GAsyncResult          *result,
168                                            gsize                 *bytes_read,
169                                            GError               **error);
170
171 GIO_AVAILABLE_IN_2_34
172 void     g_input_stream_read_bytes_async  (GInputStream          *stream,
173                                            gsize                  count,
174                                            int                    io_priority,
175                                            GCancellable          *cancellable,
176                                            GAsyncReadyCallback    callback,
177                                            gpointer               user_data);
178 GIO_AVAILABLE_IN_2_34
179 GBytes  *g_input_stream_read_bytes_finish (GInputStream          *stream,
180                                            GAsyncResult          *result,
181                                            GError               **error);
182 GIO_AVAILABLE_IN_ALL
183 void     g_input_stream_skip_async    (GInputStream          *stream,
184                                        gsize                  count,
185                                        int                    io_priority,
186                                        GCancellable          *cancellable,
187                                        GAsyncReadyCallback    callback,
188                                        gpointer               user_data);
189 GIO_AVAILABLE_IN_ALL
190 gssize   g_input_stream_skip_finish   (GInputStream          *stream,
191                                        GAsyncResult          *result,
192                                        GError               **error);
193 GIO_AVAILABLE_IN_ALL
194 void     g_input_stream_close_async   (GInputStream          *stream,
195                                        int                    io_priority,
196                                        GCancellable          *cancellable,
197                                        GAsyncReadyCallback    callback,
198                                        gpointer               user_data);
199 GIO_AVAILABLE_IN_ALL
200 gboolean g_input_stream_close_finish  (GInputStream          *stream,
201                                        GAsyncResult          *result,
202                                        GError               **error);
203
204 /* For implementations: */
205
206 GIO_AVAILABLE_IN_ALL
207 gboolean g_input_stream_is_closed     (GInputStream          *stream);
208 GIO_AVAILABLE_IN_ALL
209 gboolean g_input_stream_has_pending   (GInputStream          *stream);
210 GIO_AVAILABLE_IN_ALL
211 gboolean g_input_stream_set_pending   (GInputStream          *stream,
212                                        GError               **error);
213 GIO_AVAILABLE_IN_ALL
214 void     g_input_stream_clear_pending (GInputStream          *stream);
215
216 G_END_DECLS
217
218 #endif /* __G_INPUT_STREAM_H__ */