Getting device added events through dbus

Rob Taylor rob.taylor at codethink.co.uk
Thu Dec 6 06:07:33 PST 2007


shankar grep wrote:
> Hi,
> 
> I compiled hal.0.5.10 on my system...
> I can call methods registered on the Dbus at
> org.freedesktop.Hal.Manager   --- like GetAllDevices. And get the list
> of all device connected to the system at that time.
> But I am not able to get the signal  DeviceAdded  through DBus....
> 
> Below is the code i use to listen to the signal
> 
> 
> con=dbus_g_bus_get(DBUS_BUS_SYSTEM,NULL);
>      proxy=dbus_g_proxy_new_for_name(con,"
> org.freedesktop.Hal","/org/freedesktop/Hal/Manager","org.freedesktop.Hal.Manager");
> 
>      printf("Probably got a connectrion to the correct interface...\n");
>      loop=g_main_loop_new(NULL,FALSE);
>      m1=g_cclosure_user_marshal_VOID__STRING;
>      m2=g_cclosure_user_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);
> 
>      printf("Calling a remote method...\n");
>      err=NULL;
>     
> dbus_g_proxy_call(proxy,"GetAllDevices",&err,G_TYPE_INVALID,G_TYPE_STRV,&list,G_TYPE_INVALID);
> 
> 
> 
> 
> I am not able to determine what the problem...  Do i have to edit any
> policy files for this?? Or my code is wrong??
> {I am trying to get DeviceAdded signal whner i connect my flash stick}
> Any suggestion on this is appreciated....
> Thanks in advance .

I think your dbus_g_proxy_add_signal is wrong, should have
G_TYPE_STRING, G_TYPE_INVALID. also the marshaller registering is wrong,
should be G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID.
http://wiki.bluez.org/wiki/HOWTO/DiscoveringDevices has a nice example
of some simple signal usage with dbus-glib.


Though *really*, I'd recommend using libhal rather than fighting with
dbus-glib..

Thanks,
Rob

> shankar
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> hal mailing list
> hal at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/hal


-- 
Rob Taylor, Codethink Ltd. -  http://codethink.co.uk


More information about the hal mailing list