Logo Search packages:      
Sourcecode: hal version File versions

char ** hal_manager_find_device_string_match ( LibHalContext ctx,
const char *  key,
const char *  value,
int *  num_devices 

Find a device in the GDL where a single string property matches a given value.

ctx The context for the connection to hald
key Name of the property
value Value to match
num_devices Pointer to store number of devices
UDI of devices; free with hal_free_string_array()

Definition at line 2092 of file libhal.c.

References LibHalContext_s::connection.

Referenced by hal_drive_from_device_file(), and hal_volume_from_device_file().

      int i;
      DBusError error;
      DBusMessage *message;
      DBusMessage *reply;
      DBusMessageIter iter;
      char **device_names;
      char **hal_device_names;

      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 NULL;

      dbus_message_iter_init (message, &iter);
      dbus_message_iter_append_string (&iter, key);
      dbus_message_iter_append_string (&iter, value);

      dbus_error_init (&error);
      reply = dbus_connection_send_with_reply_and_block (ctx->connection,
                                             message, -1,
      if (dbus_error_is_set (&error)) {
            fprintf (stderr, "%s %d : Error sending msg: %s\n",
                   __FILE__, __LINE__, error.message);
            dbus_message_unref (message);
            return NULL;
      if (reply == NULL) {
            dbus_message_unref (message);
            return NULL;
      /* now analyse reply */
      dbus_message_iter_init (reply, &iter);
      if (!dbus_message_iter_get_string_array (&iter,
                                     num_devices)) {
            fprintf (stderr, "%s %d : wrong reply from hald\n",
                   __FILE__, __LINE__);
            return NULL;

      dbus_message_unref (message);
      dbus_message_unref (reply);

      /* Have to convert from dbus string array to hal string array 
       * since we can't poke at the dbus string array for the reason
       * that d-bus use their own memory allocation scheme
      hal_device_names = malloc (sizeof (char *) * ((*num_devices) + 1));
      if (hal_device_names == NULL)
            return NULL;
                 /** @todo Handle OOM better */

      for (i = 0; i < (*num_devices); i++) {
            hal_device_names[i] = strdup (device_names[i]);
            if (hal_device_names[i] == NULL)
                  return NULL;
                   /** @todo Handle OOM better */
      hal_device_names[i] = NULL;

      dbus_free_string_array (device_names);

      return hal_device_names;

Generated by  Doxygen 1.6.0   Back to index