source: appstream-generator/build/girepo/gio/PollableUtils.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 7.1 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.PollableUtils;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.Cancellable;
26private import gio.InputStream;
27private import gio.OutputStream;
28private import glib.ErrorG;
29private import glib.GException;
30private import glib.Source;
31private import gobject.ObjectG;
32
33
34/** */
35
36/**
37 * Utility method for #GPollableInputStream and #GPollableOutputStream
38 * implementations. Creates a new #GSource that expects a callback of
39 * type #GPollableSourceFunc. The new source does not actually do
40 * anything on its own; use g_source_add_child_source() to add other
41 * sources to it to cause it to trigger.
42 *
43 * Params:
44 *     pollableStream = the stream associated with the new source
45 *
46 * Returns: the new #GSource.
47 *
48 * Since: 2.28
49 */
50public Source pollableSourceNew(ObjectG pollableStream)
51{
52        auto p = g_pollable_source_new((pollableStream is null) ? null : pollableStream.getObjectGStruct());
53       
54        if(p is null)
55        {
56                return null;
57        }
58       
59        return new Source(cast(GSource*) p, true);
60}
61
62/**
63 * Utility method for #GPollableInputStream and #GPollableOutputStream
64 * implementations. Creates a new #GSource, as with
65 * g_pollable_source_new(), but also attaching @child_source (with a
66 * dummy callback), and @cancellable, if they are non-%NULL.
67 *
68 * Params:
69 *     pollableStream = the stream associated with the
70 *         new source
71 *     childSource = optional child source to attach
72 *     cancellable = optional #GCancellable to attach
73 *
74 * Returns: the new #GSource.
75 *
76 * Since: 2.34
77 */
78public Source pollableSourceNewFull(ObjectG pollableStream, Source childSource, Cancellable cancellable)
79{
80        auto p = g_pollable_source_new_full((pollableStream is null) ? null : pollableStream.getObjectGStruct(), (childSource is null) ? null : childSource.getSourceStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct());
81       
82        if(p is null)
83        {
84                return null;
85        }
86       
87        return new Source(cast(GSource*) p, true);
88}
89
90/**
91 * Tries to read from @stream, as with g_input_stream_read() (if
92 * @blocking is %TRUE) or g_pollable_input_stream_read_nonblocking()
93 * (if @blocking is %FALSE). This can be used to more easily share
94 * code between blocking and non-blocking implementations of a method.
95 *
96 * If @blocking is %FALSE, then @stream must be a
97 * #GPollableInputStream for which g_pollable_input_stream_can_poll()
98 * returns %TRUE, or else the behavior is undefined. If @blocking is
99 * %TRUE, then @stream does not need to be a #GPollableInputStream.
100 *
101 * Params:
102 *     stream = a #GInputStream
103 *     buffer = a buffer to
104 *         read data into
105 *     count = the number of bytes to read
106 *     blocking = whether to do blocking I/O
107 *     cancellable = optional #GCancellable object, %NULL to ignore.
108 *
109 * Returns: the number of bytes read, or -1 on error.
110 *
111 * Since: 2.34
112 *
113 * Throws: GException on failure.
114 */
115public ptrdiff_t pollableStreamRead(InputStream stream, ubyte[] buffer, bool blocking, Cancellable cancellable)
116{
117        GError* err = null;
118       
119        auto p = g_pollable_stream_read((stream is null) ? null : stream.getInputStreamStruct(), buffer.ptr, cast(size_t)buffer.length, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
120       
121        if (err !is null)
122        {
123                throw new GException( new ErrorG(err) );
124        }
125       
126        return p;
127}
128
129/**
130 * Tries to write to @stream, as with g_output_stream_write() (if
131 * @blocking is %TRUE) or g_pollable_output_stream_write_nonblocking()
132 * (if @blocking is %FALSE). This can be used to more easily share
133 * code between blocking and non-blocking implementations of a method.
134 *
135 * If @blocking is %FALSE, then @stream must be a
136 * #GPollableOutputStream for which
137 * g_pollable_output_stream_can_poll() returns %TRUE or else the
138 * behavior is undefined. If @blocking is %TRUE, then @stream does not
139 * need to be a #GPollableOutputStream.
140 *
141 * Params:
142 *     stream = a #GOutputStream.
143 *     buffer = the buffer
144 *         containing the data to write.
145 *     count = the number of bytes to write
146 *     blocking = whether to do blocking I/O
147 *     cancellable = optional #GCancellable object, %NULL to ignore.
148 *
149 * Returns: the number of bytes written, or -1 on error.
150 *
151 * Since: 2.34
152 *
153 * Throws: GException on failure.
154 */
155public ptrdiff_t pollableStreamWrite(OutputStream stream, ubyte[] buffer, bool blocking, Cancellable cancellable)
156{
157        GError* err = null;
158       
159        auto p = g_pollable_stream_write((stream is null) ? null : stream.getOutputStreamStruct(), buffer.ptr, cast(size_t)buffer.length, blocking, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
160       
161        if (err !is null)
162        {
163                throw new GException( new ErrorG(err) );
164        }
165       
166        return p;
167}
168
169/**
170 * Tries to write @count bytes to @stream, as with
171 * g_output_stream_write_all(), but using g_pollable_stream_write()
172 * rather than g_output_stream_write().
173 *
174 * On a successful write of @count bytes, %TRUE is returned, and
175 * @bytes_written is set to @count.
176 *
177 * If there is an error during the operation (including
178 * %G_IO_ERROR_WOULD_BLOCK in the non-blocking case), %FALSE is
179 * returned and @error is set to indicate the error status,
180 * @bytes_written is updated to contain the number of bytes written
181 * into the stream before the error occurred.
182 *
183 * As with g_pollable_stream_write(), if @blocking is %FALSE, then
184 * @stream must be a #GPollableOutputStream for which
185 * g_pollable_output_stream_can_poll() returns %TRUE or else the
186 * behavior is undefined. If @blocking is %TRUE, then @stream does not
187 * need to be a #GPollableOutputStream.
188 *
189 * Params:
190 *     stream = a #GOutputStream.
191 *     buffer = the buffer
192 *         containing the data to write.
193 *     count = the number of bytes to write
194 *     blocking = whether to do blocking I/O
195 *     bytesWritten = location to store the number of bytes that was
196 *         written to the stream
197 *     cancellable = optional #GCancellable object, %NULL to ignore.
198 *
199 * Returns: %TRUE on success, %FALSE if there was an error
200 *
201 * Since: 2.34
202 *
203 * Throws: GException on failure.
204 */
205public bool pollableStreamWriteAll(OutputStream stream, ubyte[] buffer, bool blocking, out size_t bytesWritten, Cancellable cancellable)
206{
207        GError* err = null;
208       
209        auto p = g_pollable_stream_write_all((stream is null) ? null : stream.getOutputStreamStruct(), buffer.ptr, cast(size_t)buffer.length, blocking, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
210       
211        if (err !is null)
212        {
213                throw new GException( new ErrorG(err) );
214        }
215       
216        return p;
217}
Note: See TracBrowser for help on using the repository browser.