Logo Search packages:      
Sourcecode: hal version File versions

dbus_bool_t hal_device_lock ( LibHalContext ctx,
const char *  udi,
const char *  reason_to_lock,
char **  reason_why_locked 

Take an advisory lock on the device.

ctx The context for the connection to hald
udi Unique Device Id
reason_to_lock A user-presentable reason why the device is locked.l
reason_why_locked A pointer to store the reason why the device cannot be locked on failure, or NULL
TRUE if the lock was obtained, FALSE otherwise

Definition at line 1465 of file libhal.c.

References LibHalContext_s::connection.

      DBusMessage *message;
      DBusMessageIter iter;
      DBusError error;
      DBusMessage *reply;

      if (reason_why_locked != NULL)
            *reason_why_locked = NULL;

      message = dbus_message_new_method_call ("org.freedesktop.Hal",

      if (message == NULL) {
            fprintf (stderr,
                   "%s %d : Couldn't allocate D-BUS message\n",
                   __FILE__, __LINE__);
            return FALSE;

      dbus_message_iter_init (message, &iter);
      dbus_message_iter_append_string (&iter, reason_to_lock);

      dbus_error_init (&error);
      reply = dbus_connection_send_with_reply_and_block (ctx->connection,
                                             message, -1,

      if (dbus_error_is_set (&error)) {
            if (strcmp (error.name,
                      "org.freedesktop.Hal.DeviceAlreadyLocked") == 0) {
                  if (reason_why_locked != NULL) {
                        *reason_why_locked =
                              dbus_malloc0 (strlen (error.message) + 1);
                        strcpy (*reason_why_locked, error.message);
            } else {
                  fprintf (stderr, "%s %d: %s raised\n\"%s\"\n\n",
                         __FILE__, __LINE__, error.name,

            dbus_message_unref (message);
            return FALSE;

      dbus_message_unref (message);

      if (reply == NULL)
            return FALSE;

      dbus_message_unref (reply);

      return TRUE;

Generated by  Doxygen 1.6.0   Back to index