DBus总线-X11、Wayland等桌面环境下进程间IPC通信机制
DBus总线接口在shell下怎么查看 (以查看网口的网关为例)
1. 首先用ListActivatableNames查看系统里有哪些有用的总线连接:
$ dbus-send –system –print-reply –dest=org.freedesktop.DBus / org.freedesktop.DBus.ListActivatableNames
$ dbus-send –session –print-reply –dest=org.freedesktop.DBus / org.freedesktop.DBus.ListActivatableNames
输出里面有一个:
string “org.freedesktop.NetworkManager”
2. 然后用ListNames查看系统有哪些连接名字(如果这步没有显示而上步有显示,则该连接名仍然不可用):
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.DBus / org.freedesktop.DBus.ListNames
输出里面有一个:
string “org.freedesktop.NetworkManager”
3. 用Introspect从根目录路径开始查该连接名字下有哪些节点:
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager / org.freedesktop.DBus.Introspectable.Introspect
输出:
<node>
<node name=”com”/>
<node name=”org”/>
</node>
4. 从根目录开始一步一步往下查看子节点(这里以org节点往下):
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org org.freedesktop.DBus.Introspectable.Introspect
输出:
<node>
<node name=”freedesktop”/>
</node>
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.Introspectable.Introspect
输出:
<node>
<node name=”NetworkManager”/>
</node>
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.DBus.Introspectable.Introspect
输出其中一段:
<interface name=”org.freedesktop.NetworkManager“>
<method name=”GetDeviceByIpIface“> 对应下面5.1的功能调用的接口和方法
<arg name=”iface” type=”s” direction=”in”/>
<arg name=”device” type=”o” direction=”out”/>
</method>
<node name=”IP4Config”/>
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/IP4Config org.freedesktop.DBus.Introspectable.Introspect
输出:
<node>
<node name=”2″/>
<node name=”3″/>
<node name=”4″/>
<node name=”5″/>
<node name=”6″/>
<node name=”7″/>
<node name=”8″/>
</node>
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/IP4Config/4 org.freedesktop.DBus.Introspectable.Introspect
输出其中一段:
<interface name=”org.freedesktop.DBus.Properties“>
<method name=”Get“> 对应下面5.2的功能调用的接口和方法
<arg name=”interface” direction=”in” type=”s”/>
<arg name=”propname” direction=”in” type=”s”/>
<arg name=”value” direction=”out” type=”v”/>
</method>
<interface name=”org.freedesktop.NetworkManager.IP4Config“>
<property name=”Gateway” type=”s” access=”read”/> 对应下面5.2的功能调用的两个参数
5.1 根据接口和方法调用dbus功能(第4步中查到的接口方法):
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.GetDeviceByIpIface string:eth0
输出:
method return sender=:1.2 -> dest=:1.1850 reply_serial=2
object path “/org/freedesktop/NetworkManager/Devices/2”
5.2 根据接口和属性调用dbus功能(第4步中查到的接口方法):
$ dbus-send –system –type=method_call –print-reply –dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/IP4Config/4 org.freedesktop.DBus.Properties.Get string:org.freedesktop.NetworkManager.IP4Config string:Gateway
输出:
method return sender=:1.2 -> dest=:1.1864 reply_serial=2
variant string “172.18.1.1”