How to figure out which D-Bus binding to use

妖精的绣舞 提交于 2019-11-27 07:37:37

问题


I'm trying to detect across all linux if screensaver is running or if screen is locked.

People recommended dbus. So now i'm trying to auto detect with x11 or C APIs or something what kind of dbus is available, then use that. Like qdubs, gdbus, etc?

Thanks


回答1:


As you’ve noticed, there are various D-Bus bindings available. As Ignacio says, you can use any of them, since they all speak the same protocol — but some bindings are more appropriate to some situations than others.

Recommended high-level bindings:

  • GDBus is a high level binding based around GLib/GObject. It’s appropriate to use if you’re writing a service or application based around GNOME technologies or GLib. It’s written in C, but bindings are available (at various levels of functionality) for other languages using gobject-introspection.
  • QtDBus is a high level binding based around Qt. It’s appropriate to use if you’re writing a service or application based around Qt. It’s written in C++.

Recommended low-level bindings:

  • sd-bus is a lower level binding with very few dependencies. It’s appropriate if you’re writing a system service or system application and are not using GLib or Qt. It’s written in C.

Not recommended bindings:

  • libdbus is a lower level binding which comes with the official D-Bus implementation. It’s old, and the best practice in designing D-Bus APIs has improved since it was written. It is recommended you do not use libdbus. As the documentation says: “If you use this low-level API directly, you're signing up for some pain.”. It’s awkward to use. It’s written in C.
  • dbus-glib is a high level binding which was affiliated with the official D-Bus implementation. Like libdbus, it’s old, and the best practice has moved on since then. It is recommended you do not use dbus-glib, and use GDBus instead. It’s awkward ot use. It’s written in C.

There are various bindings for other languages available, but I am not sure of their relative merits (if someone wants to edit this answer to cover those, that would be great).




回答2:


You don't need to detect what bindings for D-Bus are in use. Since they all speak the same way to the same thing, you only need to use your binding to talk to the message bus and interact with any other D-Bus client.



来源:https://stackoverflow.com/questions/27751358/how-to-figure-out-which-d-bus-binding-to-use

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!