Get on the D-BUS

Programs, the kernel and even your phone can keep you in touch and make the whole desktop work the way you want. Here's how D-BUS works, and how applications are using it.

The Kernel Event Layer

The Kernel Event Layer is a kernel-to-user communication mechanism that
uses a high-speed netlink socket to communicate asynchronously with
user space. This mechanism can be tied into D-BUS, allowing the kernel
to send D-BUS signals!

The Kernel Event Layer is tied to sysfs, the tree of kobjects that lives
at
/sys on modern Linux systems. Each directory in sysfs is tied to
a kobject, which is a structure in the kernel used to represent objects;
sysfs is an object hierarchy exported as a filesystem.

Each Kernel Event Layer event is modeled as though it originated from a sysfs
path. Thus, the events appear as if they emit from kobjects. The
sysfs
paths are easily translatable to D-BUS paths, making the Kernel Event
Layer
and D-BUS a natural fit.
This Kernel Event Layer was merged into the 2.6.10-rc1 kernel.

Second, the session bus provides a mechanism for IPC and remote method
invocation, possibly providing a unified system between GNOME and
KDE. D-BUS aims to be a better CORBA than CORBA and a better DCOP than
DCOP, satisfying the needs of both projects while providing additional
features.

And, D-BUS does all this while remaining simple and efficient.

Adding D-BUS Support to Your Application

The core D-BUS API, written in C, is rather low-level and large. On
top of this API, bindings integrate
with programming languages and environments, including Glib,
Python, Qt and Mono. On top of providing language wrappers, the bindings
provide environment-specific features. For example, the Glib bindings
treat D-BUS connections as GObjects and allow messaging to integrate
into the Glib mainloop. The preferred use of D-BUS is definitely using
language and environment-specific bindings, both for ease of use and
improved functionality.

Let's look at some basic uses of D-BUS in your application. We
first look at the C API and then poke at some D-BUS code using the
Glib interface.

The D-BUS C API

Using D-BUS starts with including its header:

#include <dbus/dbus.h>

The first thing you probably want to do is connect to an existing
bus. Recall from our initial D-BUS discussion that D-BUS provides two
buses, the session and the system bus. Let's connect to the system bus:

This sends the Feathers signal from
org.pirate.parrot.attr with a payload consisting of two fields,
each strings: Shiny and Well Groomed. Anyone listening on
the system message bus with sufficient permissions can subscribe to this
service and listen for the signal.

Disconnecting from the system message bus is a single function:

if (conn)
dbus_connection_disconnect (conn);

The Glib Bindings

Glib (pronounced gee-lib) is the base library of GNOME. It is on top
of Glib that Gtk+ (GNOME's GUI API) and the rest of GNOME is built. Glib
provides several convenience functions, portability wrappers, a family
of string functions and a complete object and type system—all in C.

The Glib library provides an object system and a mainloop, making
object-based, event-driven programming possible, even in C. The D-BUS
Glib bindings take advantage of these features. First, we want to
include the right header files:

The Peel function accepts a single parameter,
an integer. If this call returned nonzero, it succeeded, and the variable
ret holds the return value from this function. The data
types that a specific method accepts are determined by the remote method.
For example, we
could not have passed DBUS_TYPE_STRING instead of
DBUS_TYPE_INT32.

The main benefit of the Glib bindings
is mainloop integration, allowing developers to manage multiple D-BUS
messages intertwined with other I/O and UI events. The header file
<dbus/dbus-glib.h> declares multiple functions for connecting
D-BUS to the Glib mainloop.

If my understanding is correct, I should have a server object providing the method Peel to reply to the method request.Do I register it via "dbus_g_connection_lookup_g_object" and the object information via "void dbus_g_object_type_install_info"

Also when the server object get the Peel method, does it use "void dbus_g_method_return" to retun a message. Thx