void device_added()
{
printf("Added \n");
g_main_loop_quit (loop);
}
void device_removed()
{
printf("Removed\n");
g_main_loop_quit (loop);
}
int
main (int argc, char **argv)
{
DBusGConnection *connection;
DBusMessage* message;
GError *error;
DBusGProxy *proxy;
char **name_list;
char **name_list_ptr;
gchar *m1;
gchar *m2;
g_type_init();
error = NULL;
connection = dbus_g_bus_get(DBUS_BUS_SYSTEM,NULL);
if (connection == NULL)
{
g_printerr ("Failed to open connection to bus: %s\n",
error->message);
g_error_free (error);
exit (1);
}
/* Create a proxy object for the "bus driver" (name "org.freedesktop.DBus") */
proxy=dbus_g_proxy_new_for_name(connection,"org.freedesktop.UDisks","/org/freedesktop/UDisks","org.freedesktop.UDisks");
if(proxy == NULL)
{
g_printerr ("Failed To Create A proxy...: %s\n", error->message);
g_error_free (error);
exit(1);
}
else
printf("Probably got a connection to the correct interface...\n");
m1=g_cclosure_marshal_VOID__STRING;
m2=g_cclosure_marshal_VOID__STRING;
dbus_g_object_register_marshaller(m1,G_TYPE_BOOLEAN,G_TYPE_STRING,G_TYPE_INVALID);
dbus_g_object_register_marshaller(m2,G_TYPE_BOOLEAN,G_TYPE_STRING,G_TYPE_INVALID);
dbus_g_proxy_add_signal(proxy,"DeviceAdded",G_TYPE_INVALID);
dbus_g_proxy_add_signal(proxy,"DeviceRemoved",G_TYPE_INVALID);
dbus_g_proxy_connect_signal(proxy,"DeviceAdded",(GCallback)device_added,NULL,NULL);
dbus_g_proxy_connect_signal(proxy,"DeviceRemoved",(GCallback)device_removed,NULL,NULL);
loop=g_main_loop_new(NULL,FALSE);
g_main_loop_run (loop);
return 0;
}
我想檢測usb事件,我使用org.freedesktop.UDisks接口的DeviceAdded和DeviceRemoved信號。但device_added或device_removed不是geting調用,任何人都可以請告訴我上面的代碼有什麼問題嗎?dbus glib綁定UDisks錯誤