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  = gio-GDBusError.html
27  * outPack = gio
28  * outFile = DBusError
29  * strct   = GError
30  * realStrct=
31  * ctorStrct=
32  * clss    = DBusError
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_dbus_error_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * structWrap:
49  * 	- GError* -> ErrorG
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module gio.DBusError;
56 
57 public  import gtkc.giotypes;
58 
59 private import gtkc.gio;
60 private import glib.ConstructionException;
61 private import gobject.ObjectG;
62 
63 private import glib.Str;
64 private import glib.ErrorG;
65 
66 
67 
68 /**
69  * All facilities that return errors from remote methods (such as
70  * g_dbus_connection_call_sync()) use GError to represent both D-Bus
71  * errors (e.g. errors returned from the other peer) and locally
72  * in-process generated errors.
73  *
74  * To check if a returned GError is an error from a remote peer, use
75  * g_dbus_error_is_remote_error(). To get the actual D-Bus error name,
76  * use g_dbus_error_get_remote_error(). Before presenting an error,
77  * always use g_dbus_error_strip_remote_error().
78  *
79  * In addition, facilities used to return errors to a remote peer also
80  * use GError. See g_dbus_method_invocation_return_error() for
81  * discussion about how the D-Bus error name is set.
82  *
83  * Applications can associate a GError error domain with a set of D-Bus errors in order to
84  * automatically map from D-Bus errors to GError and back. This
85  * is typically done in the function returning the GQuark for the
86  * error domain:
87  *
88  * $(DDOC_COMMENT example)
89  *
90  * With this setup, a D-Bus peer can transparently pass e.g. FOO_BAR_ERROR_ANOTHER_ERROR and
91  * other peers will see the D-Bus error name org.project.Foo.Bar.Error.AnotherError.
92  *
93  * If the other peer is using GDBus, and has registered the association with
94  * g_dbus_error_register_error_domain() in advance (e.g. by invoking the FOO_BAR_ERROR quark
95  * generation itself in the previous example) the peer will see also FOO_BAR_ERROR_ANOTHER_ERROR instead
96  * of G_IO_ERROR_DBUS_ERROR. Note that GDBus clients can still recover
97  * org.project.Foo.Bar.Error.AnotherError using g_dbus_error_get_remote_error().
98  *
99  * Note that errors in the G_DBUS_ERROR error domain is intended only
100  * for returning errors from a remote message bus process. Errors
101  * generated locally in-process by e.g. GDBusConnection is from the
102  * G_IO_ERROR domain.
103  */
104 public class DBusError
105 {
106 	
107 	/** the main Gtk struct */
108 	protected GError* gError;
109 	
110 	
111 	/** Get the main Gtk struct */
112 	public GError* getDBusErrorStruct()
113 	{
114 		return gError;
115 	}
116 	
117 	
118 	/** the main Gtk struct as a void* */
119 	protected void* getStruct()
120 	{
121 		return cast(void*)gError;
122 	}
123 	
124 	/**
125 	 * Sets our main struct and passes it to the parent class
126 	 */
127 	public this (GError* gError)
128 	{
129 		this.gError = gError;
130 	}
131 	
132 	/**
133 	 */
134 	
135 	/**
136 	 * Checks if error represents an error received via D-Bus from a remote peer. If so,
137 	 * use g_dbus_error_get_remote_error() to get the name of the error.
138 	 * Since 2.26
139 	 * Returns: TRUE if error represents an error from a remote peer, FALSE otherwise.
140 	 */
141 	public int isRemoteError()
142 	{
143 		// gboolean g_dbus_error_is_remote_error (const GError *error);
144 		return g_dbus_error_is_remote_error(gError);
145 	}
146 	
147 	/**
148 	 * Gets the D-Bus error name used for error, if any.
149 	 * This function is guaranteed to return a D-Bus error name for all
150 	 * GErrors returned from functions handling remote method
151 	 * calls (e.g. g_dbus_connection_call_finish()) unless
152 	 * g_dbus_error_strip_remote_error() has been used on error.
153 	 * Since 2.26
154 	 * Returns: An allocated string or NULL if the D-Bus error name could not be found. Free with g_free().
155 	 */
156 	public string getRemoteError()
157 	{
158 		// gchar * g_dbus_error_get_remote_error (const GError *error);
159 		return Str.toString(g_dbus_error_get_remote_error(gError));
160 	}
161 	
162 	/**
163 	 * Looks for extra information in the error message used to recover
164 	 * the D-Bus error name and strips it if found. If stripped, the
165 	 * message field in error will correspond exactly to what was
166 	 * received on the wire.
167 	 * This is typically used when presenting errors to the end user.
168 	 * Since 2.26
169 	 * Returns: TRUE if information was stripped, FALSE otherwise.
170 	 */
171 	public int stripRemoteError()
172 	{
173 		// gboolean g_dbus_error_strip_remote_error (GError *error);
174 		return g_dbus_error_strip_remote_error(gError);
175 	}
176 	
177 	/**
178 	 * Helper function for associating a GError error domain with D-Bus error names.
179 	 * Since 2.26
180 	 * Params:
181 	 * errorDomainQuarkName = The error domain name.
182 	 * quarkVolatile = A pointer where to store the GQuark.
183 	 * entries = A pointer to num_entries GDBusErrorEntry struct items.
184 	 */
185 	public static void registerErrorDomain(string errorDomainQuarkName, out gsize quarkVolatile, GDBusErrorEntry[] entries)
186 	{
187 		// void g_dbus_error_register_error_domain (const gchar *error_domain_quark_name,  volatile gsize *quark_volatile,  const GDBusErrorEntry *entries,  guint num_entries);
188 		g_dbus_error_register_error_domain(Str.toStringz(errorDomainQuarkName), &quarkVolatile, entries.ptr, cast(int) entries.length);
189 	}
190 	
191 	/**
192 	 * Creates an association to map between dbus_error_name and
193 	 * GErrors specified by error_domain and error_code.
194 	 * This is typically done in the routine that returns the GQuark for
195 	 * an error domain.
196 	 * Since 2.26
197 	 * Params:
198 	 * errorDomain = A GQuark for a error domain.
199 	 * errorCode = An error code.
200 	 * dbusErrorName = A D-Bus error name.
201 	 * Returns: TRUE if the association was created, FALSE if it already exists.
202 	 */
203 	public static int registerError(GQuark errorDomain, int errorCode, string dbusErrorName)
204 	{
205 		// gboolean g_dbus_error_register_error (GQuark error_domain,  gint error_code,  const gchar *dbus_error_name);
206 		return g_dbus_error_register_error(errorDomain, errorCode, Str.toStringz(dbusErrorName));
207 	}
208 	
209 	/**
210 	 * Destroys an association previously set up with g_dbus_error_register_error().
211 	 * Since 2.26
212 	 * Params:
213 	 * errorDomain = A GQuark for a error domain.
214 	 * errorCode = An error code.
215 	 * dbusErrorName = A D-Bus error name.
216 	 * Returns: TRUE if the association was destroyed, FALSE if it wasn't found.
217 	 */
218 	public static int unregisterError(GQuark errorDomain, int errorCode, string dbusErrorName)
219 	{
220 		// gboolean g_dbus_error_unregister_error (GQuark error_domain,  gint error_code,  const gchar *dbus_error_name);
221 		return g_dbus_error_unregister_error(errorDomain, errorCode, Str.toStringz(dbusErrorName));
222 	}
223 	
224 	/**
225 	 * Creates a GError based on the contents of dbus_error_name and
226 	 * dbus_error_message.
227 	 * Errors registered with g_dbus_error_register_error() will be looked
228 	 * up using dbus_error_name and if a match is found, the error domain
229 	 * and code is used. Applications can use g_dbus_error_get_remote_error()
230 	 * to recover dbus_error_name.
231 	 * If a match against a registered error is not found and the D-Bus
232 	 * error name is in a form as returned by g_dbus_error_encode_gerror()
233 	 * the error domain and code encoded in the name is used to
234 	 * create the GError. Also, dbus_error_name is added to the error message
235 	 * such that it can be recovered with g_dbus_error_get_remote_error().
236 	 * Otherwise, a GError with the error code G_IO_ERROR_DBUS_ERROR
237 	 * in the G_IO_ERROR error domain is returned. Also, dbus_error_name is
238 	 * added to the error message such that it can be recovered with
239 	 * g_dbus_error_get_remote_error().
240 	 * In all three cases, dbus_error_name can always be recovered from the
241 	 * returned GError using the g_dbus_error_get_remote_error() function
242 	 * (unless g_dbus_error_strip_remote_error() hasn't been used on the returned error).
243 	 * This function is typically only used in object mappings to prepare
244 	 * GError instances for applications. Regular applications should not use
245 	 * it.
246 	 * Since 2.26
247 	 * Params:
248 	 * dbusErrorName = D-Bus error name.
249 	 * dbusErrorMessage = D-Bus error message.
250 	 * Throws: ConstructionException GTK+ fails to create the object.
251 	 */
252 	public this (string dbusErrorName, string dbusErrorMessage)
253 	{
254 		// GError * g_dbus_error_new_for_dbus_error (const gchar *dbus_error_name,  const gchar *dbus_error_message);
255 		auto p = g_dbus_error_new_for_dbus_error(Str.toStringz(dbusErrorName), Str.toStringz(dbusErrorMessage));
256 		if(p is null)
257 		{
258 			throw new ConstructionException("null returned by g_dbus_error_new_for_dbus_error(Str.toStringz(dbusErrorName), Str.toStringz(dbusErrorMessage))");
259 		}
260 		this(cast(GError*) p);
261 	}
262 	
263 	/**
264 	 * Like g_dbus_error_set_dbus_error() but intended for language bindings.
265 	 * Since 2.26
266 	 * Params:
267 	 * error = A pointer to a GError or NULL.
268 	 * dbusErrorName = D-Bus error name.
269 	 * dbusErrorMessage = D-Bus error message.
270 	 * format = printf()-style format to prepend to dbus_error_message or NULL. [allow-none]
271 	 * varArgs = Arguments for format.
272 	 */
273 	public static void setDbusErrorValist(out ErrorG error, string dbusErrorName, string dbusErrorMessage, string format, void* varArgs)
274 	{
275 		// void g_dbus_error_set_dbus_error_valist (GError **error,  const gchar *dbus_error_name,  const gchar *dbus_error_message,  const gchar *format,  va_list var_args);
276 		GError* outerror = null;
277 		
278 		g_dbus_error_set_dbus_error_valist(&outerror, Str.toStringz(dbusErrorName), Str.toStringz(dbusErrorMessage), Str.toStringz(format), varArgs);
279 		
280 		error = ObjectG.getDObject!(ErrorG)(outerror);
281 	}
282 	
283 	/**
284 	 * Creates a D-Bus error name to use for error. If error matches
285 	 * a registered error (cf. g_dbus_error_register_error()), the corresponding
286 	 * D-Bus error name will be returned.
287 	 * Otherwise the a name of the form
288 	 * org.gtk.GDBus.UnmappedGError.Quark._ESCAPED_QUARK_NAME.Code_ERROR_CODE
289 	 * will be used. This allows other GDBus applications to map the error
290 	 * on the wire back to a GError using g_dbus_error_new_for_dbus_error().
291 	 * This function is typically only used in object mappings to put a
292 	 * GError on the wire. Regular applications should not use it.
293 	 * Since 2.26
294 	 * Params:
295 	 * error = A GError.
296 	 * Returns: A D-Bus error name (never NULL). Free with g_free().
297 	 */
298 	public string encodeGerror()
299 	{
300 		// gchar * g_dbus_error_encode_gerror (const GError *error);
301 		return Str.toString(g_dbus_error_encode_gerror(gError));
302 	}
303 }