source: appstream-generator/build/girepo/gio/InitableT.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 4.3 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.InitableT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import gio.Cancellable;
26public  import glib.ConstructionException;
27public  import glib.ErrorG;
28public  import glib.GException;
29public  import glib.Str;
30public  import gobject.ObjectG;
31
32
33/**
34 * #GInitable is implemented by objects that can fail during
35 * initialization. If an object implements this interface then
36 * it must be initialized as the first thing after construction,
37 * either via g_initable_init() or g_async_initable_init_async()
38 * (the latter is only available if it also implements #GAsyncInitable).
39 *
40 * If the object is not initialized, or initialization returns with an
41 * error, then all operations on the object except g_object_ref() and
42 * g_object_unref() are considered to be invalid, and have undefined
43 * behaviour. They will often fail with g_critical() or g_warning(), but
44 * this must not be relied on.
45 *
46 * Users of objects implementing this are not intended to use
47 * the interface method directly, instead it will be used automatically
48 * in various ways. For C applications you generally just call
49 * g_initable_new() directly, or indirectly via a foo_thing_new() wrapper.
50 * This will call g_initable_init() under the cover, returning %NULL and
51 * setting a #GError on failure (at which point the instance is
52 * unreferenced).
53 *
54 * For bindings in languages where the native constructor supports
55 * exceptions the binding could check for objects implemention %GInitable
56 * during normal construction and automatically initialize them, throwing
57 * an exception on failure.
58 *
59 * Since: 2.22
60 */
61public template InitableT(TStruct)
62{
63        /** Get the main Gtk struct */
64        public GInitable* getInitableStruct()
65        {
66                return cast(GInitable*)getStruct();
67        }
68
69
70        /**
71         * Initializes the object implementing the interface.
72         *
73         * The object must be initialized before any real use after initial
74         * construction, either with this function or g_async_initable_init_async().
75         *
76         * Implementations may also support cancellation. If @cancellable is not %NULL,
77         * then initialization can be cancelled by triggering the cancellable object
78         * from another thread. If the operation was cancelled, the error
79         * %G_IO_ERROR_CANCELLED will be returned. If @cancellable is not %NULL and
80         * the object doesn't support cancellable initialization the error
81         * %G_IO_ERROR_NOT_SUPPORTED will be returned.
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. See the [introduction][ginitable] for more details.
87         *
88         * Implementations of this method must be idempotent, i.e. multiple calls
89         * to this function with the same argument should return the same results.
90         * Only the first call initializes the object, further calls return the result
91         * of the first call. This is so that it's safe to implement the singleton
92         * pattern in the GObject constructor function.
93         *
94         * Params:
95         *     cancellable = optional #GCancellable object, %NULL to ignore.
96         *
97         * Returns: %TRUE if successful. If an error has occurred, this function will
98         *     return %FALSE and set @error appropriately if present.
99         *
100         * Since: 2.22
101         *
102         * Throws: GException on failure.
103         */
104        public bool init(Cancellable cancellable)
105        {
106                GError* err = null;
107               
108                auto p = g_initable_init(getInitableStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0;
109               
110                if (err !is null)
111                {
112                        throw new GException( new ErrorG(err) );
113                }
114               
115                return p;
116        }
117}
Note: See TracBrowser for help on using the repository browser.