Specifications

CHAPTER 5. IMPLEMENTATION 31
/* Check whether D-BUS connection is already established. */
if (dbus_connection == NULL) {
/* Connect to the D-BUS system message bus. */
dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
}
The type of the global variable dbus connection is DBusConnection. It represents a
D-BUS connection. The D-BUS function dbus get bus() establishes the connection and sub-
sequently returns the established connection. The first argument (DBUS BUS SYSTEM) states
that a connection to the system message bus is requested. Once issued, the D-BUS daemon
checks if the request is allowed by comparing the request with the policy defined by the D-BUS
configuration.
The modules report input events calling the library’s function event send(). This function
requires a pointer to an IalEvent structure—representing the abstract input event—as an
argument:
void event_send(IalEvent *);
The IalEvent structure has to be set up by the module which is calling event send()
(§5.3). Up on being called, event send() creates a D-BUS message and sends this message to
the Input Abstraction Layer’s D-BUS interface. This is done by appending each member of
the referred IalEvent structure to a D-BUS message. The following source code is a modified
and shortened excerpt of event send(), supplemented with the explanatory comments.
/* Create D-BUS message and message iterator. */
DBusMessage *dbus_message;
DBusMessageIter dbus_it;
/* Create a new message. */
dbus_message = dbus_message_new_signal("/com/novell/Ial/Event",
"com.novell.Ial.Event",
"event");
/* Initialize the message iterator. */
dbus_message_iter_init(dbus_message, &dbus_it);
/* Append message arguments. */
dbus_message_iter_append_string(&dbus_it, event->sender);
dbus_message_iter_append_string(&dbus_it, event->source);
dbus_message_iter_append_string(&dbus_it, event->name);
dbus_message_iter_append_int32(&dbus_it, event->raw);
/* Send the message. */
dbus_connection_send(dbus_connection, dbus_message, NULL);
DBusMessage is the data type representing a D-BUS message. The D-BUS data type
DBusMessageIter is an iterator representing the arguments of a DBusMessage. The function