Logo Search packages:      
Sourcecode: hal version File versions

char * hal_agent_new_device ( LibHalContext ctx  ) 

Create a new device object which will be hidden from applications until the CommitToGdl(), ie. hal_agent_commit_to_gdl(), method is called.

Note that the program invoking this method needs to run with super user privileges.

Parameters:
ctx The context for the connection to hald
Returns:
Tempoary device unique id or NULL if there was a problem. This string must be freed by the caller.

Definition at line 1589 of file libhal.c.

References LibHalContext_s::connection.

{
      DBusError error;
      DBusMessage *message;
      DBusMessage *reply;
      DBusMessageIter iter;
      char *value;
      char *dbus_str;

      message = dbus_message_new_method_call ("org.freedesktop.Hal",
                                    "/org/freedesktop/Hal/Manager",
                                    "org.freedesktop.Hal.AgentManager",
                                    "NewDevice");
      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 : Error sending msg: %s\n",
                   __FILE__, __LINE__, error.message);
            dbus_message_unref (message);
            return NULL;
      }
      if (reply == NULL) {
            dbus_message_unref (message);
            return NULL;
      }

      dbus_message_iter_init (reply, &iter);

      /* now analyze reply */
      if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING) {
            fprintf (stderr,
                   "%s %d : expected a string in reply to NewDevice\n",
                   __FILE__, __LINE__);
            dbus_message_unref (message);
            dbus_message_unref (reply);
            return NULL;
      }

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

      dbus_message_unref (message);
      dbus_message_unref (reply);
      return value;
}


Generated by  Doxygen 1.6.0   Back to index