javadbusintrospectionnetworkmanager

dbus NetworkManager: supply "/" as DBusInterface parameter in Java


The documentation for activating a wireless connection with ActivateConnection says that you can supply "/" as the second and third parameters to get dbus to choose sensible defaults for you.

As the bindings for the function in Java are of type DBusInterface, how do you do that? You can hardly write (DBusInterface)"/", can you?

If anyone can answer the above, I will very grateful. For anyone with a bit more time or knowledge of this area, the real problem I'm trying to solve is that my call to ActivateConnection crashes out. Here is my code leading up to the crash. It references this interface.

            var nmIface = (NetworkManagerIface) instance.getRemoteObject(NetworkManagerIface._NM_IFACE, NetworkManagerIface._NM_PATH, NetworkManagerIface.class);
            System.out.println("Connect:" + connMatch.getObjectPath());
            System.out.println("Adaptor:" + adaptor.getObjectPath());
            System.out.println("AccessP:" + accessMatch.getObjectPath());
            for (DBusPath devName : nmIface.GetDevices()) {
                System.out.println("   Device:" + devName.getPath());
            }
            nmIface.ActivateConnection(connMatch, adaptor, accessMatch);

and produces this output (colouring inserted by SO):

Connect:/org/freedesktop/NetworkManager/Settings/4
Adaptor:/org/freedesktop/NetworkManager/Devices/3
AccessP:/org/freedesktop/NetworkManager/AccessPoint/248
   Device:/org/freedesktop/NetworkManager/Devices/1
   Device:/org/freedesktop/NetworkManager/Devices/2
   Device:/org/freedesktop/NetworkManager/Devices/3
Exception in thread "JavaFX Application Thread" org.freedesktop.dbus.exceptions.DBusExecutionException: Failed to construct D-Bus type: Not an object exported or imported by this connection at org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(RemoteInvocationHandler.java:102)
        at org.freedesktop.dbus.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:228)
        at com.sun.proxy.$Proxy23.ActivateConnection(Unknown Source)
        at com.mycompany.Wifi.activateConnection(Wifi.java:322)

If anyone can give any pointers about what might be wrong with that, I will be even more grateful.


Solution

  • Your bindings are almost certainly wrong. If we check the documentation for Activate Connection, we see that it has the following parameters:

    ActivateConnection (IN  o connection,
                        IN  o device,
                        IN  o specific_object,
                        OUT o active_connection);
    

    The 'o' in this case is telling you what this parameter type is. The types are specified in the DBus specification, but for our purposes all that we have to know is that 'o' means that this parameter is an Object Path. This will correspond to the type Path in dbus-java(if you are using the 2.7 bindings) or DBusPath if you're using hypfvieh's updated 3.2 bindings.

    The current type is:

    public DBusInterface ActivateConnection(DBusInterface connection, DBusInterface device, DBusInterface specific_object);
    

    But given what the 'o' actually means, this should probably be:

    public DBusInterface ActivateConnection(DBusPath connection, DBusPath device, DBusPath specific_object);
    

    A better solution would be to to use the CreateInterface program for dbus-java(hypfvieh's version) to take the introspection XML and create this class for you automatically.