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