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