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  = GInitable.html
27  * outPack = gio
28  * outFile = InitableT
29  * strct   = GInitable
30  * realStrct=
31  * ctorStrct=
32  * clss    = InitableT
33  * interf  = InitableIF
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * 	- TStruct
38  * extend  = 
39  * implements:
40  * prefixes:
41  * 	- g_initable_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- gobject.ObjectG
51  * 	- gio.Cancellable
52  * structWrap:
53  * 	- GCancellable* -> Cancellable
54  * 	- GObject* -> ObjectG
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gio.InitableT;
61 
62 public  import gtkc.giotypes;
63 
64 public import gtkc.gio;
65 public import glib.ConstructionException;
66 public import gobject.ObjectG;
67 
68 
69 public import glib.Str;
70 public import glib.ErrorG;
71 public import glib.GException;
72 public import gobject.ObjectG;
73 public import gio.Cancellable;
74 
75 
76 
77 
78 /**
79  * GInitable is implemented by objects that can fail during
80  * initialization. If an object implements this interface then
81  * it must be initialized as the first thing after construction,
82  * either via g_initable_init() or g_async_initable_init_async()
83  * (the latter is only available if it also implements GAsyncInitable).
84  *
85  * If the object is not initialized, or initialization returns with an
86  * error, then all operations on the object except g_object_ref() and
87  * g_object_unref() are considered to be invalid, and have undefined
88  * behaviour. They will often fail with g_critical() or g_warning(), but
89  * this must not be relied on.
90  *
91  * Users of objects implementing this are not intended to use
92  * the interface method directly, instead it will be used automatically
93  * in various ways. For C applications you generally just call
94  * g_initable_new() directly, or indirectly via a foo_thing_new() wrapper.
95  * This will call g_initable_init() under the cover, returning NULL and
96  * setting a GError on failure (at which point the instance is
97  * unreferenced).
98  *
99  * For bindings in languages where the native constructor supports
100  * exceptions the binding could check for objects implemention GInitable
101  * during normal construction and automatically initialize them, throwing
102  * an exception on failure.
103  */
104 public template InitableT(TStruct)
105 {
106 	
107 	/** the main Gtk struct */
108 	protected GInitable* gInitable;
109 	
110 	
111 	public GInitable* getInitableTStruct()
112 	{
113 		return cast(GInitable*)getStruct();
114 	}
115 	
116 	
117 	/**
118 	 */
119 	
120 	/**
121 	 * Initializes the object implementing the interface.
122 	 * The object must be initialized before any real use after initial
123 	 * construction, either with this function or g_async_initable_init_async().
124 	 * Implementations may also support cancellation. If cancellable is not NULL,
125 	 * then initialization can be cancelled by triggering the cancellable object
126 	 * from another thread. If the operation was cancelled, the error
127 	 * G_IO_ERROR_CANCELLED will be returned. If cancellable is not NULL and
128 	 * the object doesn't support cancellable initialization the error
129 	 * G_IO_ERROR_NOT_SUPPORTED will be returned.
130 	 * If the object is not initialized, or initialization returns with an
131 	 * error, then all operations on the object except g_object_ref() and
132 	 * g_object_unref() are considered to be invalid, and have undefined
133 	 * behaviour. See the ??? section introduction
134 	 * for more details.
135 	 * Implementations of this method must be idempotent, i.e. multiple calls
136 	 * to this function with the same argument should return the same results.
137 	 * Only the first call initializes the object, further calls return the result
138 	 * of the first call. This is so that it's safe to implement the singleton
139 	 * pattern in the GObject constructor function.
140 	 * Since 2.22
141 	 * Params:
142 	 * cancellable = optional GCancellable object, NULL to ignore.
143 	 * Returns: TRUE if successful. If an error has occurred, this function will return FALSE and set error appropriately if present.
144 	 * Throws: GException on failure.
145 	 */
146 	public int init(Cancellable cancellable)
147 	{
148 		// gboolean g_initable_init (GInitable *initable,  GCancellable *cancellable,  GError **error);
149 		GError* err = null;
150 		
151 		auto p = g_initable_init(getInitableTStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
152 		
153 		if (err !is null)
154 		{
155 			throw new GException( new ErrorG(err) );
156 		}
157 		
158 		return p;
159 	}
160 	
161 	/**
162 	 * Helper function for constructing GInitable object. This is
163 	 * similar to g_object_new_valist() but also initializes the object
164 	 * and returns NULL, setting an error on failure.
165 	 * Since 2.22
166 	 * Params:
167 	 * objectType = a GType supporting GInitable.
168 	 * firstPropertyName = the name of the first property, followed by
169 	 * the value, and other property value pairs, and ended by NULL.
170 	 * varArgs = The var args list generated from first_property_name.
171 	 * cancellable = optional GCancellable object, NULL to ignore.
172 	 * Returns: a newly allocated GObject, or NULL on error. [type GObject.Object][transfer full]
173 	 * Throws: GException on failure.
174 	 */
175 	public static ObjectG newValist(GType objectType, string firstPropertyName, void* varArgs, Cancellable cancellable)
176 	{
177 		// GObject * g_initable_new_valist (GType object_type,  const gchar *first_property_name,  va_list var_args,  GCancellable *cancellable,  GError **error);
178 		GError* err = null;
179 		
180 		auto p = g_initable_new_valist(objectType, Str.toStringz(firstPropertyName), varArgs, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
181 		
182 		if (err !is null)
183 		{
184 			throw new GException( new ErrorG(err) );
185 		}
186 		
187 		
188 		if(p is null)
189 		{
190 			return null;
191 		}
192 		
193 		return ObjectG.getDObject!(ObjectG)(cast(GObject*) p);
194 	}
195 	
196 	/**
197 	 * Helper function for constructing GInitable object. This is
198 	 * similar to g_object_newv() but also initializes the object
199 	 * and returns NULL, setting an error on failure.
200 	 * Since 2.22
201 	 * Params:
202 	 * objectType = a GType supporting GInitable.
203 	 * parameters = the parameters to use to construct the object. [array length=n_parameters]
204 	 * cancellable = optional GCancellable object, NULL to ignore.
205 	 * Returns: a newly allocated GObject, or NULL on error. [type GObject.Object][transfer full]
206 	 * Throws: GException on failure.
207 	 */
208 	public static void* newv(GType objectType, GParameter[] parameters, Cancellable cancellable)
209 	{
210 		// gpointer g_initable_newv (GType object_type,  guint n_parameters,  GParameter *parameters,  GCancellable *cancellable,  GError **error);
211 		GError* err = null;
212 		
213 		auto p = g_initable_newv(objectType, cast(int) parameters.length, parameters.ptr, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
214 		
215 		if (err !is null)
216 		{
217 			throw new GException( new ErrorG(err) );
218 		}
219 		
220 		return p;
221 	}
222 }