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