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 public struct DBusError
34 {
35 	/**
36 	 */
37 
38 	/**
39 	 * Creates a D-Bus error name to use for @error. If @error matches
40 	 * a registered error (cf. g_dbus_error_register_error()), the corresponding
41 	 * D-Bus error name will be returned.
42 	 *
43 	 * Otherwise the a name of the form
44 	 * `org.gtk.GDBus.UnmappedGError.Quark._ESCAPED_QUARK_NAME.Code_ERROR_CODE`
45 	 * will be used. This allows other GDBus applications to map the error
46 	 * on the wire back to a #GError using g_dbus_error_new_for_dbus_error().
47 	 *
48 	 * This function is typically only used in object mappings to put a
49 	 * #GError on the wire. Regular applications should not use it.
50 	 *
51 	 * Params:
52 	 *     error = A #GError.
53 	 *
54 	 * Return: A D-Bus error name (never %NULL). Free with g_free().
55 	 *
56 	 * Since: 2.26
57 	 */
58 	public static string encodeGerror(ErrorG error)
59 	{
60 		return Str.toString(g_dbus_error_encode_gerror((error is null) ? null : error.getErrorGStruct()));
61 	}
62 
63 	/**
64 	 * Gets the D-Bus error name used for @error, if any.
65 	 *
66 	 * This function is guaranteed to return a D-Bus error name for all
67 	 * #GErrors returned from functions handling remote method calls
68 	 * (e.g. g_dbus_connection_call_finish()) unless
69 	 * g_dbus_error_strip_remote_error() has been used on @error.
70 	 *
71 	 * Params:
72 	 *     error = a #GError
73 	 *
74 	 * Return: an allocated string or %NULL if the D-Bus error name
75 	 *     could not be found. Free with g_free().
76 	 *
77 	 * Since: 2.26
78 	 */
79 	public static string getRemoteError(ErrorG error)
80 	{
81 		return Str.toString(g_dbus_error_get_remote_error((error is null) ? null : error.getErrorGStruct()));
82 	}
83 
84 	/**
85 	 * Checks if @error represents an error received via D-Bus from a remote peer. If so,
86 	 * use g_dbus_error_get_remote_error() to get the name of the error.
87 	 *
88 	 * Params:
89 	 *     error = A #GError.
90 	 *
91 	 * Return: %TRUE if @error represents an error from a remote peer,
92 	 *     %FALSE otherwise.
93 	 *
94 	 * Since: 2.26
95 	 */
96 	public static bool isRemoteError(ErrorG error)
97 	{
98 		return g_dbus_error_is_remote_error((error is null) ? null : error.getErrorGStruct()) != 0;
99 	}
100 
101 	/**
102 	 * Creates a #GError based on the contents of @dbus_error_name and
103 	 * @dbus_error_message.
104 	 *
105 	 * Errors registered with g_dbus_error_register_error() will be looked
106 	 * up using @dbus_error_name and if a match is found, the error domain
107 	 * and code is used. Applications can use g_dbus_error_get_remote_error()
108 	 * to recover @dbus_error_name.
109 	 *
110 	 * If a match against a registered error is not found and the D-Bus
111 	 * error name is in a form as returned by g_dbus_error_encode_gerror()
112 	 * the error domain and code encoded in the name is used to
113 	 * create the #GError. Also, @dbus_error_name is added to the error message
114 	 * such that it can be recovered with g_dbus_error_get_remote_error().
115 	 *
116 	 * Otherwise, a #GError with the error code %G_IO_ERROR_DBUS_ERROR
117 	 * in the #G_IO_ERROR error domain is returned. Also, @dbus_error_name is
118 	 * added to the error message such that it can be recovered with
119 	 * g_dbus_error_get_remote_error().
120 	 *
121 	 * In all three cases, @dbus_error_name can always be recovered from the
122 	 * returned #GError using the g_dbus_error_get_remote_error() function
123 	 * (unless g_dbus_error_strip_remote_error() hasn't been used on the returned error).
124 	 *
125 	 * This function is typically only used in object mappings to prepare
126 	 * #GError instances for applications. Regular applications should not use
127 	 * it.
128 	 *
129 	 * Params:
130 	 *     dbusErrorName = D-Bus error name.
131 	 *     dbusErrorMessage = D-Bus error message.
132 	 *
133 	 * Return: An allocated #GError. Free with g_error_free().
134 	 *
135 	 * Since: 2.26
136 	 */
137 	public static ErrorG newForDbusError(string dbusErrorName, string dbusErrorMessage)
138 	{
139 		auto p = g_dbus_error_new_for_dbus_error(Str.toStringz(dbusErrorName), Str.toStringz(dbusErrorMessage));
140 		
141 		if(p is null)
142 		{
143 			return null;
144 		}
145 		
146 		return new ErrorG(cast(GError*) p);
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 }