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