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