Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

c - How to figure out which D-Bus binding to use

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...