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 module gio.InitableT;
26 
27 public  import gio.Cancellable;
28 public  import glib.ConstructionException;
29 public  import glib.ErrorG;
30 public  import glib.GException;
31 public  import glib.Str;
32 public  import gobject.ObjectG;
33 public  import gtkc.gio;
34 public  import gtkc.giotypes;
35 
36 
37 /**
38  * #GInitable is implemented by objects that can fail during
39  * initialization. If an object implements this interface then
40  * it must be initialized as the first thing after construction,
41  * either via g_initable_init() or g_async_initable_init_async()
42  * (the latter is only available if it also implements #GAsyncInitable).
43  * 
44  * If the object is not initialized, or initialization returns with an
45  * error, then all operations on the object except g_object_ref() and
46  * g_object_unref() are considered to be invalid, and have undefined
47  * behaviour. They will often fail with g_critical() or g_warning(), but
48  * this must not be relied on.
49  * 
50  * Users of objects implementing this are not intended to use
51  * the interface method directly, instead it will be used automatically
52  * in various ways. For C applications you generally just call
53  * g_initable_new() directly, or indirectly via a foo_thing_new() wrapper.
54  * This will call g_initable_init() under the cover, returning %NULL and
55  * setting a #GError on failure (at which point the instance is
56  * unreferenced).
57  * 
58  * For bindings in languages where the native constructor supports
59  * exceptions the binding could check for objects implemention %GInitable
60  * during normal construction and automatically initialize them, throwing
61  * an exception on failure.
62  *
63  * Since: 2.22
64  */
65 public template InitableT(TStruct)
66 {
67 	/** Get the main Gtk struct */
68 	public GInitable* getInitableStruct()
69 	{
70 		return cast(GInitable*)getStruct();
71 	}
72 
73 	/**
74 	 */
75 
76 	/**
77 	 * Initializes the object implementing the interface.
78 	 *
79 	 * The object must be initialized before any real use after initial
80 	 * construction, either with this function or g_async_initable_init_async().
81 	 *
82 	 * Implementations may also support cancellation. If @cancellable is not %NULL,
83 	 * then initialization can be cancelled by triggering the cancellable object
84 	 * from another thread. If the operation was cancelled, the error
85 	 * %G_IO_ERROR_CANCELLED will be returned. If @cancellable is not %NULL and
86 	 * the object doesn't support cancellable initialization the error
87 	 * %G_IO_ERROR_NOT_SUPPORTED will be returned.
88 	 *
89 	 * If the object is not initialized, or initialization returns with an
90 	 * error, then all operations on the object except g_object_ref() and
91 	 * g_object_unref() are considered to be invalid, and have undefined
92 	 * behaviour. See the [introduction][ginitable] for more details.
93 	 *
94 	 * Implementations of this method must be idempotent, i.e. multiple calls
95 	 * to this function with the same argument should return the same results.
96 	 * Only the first call initializes the object, further calls return the result
97 	 * of the first call. This is so that it's safe to implement the singleton
98 	 * pattern in the GObject constructor function.
99 	 *
100 	 * Params:
101 	 *     cancellable = optional #GCancellable object, %NULL to ignore.
102 	 *
103 	 * Return: %TRUE if successful. If an error has occurred, this function will
104 	 *     return %FALSE and set @error appropriately if present.
105 	 *
106 	 * Since: 2.22
107 	 *
108 	 * Throws: GException on failure.
109 	 */
110 	public bool init(Cancellable cancellable)
111 	{
112 		GError* err = null;
113 		
114 		auto p = g_initable_init(getInitableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
115 		
116 		if (err !is null)
117 		{
118 			throw new GException( new ErrorG(err) );
119 		}
120 		
121 		return p;
122 	}
123 }