Dbus instrospection incomplete for UDisks2?

Tags: ,



I am using the java dbus interface. As it is not complete, we have to use the dbus introspection tool to generate xml files that will be converted into Java classes.

I want to be able to receive signals when a drive is inserted or removed from the system.

For that, I found that the signals InterfacesAdded and InterfacesRemoved are what I am searching for.

I have used this command to generate the xml introspection file :

gdbus introspect --system --dest org.freedesktop.UDisks2 --object-path /org/freedesktop/UDisks2 --xml

It have generated a file, that I have converted with this command :

CreateInterface --system --no-ignore-builtin --create-files org.freedesktop.UDisks2.xml

I am now able to receive the InterfacesAdded signal, but not the InterfacesRemoved one.

There seems to be a problem, this signal want’s to give some information that are in the block_devices node. But for this node the xml file is empty :

<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
                      "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!-- GDBus 2.66.2 -->
<node>
  <interface name="org.freedesktop.DBus.Properties">
    ... snip ...
  <interface name="org.freedesktop.DBus.ObjectManager">
    <method name="GetManagedObjects">
      <arg type="a{oa{sa{sv}}}" name="object_paths_interfaces_and_properties" direction="out"/>
    </method>
    <signal name="InterfacesAdded">
      <arg type="o" name="object_path"/>
      <arg type="a{sa{sv}}" name="interfaces_and_properties"/>
    </signal>
    <signal name="InterfacesRemoved">
      <arg type="o" name="object_path"/>
      <arg type="as" name="interfaces"/>
    </signal>
  </interface>
  <node name="Manager"/>
  <node name="drives"/>
  <node name="block_devices"/>
</node>

And as such the java code don’t know how to create the signal.

What could I do for that ?

Answer

I think the core misunderstanding is this: You generate interface files for object /org/freedesktop/UDisks2 but then in your code you use those interface files to create proxies for interfaces implemented by /org/freedesktop/UDisks2/block_devices/sdb. These objects implement different interfaces.

You will need interface definitions for all interfaces you create proxies for. I can’t give the exact commands to do that with introspection but you can use the same method to generate them as long as you find a suitable object. As an example:

gdbus introspect --system --xml 
    --dest org.freedesktop.UDisks2 
    --object-path /org/freedesktop/UDisks2/block_devices/nvme0n1

produces the interface definition for org.freedesktop.UDisks2.Block and org.freedesktop.UDisks2.PartitionTable on my machine.

That said, UDisks2 does seem to have all of the org.freedesktop.UDisks2.* interfaces available in source code: org.freedesktop.UDisks2.xml.



Source: stackoverflow