DBus interface properties

Alex picture Alex · Jun 3, 2009 · Viewed 10.5k times · Source

How do I get the list of available DBus interface properties?

I am writing a script that would be tracking specific type of usb devices connections. A way to distinguish the connections to be tracked from all usb connections I guess is to check the properties of signals' interfaces DBus is sending on a usb connection. I'd like to get the list of all such properties to chose the relevant.

My code is:

    import sys
    import dbus
    from dbus.mainloop.glib import DBusGMainLoop
    import gobject

    def deviceAdded(udi):
        device = bus.get_object("org.freedesktop.Hal", udi)
        device_if = dbus.Interface(device, 'org.freedesktop.Hal.Device')
        if device_if.GetPropertyString('info.subsystem') == 'usb_device':
            #
            # Properties can be accesed like this:
            # vendor_id = device_if.GetPropertyInteger('usb_device.vendor_id')
            # 
            # how to get the list of all properties?
            #
            # do something

    def deviceRemoved(udi):
        # do something
        pass

    if __name__ == "__main__":
    DBusGMainLoop(set_as_default=True)
    bus = dbus.SystemBus()

    bus.add_signal_receiver( 
        deviceAdded,
        'DeviceAdded',
        'org.freedesktop.Hal.Manager',
        'org.freedesktop.Hal',
        '/org/freedesktop/Hal/Manager')

    bus.add_signal_receiver( 
        deviceRemoved,
        'DeviceRemoved',
        'org.freedesktop.Hal.Manager',
        'org.freedesktop.Hal',
        '/org/freedesktop/Hal/Manager')

    loop = gobject.MainLoop()

    try:
        loop.run()
    except KeyboardInterrupt:
        print "usb-device-tracker: keyboad interrupt received, shutting down"
        loop.quit()
        sys.exit(0)

Answer

daf picture daf · Jan 3, 2010

In general, you can use the GetAll method on the org.freedesktop.DBus.Properties interface.