documentation使用 ActivateConnection
激活无线连接表示您可以提供 "/"
作为第二个和第三个参数,让 dbus 为您选择合理的默认值。
由于 Java 中函数的绑定(bind)是 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)
如果有人可以指出可能出现的问题,我将更加感激。
最佳答案
你的绑定(bind)几乎肯定是错误的。如果我们检查 Activate Connection 的文档,我们看到它有以下参数:
ActivateConnection (IN o connection,
IN o device,
IN o specific_object,
OUT o active_connection);
本例中的“o”告诉您该参数类型是什么。这些类型在 DBus specification 中指定。 ,但就我们的目的而言,我们必须知道“o”表示该参数是对象路径。这将对应于类型 Path
在 dbus-java 中(如果您使用的是 2.7 绑定(bind))或 DBusPath
如果您使用 hypfvieh 更新的 3.2 绑定(bind)。
当前类型是:
public DBusInterface ActivateConnection(DBusInterface connection, DBusInterface device, DBusInterface specific_object);
但是考虑到“o”的实际含义,这可能应该是:
public DBusInterface ActivateConnection(DBusPath connection, DBusPath device, DBusPath specific_object);
<小时/>
更好的解决方案是使用 CreateInterface
dbus-java(hypfvieh 版本)的程序取introspection XML并自动为您创建此类。
关于java - dbus 网络管理器 : supply "/" as DBusInterface parameter in Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59061685/