GBus discussion

Havoc Pennington hp at redhat.com
Sat Aug 18 09:25:38 PDT 2007


Hi,

On 8/18/07, Fan Wu <wufan9418 at gmail.com> wrote:
> Sorry I didn't make myself clear when referring to "error message".
> What I meant was DBusError which I think include both the error
> DBusMessages and the errors set by the libdbus (reply timeout, or bad
> DBusMessage etc), and pass the DBusError to the callbacks.
>

For requesting a name, a DBusError is effectively impossible unless
there's a bug in the bus, or the connection disconnects.

For disconnect I think calling the "not owned" callback and then
calling a disconnect callback is appropriate; this should not be
treated as an error but just as a disconnect.

For a bug in the bus, I would say just printing a warning in the
library itself is fine (probably with some way for apps to override
the warning handler).

typedef void (* GBusUnexpectedErrorHandler) (const DBusError *error,
const char *context_description, void *data);

gbus_set_unexpected_error_handler(GBusUnexpectedErrorHandler handler,
void *data);

static void
default_unexpected_error_handler(const DBusError *error, const char
*context_description, void *data)
{
  _dbus_warn("%s: did not expect error %s: %s\n", context_description,
error->name, error->message);
}

So then when doing the request name (note that dbus_bus_request_name
blocks so should not be used, we'd do it async):

 old_state = OWNED, NOT_OWNED, or UNKNOWN;

 if (dbus_message_is_error(reply))
   {
      // an error is expected if we were disconnected, so don't warn
      if (dbus_connection_get_is_connected(connection))
          run_unexpected_error_handler_for_message(reply, "requesting
a bus name");
      new_state = NOT_OWNED;
   }
 else
   {
      new_state = OWNED or NOT_OWNED depending on reply;
   }

    if (new_state == OWNED && new_state != old_state)
      invoke_owned_callback()
    else if (new_state == NOT_OWNED && new_state != old_state)
      invoke_not_owned_callback();

Something like that...

Havoc


More information about the dbus mailing list