dbus noob questions

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Aug 20 06:14:50 PDT 2015


D-Bus is a protocol, not a specific implementation, but you are asking
questions about implementations.

Possible implementations include libdbus (the reference implementation,
portable, low-level, painful to use); GDBus (a reimplementation using
GObject, portable, higher-level APIs); and sd-bus (a reimplementation as
part of systemd, easier than libdbus but equally low-level, Linux-specific).

On 20/08/15 12:08, Zap Foster wrote:
> 1.  can the using application specify its own allocators?
> For example, the app is written in C.  It has taken over the malloc/free
> mechanism, and uses a slab allocator.

libdbus: not as such, but if you override malloc() and free() by
interposing your own symbols, libdbus will call those (for instance,
LD_PRELOAD-based memory allocation debuggers like Electric Fence work
like you'd expect).

GDBus: same answer. GLib used to have support for making g_malloc() not
be the same thing as malloc(), but it was recently removed, because it
was never tested in practice (and therefore it probably didn't work),
and the ability to interpose malloc() and free() makes it more or less
useless.

sd-bus: I don't know, but probably the same answer as libdbus.

> Each allocation is actually a
> member of a series of page slabs, and allocations come from pools that
> are contained in slabs.

FYI, libdbus has its own memory-pool implementation layered over
malloc/free.

> QUESTION:  can we use dbus without
> incuring thread costs, and can it be used in a poll-model?

libdbus: The usual way to use it is in an asynchronous single-threaded
main loop (event loop, dispatcher), using epoll, poll() or select().
Some API calls will block, but most of those have a non-blocking
equivalent. A few things (notably, initialization) do not have a
non-blocking equivalent.

GDBus: The usual way to use GDBus is in an asynchronous single-threaded
main loop (event loop, dispatcher), using epoll, poll() or select(). All
blocking API calls have a non-blocking equivalent, I think. However, it
uses a worker thread to do the actual work of managing the D-Bus connection.

sd-bus: probably the same as libdbus.

> 3.  With other (and current) IPC forms, we have an "IDL" where we define
> a message structure, run a code-generator over it, and use the fruit of
> the output (which are message datastructures). QUESTION:  does dbus have
> a mechanism like this for defining message payload structure?

D-Bus has a type system for message data structures. The "introspection"
format (XML) is the de facto IDL for them.

libdbus does not have code-generation tools. GDBus does, and they take
the IDL as input. sd-bus probably does not.

-- 
Simon McVittie
Collabora Ltd. <http://www.collabora.com/>



More information about the dbus mailing list