dbus NetworkManager:在 Java 中提供“/”作为 DBusInterface 参数

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

用于激活与 ActivateConnection 的无线连接的 documentation 说您可以提供 "/" 作为第二个和第三个参数,让 dbus 为您选择合理的默认值。

由于 Java 中函数的绑定是 DBusInterface 类型,你是怎么做到的?你很难写(DBusInterface)"/",可以吗?

如果有人能回答以上问题,我将不胜感激。对于在该领域有更多时间或知识的任何人,我试图解决的 真正的 问题是我对 ActivateConnection 的调用崩溃了。这是导致崩溃的代码。它引用 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);

并生成此输出(由 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)

如果有人能指出 that 可能有什么问题,我将更加感激。

您的绑定几乎肯定是错误的。如果我们查看 Activate Connection 的文档,我们会发现它具有以下参数:

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

本例中的'o'告诉你这个参数类型是什么。如果您使用的是 hypfvieh 更新的 3.2 绑定,则类型在 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 中指定。

当前类型是:

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

但鉴于 'o' 的实际含义,这可能应该是:

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

更好的解决方案是使用 CreateInterface program for dbus-java(hypfvieh's version) to take the introspection XML 并自动为您创建此 class。