Logo Search packages:      
Sourcecode: hal version File versions

LibHalPropertySet * hal_device_get_all_properties ( LibHalContext ctx,
const char *  udi 
)

Retrieve all the properties on a device.

Parameters:
ctx The context for the connection to hald
udi Unique id of device
Returns:
An object represent all properties. Must be freed with hal_free_property_set

Definition at line 164 of file libhal.c.

References LibHalProperty_s::bool_value, LibHalContext_s::connection, LibHalProperty_s::double_value, LibHalProperty_s::int_value, LibHalProperty_s::key, LibHalProperty_s::next, LibHalPropertySet_s::num_properties, LibHalPropertySet_s::properties_head, LibHalProperty_s::str_value, LibHalProperty_s::type, and LibHalProperty_s::uint64_value.

Referenced by dump_devices(), hal_device_print(), hal_drive_from_udi(), and hal_volume_from_udi().

{
      DBusError error;
      DBusMessage *message;
      DBusMessage *reply;
      DBusMessageIter iter;
      DBusMessageIter dict_iter;
      LibHalPropertySet *result;
      LibHalProperty **pn;

      message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
                                    "org.freedesktop.Hal.Device",
                                    "GetAllProperties");
      if (message == NULL) {
            fprintf (stderr,
                   "%s %d : Couldn't allocate D-BUS message\n",
                   __FILE__, __LINE__);
            return NULL;
      }

      dbus_error_init (&error);
      reply = dbus_connection_send_with_reply_and_block (ctx->connection,
                                             message, -1,
                                             &error);
      if (dbus_error_is_set (&error)) {
            fprintf (stderr, "%s %d: %s raised\n\"%s\"\n\n", __FILE__,
                   __LINE__, error.name, error.message);
            dbus_message_unref (message);
            return NULL;
      }

      if (reply == NULL) {
            dbus_message_unref (message);
            return NULL;
      }

      dbus_message_iter_init (reply, &iter);

      result = malloc (sizeof (LibHalPropertySet));
      if (result == NULL) {
            fprintf (stderr, "%s %d : error allocating memory\n",
                   __FILE__, __LINE__);
            dbus_message_unref (message);
            dbus_message_unref (reply);
            return NULL;
      }

/*
    result->properties = malloc(sizeof(LibHalProperty)*result->num_properties);
    if( result->properties==NULL )
    {
    /// @todo  cleanup
      return NULL;
    }
*/

      pn = &result->properties_head;
      result->num_properties = 0;

      dbus_message_iter_init_dict_iterator (&iter, &dict_iter);

      do {
            char *dbus_str;
            LibHalProperty *p;

            p = malloc (sizeof (LibHalProperty));
            if (p == NULL) {
                  fprintf (stderr,
                         "%s %d : error allocating memory\n",
                         __FILE__, __LINE__);
                  /** @todo FIXME cleanup */
                  return NULL;
            }

            *pn = p;
            pn = &p->next;
            p->next = NULL;
            result->num_properties++;

            dbus_str = dbus_message_iter_get_dict_key (&dict_iter);
            p->key =
                (char *) ((dbus_str != NULL) ? strdup (dbus_str) :
                        NULL);
            if (p->key == NULL) {
                  fprintf (stderr,
                         "%s %d : error allocating memory\n",
                         __FILE__, __LINE__);
                  /** @todo FIXME cleanup */
                  return NULL;
            }
            dbus_free (dbus_str);

            p->type = dbus_message_iter_get_arg_type (&dict_iter);

            switch (p->type) {
            case DBUS_TYPE_STRING:
                  dbus_str =
                      dbus_message_iter_get_string (&dict_iter);
                  p->str_value =
                      (char *) ((dbus_str != NULL) ?
                              strdup (dbus_str) : NULL);
                  if (p->str_value == NULL) {
                        fprintf (stderr,
                               "%s %d : error allocating memory\n",
                               __FILE__, __LINE__);
                        /** @todo FIXME cleanup */
                        return NULL;
                  }
                  dbus_free (dbus_str);
                  break;
            case DBUS_TYPE_INT32:
                  p->int_value =
                      dbus_message_iter_get_int32 (&dict_iter);
                  break;
            case DBUS_TYPE_UINT64:
                  p->uint64_value =
                      dbus_message_iter_get_uint64 (&dict_iter);
                  break;
            case DBUS_TYPE_DOUBLE:
                  p->double_value =
                      dbus_message_iter_get_double (&dict_iter);
                  break;
            case DBUS_TYPE_BOOLEAN:
                  p->bool_value =
                      dbus_message_iter_get_boolean (&dict_iter);
                  break;

            default:
                  /** @todo  report error */
                  break;
            }

      }
      while (dbus_message_iter_has_next (&dict_iter) &&
             dbus_message_iter_next (&dict_iter));

      dbus_message_unref (message);
      dbus_message_unref (reply);

      return result;
}


Generated by  Doxygen 1.6.0   Back to index