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.DBusError;
26 
27 private import glib.ErrorG;
28 private import glib.Str;
29 private import gtkc.gio;
30 public  import gtkc.giotypes;
31 
32 
33 /** */
34 public struct DBusError
35 {
36 
37 	/**
38 	 * Creates a D-Bus error name to use for @error. If @error matches
39 	 * a registered error (cf. g_dbus_error_register_error()), the corresponding
40 	 * D-Bus error name will be returned.
41 	 *
42 	 * Otherwise the a name of the form
43 	 * `org.gtk.GDBus.UnmappedGError.Quark._ESCAPED_QUARK_NAME.Code_ERROR_CODE`
44 	 * will be used. This allows other GDBus applications to map the error
45 	 * on the wire back to a #GError using g_dbus_error_new_for_dbus_error().
46 	 *
47 	 * This function is typically only used in object mappings to put a
48 	 * #GError on the wire. Regular applications should not use it.
49 	 *
50 	 * Params:
51 	 *     error = A #GError.
52 	 *
53 	 * Return: A D-Bus error name (never %NULL). Free with g_free().
54 	 *
55 	 * Since: 2.26
56 	 */
57 	public static string encodeGerror(ErrorG error)
58 	{
59 		return Str.toString(g_dbus_error_encode_gerror((error is null) ? null : error.getErrorGStruct()));
60 	}
61 
62 	/**
63 	 * Gets the D-Bus error name used for @error, if any.
64 	 *
65 	 * This function is guaranteed to return a D-Bus error name for all
66 	 * #GErrors returned from functions handling remote method calls
67 	 * (e.g. g_dbus_connection_call_finish()) unless
68 	 * g_dbus_error_strip_remote_error() has been used on @error.
69 	 *
70 	 * Params:
71 	 *     error = a #GError
72 	 *
73 	 * Return: an allocated string or %NULL if the D-Bus error name
74 	 *     could not be found. Free with g_free().
75 	 *
76 	 * Since: 2.26
77 	 */
78 	public static string getRemoteError(ErrorG error)
79 	{
80 		return Str.toString(g_dbus_error_get_remote_error((error is null) ? null : error.getErrorGStruct()));
81 	}
82 
83 	/**
84 	 * Checks if @error represents an error received via D-Bus from a remote peer. If so,
85 	 * use g_dbus_error_get_remote_error() to get the name of the error.
86 	 *
87 	 * Params:
88 	 *     error = A #GError.
89 	 *
90 	 * Return: %TRUE if @error represents an error from a remote peer,
91 	 *     %FALSE otherwise.
92 	 *
93 	 * Since: 2.26
94 	 */
95 	public static bool isRemoteError(ErrorG error)
96 	{
97 		return g_dbus_error_is_remote_error((error is null) ? null : error.getErrorGStruct()) != 0;
98 	}
99 
100 	/**
101 	 * Creates a #GError based on the contents of @dbus_error_name and
102 	 * @dbus_error_message.
103 	 *
104 	 * Errors registered with g_dbus_error_register_error() will be looked
105 	 * up using @dbus_error_name and if a match is found, the error domain
106 	 * and code is used. Applications can use g_dbus_error_get_remote_error()
107 	 * to recover @dbus_error_name.
108 	 *
109 	 * If a match against a registered error is not found and the D-Bus
110 	 * error name is in a form as returned by g_dbus_error_encode_gerror()
111 	 * the error domain and code encoded in the name is used to
112 	 * create the #GError. Also, @dbus_error_name is added to the error message
113 	 * such that it can be recovered with g_dbus_error_get_remote_error().
114 	 *
115 	 * Otherwise, a #GError with the error code %G_IO_ERROR_DBUS_ERROR
116 	 * in the #G_IO_ERROR error domain is returned. Also, @dbus_error_name is
117 	 * added to the error message such that it can be recovered with
118 	 * g_dbus_error_get_remote_error().
119 	 *
120 	 * In all three cases, @dbus_error_name can always be recovered from the
121 	 * returned #GError using the g_dbus_error_get_remote_error() function
122 	 * (unless g_dbus_error_strip_remote_error() hasn't been used on the returned error).
123 	 *
124 	 * This function is typically only used in object mappings to prepare
125 	 * #GError instances for applications. Regular applications should not use
126 	 * it.
127 	 *
128 	 * Params:
129 	 *     dbusErrorName = D-Bus error name.
130 	 *     dbusErrorMessage = D-Bus error message.
131 	 *
132 	 * Return: An allocated #GError. Free with g_error_free().
133 	 *
134 	 * Since: 2.26
135 	 */
136 	public static ErrorG newForDbusError(string dbusErrorName, string dbusErrorMessage)
137 	{
138 		auto p = g_dbus_error_new_for_dbus_error(Str.toStringz(dbusErrorName), Str.toStringz(dbusErrorMessage));
139 		
140 		if(p is null)
141 		{
142 			return null;
143 		}
144 		
145 		return new ErrorG(cast(GError*) p);
146 	}
147 
148 	/** */
149 	public static GQuark quark()
150 	{
151 		return g_dbus_error_quark();
152 	}
153 
154 	/**
155 	 * Creates an association to map between @dbus_error_name and
156 	 * #GErrors specified by @error_domain and @error_code.
157 	 *
158 	 * This is typically done in the routine that returns the #GQuark for
159 	 * an error domain.
160 	 *
161 	 * Params:
162 	 *     errorDomain = A #GQuark for a error domain.
163 	 *     errorCode = An error code.
164 	 *     dbusErrorName = A D-Bus error name.
165 	 *
166 	 * Return: %TRUE if the association was created, %FALSE if it already
167 	 *     exists.
168 	 *
169 	 * Since: 2.26
170 	 */
171 	public static bool registerError(GQuark errorDomain, int errorCode, string dbusErrorName)
172 	{
173 		return g_dbus_error_register_error(errorDomain, errorCode, Str.toStringz(dbusErrorName)) != 0;
174 	}
175 
176 	/**
177 	 * Helper function for associating a #GError error domain with D-Bus error names.
178 	 *
179 	 * Params:
180 	 *     errorDomainQuarkName = The error domain name.
181 	 *     quarkVolatile = A pointer where to store the #GQuark.
182 	 *     entries = A pointer to @num_entries #GDBusErrorEntry struct items.
183 	 *     numEntries = Number of items to register.
184 	 *
185 	 * Since: 2.26
186 	 */
187 	public static void registerErrorDomain(string errorDomainQuarkName, size_t* quarkVolatile, GDBusErrorEntry* entries, uint numEntries)
188 	{
189 		g_dbus_error_register_error_domain(Str.toStringz(errorDomainQuarkName), quarkVolatile, entries, numEntries);
190 	}
191 
192 	/**
193 	 * Looks for extra information in the error message used to recover
194 	 * the D-Bus error name and strips it if found. If stripped, the
195 	 * message field in @error will correspond exactly to what was
196 	 * received on the wire.
197 	 *
198 	 * This is typically used when presenting errors to the end user.
199 	 *
200 	 * Params:
201 	 *     error = A #GError.
202 	 *
203 	 * Return: %TRUE if information was stripped, %FALSE otherwise.
204 	 *
205 	 * Since: 2.26
206 	 */
207 	public static bool stripRemoteError(ErrorG error)
208 	{
209 		return g_dbus_error_strip_remote_error((error is null) ? null : error.getErrorGStruct()) != 0;
210 	}
211 
212 	/**
213 	 * Destroys an association previously set up with g_dbus_error_register_error().
214 	 *
215 	 * Params:
216 	 *     errorDomain = A #GQuark for a error domain.
217 	 *     errorCode = An error code.
218 	 *     dbusErrorName = A D-Bus error name.
219 	 *
220 	 * Return: %TRUE if the association was destroyed, %FALSE if it wasn't found.
221 	 *
222 	 * Since: 2.26
223 	 */
224 	public static bool unregisterError(GQuark errorDomain, int errorCode, string dbusErrorName)
225 	{
226 		return g_dbus_error_unregister_error(errorDomain, errorCode, Str.toStringz(dbusErrorName)) != 0;
227 	}
228 }