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