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