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