如何找出要使用的D-Bus绑定 [英] How to figure out which D-Bus binding to use

查看:76
本文介绍了如何找出要使用的D-Bus绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在屏幕保护程序正在运行或屏幕被锁定的情况下在所有Linux上进行检测.

人们推荐dbus.因此,现在我尝试使用x11或C API或某种可用的dbus自动检测,然后使用它.像qdubs,gdbus等?

谢谢

解决方案

您已经注意到,有各种D-Bus绑定可用.正如Ignacio所说,您可以使用它们中的任何一个,因为它们都使用相同的协议-但是某些绑定比某些绑定更适合于某些情况.

推荐的高级绑定:

  • GDBus 是基于GLib/GObject的高级绑定.如果您要基于GNOME技术或GLib编写服务或应用程序,则适合使用.它是用C语言编写的,但是可以使用gobject-introspection对其他语言进行绑定(在各种功能级别上).
  • QtDBus 是基于Qt的高级绑定.如果您要基于Qt编写服务或应用程序,则适合使用.它是用C ++编写的.

推荐的低级绑定:

  • SD总线是一个较低级别的绑定,具有很少依赖.如果您正在编写系统服务或系统应用程序,并且未使用GLib或Qt,则比较合适.它是用C语言编写的.

推荐的绑定:

  • libdbus 是官方D-Bus实现随附的较低级别绑定.它很古老,自编写以来,改进了设计D-Bus API的最佳实践.建议您不要使用libdbus.正如文档所述:如果您直接使用此低级API,则可能会有些麻烦."使用起来很尴尬.它是用C语言编写的.
  • dbus-glib 是与官方D关联的高级绑定-公交实施.像libdbus一样,它已经很老了,从那时起,最佳做法不断发展.建议您不要使用dbus-glib,而应使用GDBus.使用起来很尴尬.它是用C语言编写的.

有各种其他语言的绑定,但我不确定他们的相对优点(如果有人想编辑此答案以涵盖这些答案,那就太好了.)

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

解决方案

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).

这篇关于如何找出要使用的D-Bus绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆