exposing dbus error names on the glib client side
Colin Walters
walters at verbum.org
Fri Jun 24 14:37:12 PDT 2005
On Fri, 2005-06-24 at 17:20 -0400, Havoc Pennington wrote:
> Another option maybe is to just expose DBusError - since we're adding
> all dbus-specific methods on GError anyhow...
Well, that means that methods which take their own GError will have to
do the transformation from DBusError to GError for the case where they
simply want to propagate errors up, which is kind of tedious. For
example, with your suggestion, code would look like:
static gboolean
nm_dostuff_to_device (const char *device, GError **error)
{
DBusError derr;
char *contents;
dbus_error_init (&derr);
if (!dbus_g_proxy_call (proxy, "LockDevice", &derr, G_TYPE_STRING, "eth1", G_TYPE_INVALID, G_TYPE_INVALID)) {
dbus_set_g_error (error, derr);
return FALSE;
}
if (!g_file_get_contents ("/etc/nm/device/config", &contents, &error))
return FALSE;
if (!dbus_g_proxy_call (proxy, "Frobnicate", &derr, G_TYPE_STRING, "eth1", G_TYPE_STRING, contents, G_TYPE_INVALID, G_TYPE_INVALID)) {
dbus_set_g_error (error, derr);
g_free (contents);
return FALSE;
}
g_free (contents);
return TRUE;
}
It seems nicer to have:
static gboolean
nm_dostuff_to_device (const char *device, GError **error)
{
if (!dbus_g_proxy_call (proxy, "LockDevice", error, G_TYPE_STRING, "eth1", G_TYPE_INVALID, G_TYPE_INVALID)) {
return FALSE;
}
if (!g_file_get_contents ("/etc/nm/device/config", &contents, &error))
return FALSE;
if (!dbus_g_proxy_call (proxy, "Frobnicate", error, G_TYPE_STRING, "eth1", G_TYPE_INVALID, G_TYPE_INVALID)) {
g_free (contents);
return FALSE;
}
g_free (contents);
return TRUE;
}
Right? In this case the caller doesn't really care about the specific
error; they just want to know that they couldn't frobnicate the device.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/dbus/attachments/20050624/19b3d3c4/attachment.pgp
More information about the dbus
mailing list