Specifications
CHAPTER 5. IMPLEMENTATION 32
dbus message new signal() creates a new DBusMessage of type SIGNAL and returns a pointer
to the created structure. The arguments specify the message path (/com/novell/Ial/Event),
the D-BUS interface (com.novell.Ial.Event) and the signal name (event). These values are
essential for the D-BUS daemon to process the D-BUS message.
The message type SIGNAL is chosen since it matches the kind of an event. It is a unidirec-
tional message sent by one process and received by an arbitrary number of processes. Other
message types provided by D-BUS are METHOD CALL and METHOD RETURN. These message types
can be used to realize remote procedure calls with D-BUS.
D-BUS provides several functions to append arguments to a DBusMessageIter in partic-
ular, for each of its basic data type. In this case, the basic data types string and int32
are used. Since the Input Abstraction Layer is implemented using C, char * is mapped to
the basic D-BUS data type string, int is mapped to the basic D-BUS data type int32. An
application receiving the D-BUS message might be implemented using another programming
language, thus a corresponding type conversion has to be performed by D-BUS upon reception.
After appending all members to the D-BUS message, it is sent to the message bus.
All messages sent by the Input Abstraction Layer’s modules can be received by any appli-
cation. This is ensured by the described policy for the D-BUS daemon (allow all processes to
connect to the system message bus) in combination with the policy for the Input Abstraction
Layer (allow all processes to receive from the interface com.novell.Ial.Event). An applica-
tion which wants to receive messages has to set up a connection to the D-BUS system message
bus. Using this connection, the application has to install a so called match to receive abstract
input events. A match can be compared to a filter mechanism: only messages matching the
rules of the match will get through. The following code shows how a match is created:
/* Add a message filter to the D-BUS connection. */
dbus_connection_add_filter(dbus_connection, event_callback, NULL, NULL);
/* Add a match to the D-BUS connection. */
dbus_bus_add_match(dbus_connection,
"type=’signal’,
interface=’com.novell.Ial.Event’,
path=’/com/novell/Ial/Event’",
&dbus_error);
The function dbus connection add filter() adds a message filter to the established D-
BUS connection. This filter defines a message handler. In this case, the message handler is
called event callback(). The third and fourth arguments of dbus connection add filter()
are optional and set to NULL. After creating the filter, a match has to be added. The function
dbus bus add match() is used for this purpose. The second argument of the function call is
the rule applied by the match. In this case, the rule states that messages of the type signal
on the D-BUS interface com.novell.Ial.Event using the path /com/novell/Ial/Event are
selected. After applying this match, the callback function event callback() is invoked every
time a message is sent on the D-BUS matching this rule. Beside others, D-BUS invokes
the callback function with an argument (DBusMessage *) which references the message. The
following source code is an example implementation of event callback():