Gnome Shell JS - 监听任意路径接口上的 DBus 信号

Gnome Shell JS - 监听任意路径接口上的 DBus 信号

我正在尝试编写一个监听 DBus 信号的扩展,但我不知道路径。实际上,有多个路径(对于实现该接口的每个应用程序都是唯一的)。似乎没有办法提前确定路径(即在应用程序启动时),所以我只能监听发送某个 DBus 命令时发出的信号。我真正寻找的是 GJS 等效于 Python 解决方案问题。不幸的是,各种 DBus 代理不允许nullundefined作为路径的值,就像 Python 库一样。我也尝试使用imports.dbus.session.watch_signal收到所有发射的信号,但无法让我将发送者与特定信号联系起来。

答案1

我不熟悉 GJS(绝对值得研究)但是,如果有 GJS 命令行界面,那么dbus-monitor可以通过任何消息属性跟踪 d-bus。

引用man dbus-monitor

EXAMPLE
       Here  is an example of using dbus-monitor to watch for the gnome typing
       monitor to say things

         dbus-monitor "type='signal',                          \
                       sender='org.gnome.TypingMonitor',       \
                       interface='org.gnome.TypingMonitor'"

   In order to get dbus-monitor to see the messages you are interested in,
   you should specify a set of watch expressions as you would expect to be
   passed to the dbus_bus_add_match function.

并引用D-Bus:消息总线 API:dbus_bus_add_match 函数

   Possible keys you can match on are type, sender, interface, member,
   path, destination and numbered keys to match message args
   (keys are 'arg0', 'arg1', etc.). Omitting a key from the rule indicates
   a wildcard match. For instance omitting the member from a match rule but
   adding a sender would let all messages from that sender through regardless
   of the member.

请注意,发送者在以下输出中被识别

输出过多的问题

         dbus-monitor "type='signal'"

例如

...
signal sender=:1.47 -> dest=(null destination) serial=1679 path=/org/ayatana/bamf/application311805604; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.ayatana.bamf.view"
   array [
      dict entry(
         string "Active"
         variant             boolean true
      )
   ]
   array [
   ]
...
signal sender=:1.51 -> dest=com.canonical.Unity.Panel.Service serial=1674 path=/com/canonical/Unity/Panel/Service; interface=com.canonical.Unity.Panel.Service; member=ReSync
   string "libappmenu.so"
...
signal sender=:1.51 -> dest=com.canonical.Unity.Panel.Service serial=1681 path=/com/canonical/Unity/Panel/Service; interface=com.canonical.Unity.Panel.Service; member=ReSync
   string "libdatetime.so"
...

可以通过以下方式修剪,或使用以下方式组合修剪:

  • dbus-monitor --profile "type='signal'"
  • dbus-monitor "type='signal'" | grep '...some pattern...'
  • dbus-monitor "type='signal', interface='...'" 或者用另一个键代替接口

ETC。

signal最后一种变体可能最适合在 d-bus 上找到"that implements the interface"

书签:
Gnome Shell JS - 监听任意路径接口上的 DBus 信号

相关内容