DBus represents an inter-process communication framework (IPC), which is especially used on Linux desktop environments. DBus is a freedesktop.org sub project. It was initiated for standardization of inter-process communication between different UI/window manager frameworks (KDE/Gnome) and Linux kernel. The DBus protocol has a binary format. A central DBus daemon receives messages of the clients and distributes them (broadcast/one-to-one).
For example if an USB stick will be inserted, the HAL DBus client (Hardware Abstraction Layer) informs all file browsers and desktops about this new hardware. You can use the libdbus library to implement C based DBus clients. The following basic example describes how to send a message to the bus.
#include#include static void send_dbus_message (DBusConnection *connection, const char *msg) { DBusMessage *message; //initiliaze the message message = dbus_message_new_signal ("/org/developers/blog/tablet/event", "org.developers.blog.tablet.text.focus.event", msg); //send the message dbus_connection_send (connection, message, NULL); //deallocate the message dbus_message_unref (message); } int main (int argc, char **argv) { DBusConnection *connection; DBusError error; //init error message dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_SESSION, &error); if (!connection) { printf ("Connection to D-BUS daemon failed: %s", error.message); //deallocate error message dbus_error_free (&error); return 1; } send_dbus_message (connection, "TabletUITextFocusEvent"); return 0; }
On Ubuntu systems you have to build this source snippet with the following command.
gcc `pkg-config --cflags --libs dbus-1` -o dbus-example dbus-example.c
After execution of the example you can see your message on console display with the command: dbus-monitor
signal sender=:1.166 -> dest=(null destination) serial=2 path=/org/developers/blog/tablet/event; interface=org.developers.blog.tablet.text.focus; member=TabletUITextFocusEvent
Regards
Rafael Sobek

Thank you very much for your example