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