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 * Conversion parameters: 26 * inFile = GPollableInputStream.html 27 * outPack = gio 28 * outFile = PollableInputStreamT 29 * strct = GPollableInputStream 30 * realStrct= 31 * ctorStrct= 32 * clss = PollableInputStreamT 33 * interf = PollableInputStreamIF 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * - TStruct 38 * extend = 39 * implements: 40 * prefixes: 41 * - g_pollable_input_stream_ 42 * omit structs: 43 * omit prefixes: 44 * omit code: 45 * omit signals: 46 * imports: 47 * - gobject.ObjectG 48 * - glib.ErrorG 49 * - glib.GException 50 * - glib.Source 51 * - gio.Cancellable 52 * structWrap: 53 * - GCancellable* -> Cancellable 54 * - GObject* -> ObjectG 55 * - GSource* -> Source 56 * module aliases: 57 * local aliases: 58 * overrides: 59 */ 60 61 module gio.PollableInputStreamT; 62 63 public import gtkc.giotypes; 64 65 public import gtkc.gio; 66 public import glib.ConstructionException; 67 public import gobject.ObjectG; 68 69 70 public import gobject.ObjectG; 71 public import glib.ErrorG; 72 public import glib.GException; 73 public import glib.Source; 74 public import gio.Cancellable; 75 76 77 78 79 /** 80 * Description 81 * GPollableInputStream is implemented by GInputStreams that 82 * can be polled for readiness to read. This can be used when 83 * interfacing with a non-GIO API that expects 84 * UNIX-file-descriptor-style asynchronous I/O rather than GIO-style. 85 */ 86 public template PollableInputStreamT(TStruct) 87 { 88 89 /** the main Gtk struct */ 90 protected GPollableInputStream* gPollableInputStream; 91 92 93 public GPollableInputStream* getPollableInputStreamTStruct() 94 { 95 return cast(GPollableInputStream*)getStruct(); 96 } 97 98 99 /** 100 */ 101 102 /** 103 * Checks if stream is actually pollable. Some classes may implement 104 * GPollableInputStream but have only certain instances of that class 105 * be pollable. If this method returns FALSE, then the behavior of 106 * other GPollableInputStream methods is undefined. 107 * For any given stream, the value returned by this method is constant; 108 * a stream cannot switch from pollable to non-pollable or vice versa. 109 * Since 2.28 110 * Returns: TRUE if stream is pollable, FALSE if not. 111 */ 112 public int canPoll() 113 { 114 // gboolean g_pollable_input_stream_can_poll (GPollableInputStream *stream); 115 return g_pollable_input_stream_can_poll(getPollableInputStreamTStruct()); 116 } 117 118 /** 119 * Checks if stream can be read. 120 * Note that some stream types may not be able to implement this 100% 121 * reliably, and it is possible that a call to g_input_stream_read() 122 * after this returns TRUE would still block. To guarantee 123 * non-blocking behavior, you should always use 124 * g_pollable_input_stream_read_nonblocking(), which will return a 125 * G_IO_ERROR_WOULD_BLOCK error rather than blocking. 126 * Since 2.28 127 * Returns: TRUE if stream is readable, FALSE if not. If an error has occurred on stream, this will result in g_pollable_input_stream_is_readable() returning TRUE, and the next attempt to read will return the error. 128 */ 129 public int isReadable() 130 { 131 // gboolean g_pollable_input_stream_is_readable (GPollableInputStream *stream); 132 return g_pollable_input_stream_is_readable(getPollableInputStreamTStruct()); 133 } 134 135 /** 136 * Creates a GSource that triggers when stream can be read, or 137 * cancellable is triggered or an error occurs. The callback on the 138 * source is of the GPollableSourceFunc type. 139 * As with g_pollable_input_stream_is_readable(), it is possible that 140 * the stream may not actually be readable even after the source 141 * triggers, so you should use g_pollable_input_stream_read_nonblocking() 142 * rather than g_input_stream_read() from the callback. 143 * Since 2.28 144 * Params: 145 * cancellable = a GCancellable, or NULL. [allow-none] 146 * Returns: a new GSource. [transfer full] 147 */ 148 public Source createSource(Cancellable cancellable) 149 { 150 // GSource * g_pollable_input_stream_create_source (GPollableInputStream *stream, GCancellable *cancellable); 151 auto p = g_pollable_input_stream_create_source(getPollableInputStreamTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct()); 152 153 if(p is null) 154 { 155 return null; 156 } 157 158 return ObjectG.getDObject!(Source)(cast(GSource*) p); 159 } 160 161 /** 162 * Attempts to read up to size bytes from stream into buffer, as 163 * with g_input_stream_read(). If stream is not currently readable, 164 * this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can 165 * use g_pollable_input_stream_create_source() to create a GSource 166 * that will be triggered when stream is readable. 167 * Note that since this method never blocks, you cannot actually 168 * use cancellable to cancel it. However, it will return an error 169 * if cancellable has already been cancelled when you call, which 170 * may happen if you call this method after a source triggers due 171 * to having been cancelled. 172 * Virtual: read_nonblocking 173 * Params: 174 * buffer = a buffer to read data into (which should be at least size 175 * bytes long). 176 * size = the number of bytes you want to read 177 * cancellable = a GCancellable, or NULL. [allow-none] 178 * Returns: the number of bytes read, or -1 on error (including G_IO_ERROR_WOULD_BLOCK). 179 * Throws: GException on failure. 180 */ 181 public gssize readNonblocking(void[] buffer, Cancellable cancellable) 182 { 183 // gssize g_pollable_input_stream_read_nonblocking (GPollableInputStream *stream, void *buffer, gsize size, GCancellable *cancellable, GError **error); 184 GError* err = null; 185 186 auto p = g_pollable_input_stream_read_nonblocking(getPollableInputStreamTStruct(), buffer.ptr, cast(int) buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 187 188 if (err !is null) 189 { 190 throw new GException( new ErrorG(err) ); 191 } 192 193 return p; 194 } 195 196 /** 197 * Utility method for GPollableInputStream and GPollableOutputStream 198 * implementations. Creates a new GSource that expects a callback of 199 * type GPollableSourceFunc. The new source does not actually do 200 * anything on its own; use g_source_add_child_source() to add other 201 * sources to it to cause it to trigger. 202 * Since 2.28 203 * Params: 204 * pollableStream = the stream associated with the new source 205 * Returns: the new GSource. [transfer full] 206 */ 207 public static Source gPollableSourceNew(ObjectG pollableStream) 208 { 209 // GSource * g_pollable_source_new (GObject *pollable_stream); 210 auto p = g_pollable_source_new((pollableStream is null) ? null : pollableStream.getObjectGStruct()); 211 212 if(p is null) 213 { 214 return null; 215 } 216 217 return ObjectG.getDObject!(Source)(cast(GSource*) p); 218 } 219 }