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 = GPollableOutputStream.html 27 * outPack = gio 28 * outFile = PollableOutputStreamT 29 * strct = GPollableOutputStream 30 * realStrct= 31 * ctorStrct= 32 * clss = PollableOutputStreamT 33 * interf = PollableOutputStreamIF 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 * - glib.ErrorG 48 * - glib.GException 49 * - glib.Source 50 * - gio.Cancellable 51 * structWrap: 52 * - GCancellable* -> Cancellable 53 * - GSource* -> Source 54 * module aliases: 55 * local aliases: 56 * overrides: 57 */ 58 59 module gio.PollableOutputStreamT; 60 61 public import gtkc.giotypes; 62 63 public import gtkc.gio; 64 public import glib.ConstructionException; 65 public import gobject.ObjectG; 66 67 68 public import glib.ErrorG; 69 public import glib.GException; 70 public import glib.Source; 71 public import gio.Cancellable; 72 73 74 75 76 /** 77 * Description 78 * GPollableOutputStream is implemented by GOutputStreams that 79 * can be polled for readiness to write. 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 PollableOutputStreamT(TStruct) 84 { 85 86 /** the main Gtk struct */ 87 protected GPollableOutputStream* gPollableOutputStream; 88 89 90 public GPollableOutputStream* getPollableOutputStreamTStruct() 91 { 92 return cast(GPollableOutputStream*)getStruct(); 93 } 94 95 96 /** 97 */ 98 99 /** 100 * Checks if stream is actually pollable. Some classes may implement 101 * GPollableOutputStream but have only certain instances of that 102 * class be pollable. If this method returns FALSE, then the behavior 103 * of other GPollableOutputStream methods is undefined. 104 * For any given stream, the value returned by this method is constant; 105 * a stream cannot switch from pollable to non-pollable or vice versa. 106 * Since 2.28 107 * Returns: TRUE if stream is pollable, FALSE if not. 108 */ 109 public int gPollableOutputStreamCanPoll() 110 { 111 // gboolean g_pollable_output_stream_can_poll (GPollableOutputStream *stream); 112 return g_pollable_output_stream_can_poll(getPollableOutputStreamTStruct()); 113 } 114 115 /** 116 * Checks if stream can be written. 117 * Note that some stream types may not be able to implement this 100% 118 * reliably, and it is possible that a call to g_output_stream_write() 119 * after this returns TRUE would still block. To guarantee 120 * non-blocking behavior, you should always use 121 * g_pollable_output_stream_write_nonblocking(), which will return a 122 * G_IO_ERROR_WOULD_BLOCK error rather than blocking. 123 * Since 2.28 124 * Returns: TRUE if stream is writable, FALSE if not. If an error has occurred on stream, this will result in g_pollable_output_stream_is_writable() returning TRUE, and the next attempt to write will return the error. 125 */ 126 public int gPollableOutputStreamIsWritable() 127 { 128 // gboolean g_pollable_output_stream_is_writable (GPollableOutputStream *stream); 129 return g_pollable_output_stream_is_writable(getPollableOutputStreamTStruct()); 130 } 131 132 /** 133 * Creates a GSource that triggers when stream can be written, or 134 * cancellable is triggered or an error occurs. The callback on the 135 * source is of the GPollableSourceFunc type. 136 * As with g_pollable_output_stream_is_writable(), it is possible that 137 * the stream may not actually be writable even after the source 138 * triggers, so you should use g_pollable_output_stream_write_nonblocking() 139 * rather than g_output_stream_write() from the callback. 140 * Since 2.28 141 * Params: 142 * cancellable = a GCancellable, or NULL. [allow-none] 143 * Returns: a new GSource. [transfer full] 144 */ 145 public Source gPollableOutputStreamCreateSource(Cancellable cancellable) 146 { 147 // GSource * g_pollable_output_stream_create_source (GPollableOutputStream *stream, GCancellable *cancellable); 148 auto p = g_pollable_output_stream_create_source(getPollableOutputStreamTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct()); 149 150 if(p is null) 151 { 152 return null; 153 } 154 155 return ObjectG.getDObject!(Source)(cast(GSource*) p); 156 } 157 158 /** 159 * Attempts to write up to size bytes from buffer to stream, as 160 * with g_output_stream_write(). If stream is not currently writable, 161 * this will immediately return G_IO_ERROR_WOULD_BLOCK, and you can 162 * use g_pollable_output_stream_create_source() to create a GSource 163 * that will be triggered when stream is writable. 164 * Note that since this method never blocks, you cannot actually 165 * use cancellable to cancel it. However, it will return an error 166 * if cancellable has already been cancelled when you call, which 167 * may happen if you call this method after a source triggers due 168 * to having been cancelled. 169 * Virtual: write_nonblocking 170 * Params: 171 * buffer = a buffer to write 172 * data from. [array length=size][element-type guint8] 173 * size = the number of bytes you want to write 174 * cancellable = a GCancellable, or NULL. [allow-none] 175 * Returns: the number of bytes written, or -1 on error (including G_IO_ERROR_WOULD_BLOCK). 176 * Throws: GException on failure. 177 */ 178 public gssize gPollableOutputStreamWriteNonblocking(void[] buffer, Cancellable cancellable) 179 { 180 // gssize g_pollable_output_stream_write_nonblocking (GPollableOutputStream *stream, const void *buffer, gsize size, GCancellable *cancellable, GError **error); 181 GError* err = null; 182 183 auto p = g_pollable_output_stream_write_nonblocking(getPollableOutputStreamTStruct(), buffer.ptr, cast(int) buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 184 185 if (err !is null) 186 { 187 throw new GException( new ErrorG(err) ); 188 } 189 190 return p; 191 } 192 }