dbus 接口 xml 文件的用途是什么?

Joh*_*ith 0 dbus configuration-files

我正在阅读D-Bus API 设计指南

公共API的接口文件应安装到$(datadir)/dbus-1/interfaces,以便其他服务可以加载它们。

好的...为了了解这些接口文件的工作原理,我打开该文件/usr/share/dbus-1/interfaces/org.gnome.Shell.Screenshot.xml(我使用的是 Ubuntu 20.04)

<node>
  <interface name="org.gnome.Shell.Screenshot">
  ...
    <method name="PickColor">
      <arg type="a{sv}" direction="out" name="result"/>
    </method>
Run Code Online (Sandbox Code Playgroud)

好吧,我看到了接口名称,我看到了方法名称,但这还不够。如果我想使用调用这个方法dbus-send

$ dbus-send --print-reply --dest=<service.name> </path/to/object> org.gnome.Shell.Screenshot.PickColor
Run Code Online (Sandbox Code Playgroud)

我需要<service.name><path/to/object>,该xml文件没有提供。

问题是:如果该文件没有提供有关服务接口的完整信息,那么该文件的用途是什么?它是否被dbus-daemon其他程序使用?某些东西真的需要这样的文件吗?我是否应该得出这样的结论:未提供 中对象路径的 xml 文件是不完整的?此类文件是否还应该提及服务已知名称(org.gnome.Shell.Screenshot在本例中)?

ukB*_*Baz 5

org.freedesktop.DBus.Introspectable接口有一种方法:

\n
      org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)\n    \n
Run Code Online (Sandbox Code Playgroud)\n

对象实例可以实现Introspect返回对象的 XML 描述。内省格式记录在:\n https://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format

\n

busctl在命令行上使用,我可以list用来获取所有服务、tree所有对象,然后intropspect查找 API。使用这三个命令我可以发现系统上的 D-Bus 服务

\n
$ busctl list\n$ busctl tree <service>\n$ busctl introspect <service> <object>\n
Run Code Online (Sandbox Code Playgroud)\n

您在问题中提到的服务位于会话/用户总线上,因此它将是:

\n
      org.freedesktop.DBus.Introspectable.Introspect (out STRING xml_data)\n    \n
Run Code Online (Sandbox Code Playgroud)\n

为了完整起见,运行与您相同的命令:

\n
$ busctl --user call org.gnome.Shell.Screenshot /org/gnome/Shell/Screenshot org.gnome.Shell.Screenshot PickColor\na{sv} 1 "color" (ddd) 1 1 1\n
Run Code Online (Sandbox Code Playgroud)\n