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