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 public import gobject.ObjectG; 70 public import glib.ErrorG; 71 public import glib.GException; 72 public import glib.Source; 73 public import gio.Cancellable; 74 75 76 77 /** 78 * GPollableInputStream is implemented by GInputStreams that 79 * can be polled for readiness to read. This can be used when 80 * interfacing with a non-GIO API that expects 81 * UNIX-file-descriptor-style asynchronous I/O rather than GIO-style. 82 */ 83 public template PollableInputStreamT(TStruct) 84 { 85 86 /** the main Gtk struct */ 87 protected GPollableInputStream* gPollableInputStream; 88 89 90 /** Get the main Gtk struct */ 91 public GPollableInputStream* getPollableInputStreamTStruct() 92 { 93 return cast(GPollableInputStream*)getStruct(); 94 } 95 96 97 /** 98 */ 99 100 /** 101 * Checks if stream is actually pollable. Some classes may implement 102 * GPollableInputStream but have only certain instances of that class 103 * be pollable. If this method returns FALSE, then the behavior of 104 * other GPollableInputStream methods is undefined. 105 * For any given stream, the value returned by this method is constant; 106 * a stream cannot switch from pollable to non-pollable or vice versa. 107 * Since 2.28 108 * Returns: TRUE if stream is pollable, FALSE if not. 109 */ 110 public int canPoll() 111 { 112 // gboolean g_pollable_input_stream_can_poll (GPollableInputStream *stream); 113 return g_pollable_input_stream_can_poll(getPollableInputStreamTStruct()); 114 } 115 116 /** 117 * Checks if stream can be read. 118 * Note that some stream types may not be able to implement this 100% 119 * reliably, and it is possible that a call to g_input_stream_read() 120 * after this returns TRUE would still block. To guarantee 121 * non-blocking behavior, you should always use 122 * g_pollable_input_stream_read_nonblocking(), which will return a 123 * G_IO_ERROR_WOULD_BLOCK error rather than blocking. 124 * Since 2.28 125 * 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. 126 */ 127 public int isReadable() 128 { 129 // gboolean g_pollable_input_stream_is_readable (GPollableInputStream *stream); 130 return g_pollable_input_stream_is_readable(getPollableInputStreamTStruct()); 131 } 132 133 /** 134 * Creates a GSource that triggers when stream can be read, or 135 * cancellable is triggered or an error occurs. The callback on the 136 * source is of the GPollableSourceFunc type. 137 * As with g_pollable_input_stream_is_readable(), it is possible that 138 * the stream may not actually be readable even after the source 139 * triggers, so you should use g_pollable_input_stream_read_nonblocking() 140 * rather than g_input_stream_read() from the callback. 141 * Since 2.28 142 * Params: 143 * cancellable = a GCancellable, or NULL. [allow-none] 144 * Returns: a new GSource. [transfer full] 145 */ 146 public Source createSource(Cancellable cancellable) 147 { 148 // GSource * g_pollable_input_stream_create_source (GPollableInputStream *stream, GCancellable *cancellable); 149 auto p = g_pollable_input_stream_create_source(getPollableInputStreamTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct()); 150 151 if(p is null) 152 { 153 return null; 154 } 155 156 return ObjectG.getDObject!(Source)(cast(GSource*) p); 157 } 158 159 /** 160 * Attempts to read up to count bytes from stream into buffer, as 161 * with g_input_stream_read(). If stream is not currently readable, 162 * this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can 163 * use g_pollable_input_stream_create_source() to create a GSource 164 * that will be triggered when stream is readable. 165 * Note that since this method never blocks, you cannot actually 166 * use cancellable to cancel it. However, it will return an error 167 * if cancellable has already been cancelled when you call, which 168 * may happen if you call this method after a source triggers due 169 * to having been cancelled. 170 * Virtual: read_nonblocking 171 * Params: 172 * buffer = a buffer to read data into (which should be at least count 173 * bytes long). 174 * count = the number of bytes you want to read 175 * cancellable = a GCancellable, or NULL. [allow-none] 176 * Returns: the number of bytes read, or -1 on error (including G_IO_ERROR_WOULD_BLOCK). 177 * Throws: GException on failure. 178 */ 179 public gssize readNonblocking(void[] buffer, gsize count, Cancellable cancellable) 180 { 181 // gssize g_pollable_input_stream_read_nonblocking (GPollableInputStream *stream, void *buffer, gsize count, GCancellable *cancellable, GError **error); 182 GError* err = null; 183 184 auto p = g_pollable_input_stream_read_nonblocking(getPollableInputStreamTStruct(), buffer.ptr, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 185 186 if (err !is null) 187 { 188 throw new GException( new ErrorG(err) ); 189 } 190 191 return p; 192 } 193 }