用于激活与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)


如果有人可以提供任何有关此问题可能出问题的指示,我将不胜感激。

最佳答案

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

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


在这种情况下,“ o”告诉您此参数类型是什么。这些类型在DBus specification中指定,但是出于我们的目的,我们只需要知道'o'表示此参数是对象路径即可。这将对应于dbus-java中的Path类型(如果使用的是2.7绑定)或DBusPath如果使用的是hypfvieh的更新的3.2绑定。

当前类型是:

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


但是考虑到“ o”的实际含义,这可能应该是:

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




更好的解决方案是对dbus-java(hypfvieh的版本)使用CreateInterface程序来采用introspection XML并自动为您创建此类。

10-01 04:56