/usr/share/doc/dbus/dbus-tutorial.html is in dbus-1-doc 1.10.6-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>D-Bus Tutorial</title><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="article"><div class="titlepage"><div><div><h2 class="title"><a name="index"></a>D-Bus Tutorial</h2></div><div><div class="authorgroup"><div class="author"><h3 class="author"><span class="firstname">Havoc</span> <span class="surname">Pennington</span></h3><div class="affiliation"><span class="orgname">Red Hat, Inc.<br></span><div class="address"><p><code class="email"><<a class="email" href="mailto:hp@pobox.com">hp@pobox.com</a>></code></p></div></div></div><div class="author"><h3 class="author"><span class="firstname">David</span> <span class="surname">Wheeler</span></h3></div><div class="author"><h3 class="author"><span class="firstname">John</span> <span class="surname">Palmieri</span></h3><div class="affiliation"><span class="orgname">Red Hat, Inc.<br></span><div class="address"><p><code class="email"><<a class="email" href="mailto:johnp@redhat.com">johnp@redhat.com</a>></code></p></div></div></div><div class="author"><h3 class="author"><span class="firstname">Colin</span> <span class="surname">Walters</span></h3><div class="affiliation"><span class="orgname">Red Hat, Inc.<br></span><div class="address"><p><code class="email"><<a class="email" href="mailto:walters@redhat.com">walters@redhat.com</a>></code></p></div></div></div></div></div><div><p class="releaseinfo">Version 0.5.0</p></div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="#meta">Tutorial Work In Progress</a></span></dt><dt><span class="sect1"><a href="#whatis">What is D-Bus?</a></span></dt><dd><dl><dt><span class="sect2"><a href="#uses">D-Bus applications</a></span></dt></dl></dd><dt><span class="sect1"><a href="#concepts">Concepts</a></span></dt><dd><dl><dt><span class="sect2"><a href="#objects">Native Objects and Object Paths</a></span></dt><dt><span class="sect2"><a href="#members">Methods and Signals</a></span></dt><dt><span class="sect2"><a href="#interfaces">Interfaces</a></span></dt><dt><span class="sect2"><a href="#proxies">Proxies</a></span></dt><dt><span class="sect2"><a href="#bus-names">Bus Names</a></span></dt><dt><span class="sect2"><a href="#addresses">Addresses</a></span></dt><dt><span class="sect2"><a href="#bigpicture">Big Conceptual Picture</a></span></dt><dt><span class="sect2"><a href="#messages">Messages - Behind the Scenes</a></span></dt><dt><span class="sect2"><a href="#callprocedure">Calling a Method - Behind the Scenes</a></span></dt><dt><span class="sect2"><a href="#signalprocedure">Emitting a Signal - Behind the Scenes</a></span></dt><dt><span class="sect2"><a href="#introspection">Introspection</a></span></dt></dl></dd><dt><span class="sect1"><a href="#glib-client">GLib APIs</a></span></dt><dt><span class="sect1"><a href="#python-client">Python API</a></span></dt><dt><span class="sect1"><a href="#qt-client">Qt API</a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="meta"></a>Tutorial Work In Progress</h2></div></div></div><p>
This tutorial is not complete; it probably contains some useful information, but
also has plenty of gaps. Right now, you'll also need to refer to the D-Bus specification,
Doxygen reference documentation, and look at some examples of how other apps use D-Bus.
</p><p>
Enhancing the tutorial is definitely encouraged - send your patches or suggestions to the
mailing list. If you create a D-Bus binding, please add a section to the tutorial for your
binding, if only a short section with a couple of examples.
</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="whatis"></a>What is D-Bus?</h2></div></div></div><p>
D-Bus is a system for <em class="firstterm">interprocess communication</em>
(IPC). Architecturally, it has several layers:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
A library, <em class="firstterm">libdbus</em>, that allows two
applications to connect to each other and exchange messages.
</p></li><li class="listitem"><p>
A <em class="firstterm">message bus daemon</em> executable, built on
libdbus, that multiple applications can connect to. The daemon can
route messages from one application to zero or more other
applications.
</p></li><li class="listitem"><p>
<em class="firstterm">Wrapper libraries</em> or <em class="firstterm">bindings</em>
based on particular application frameworks. For example, libdbus-glib and
libdbus-qt. There are also bindings to languages such as
Python. These wrapper libraries are the API most people should use,
as they simplify the details of D-Bus programming. libdbus is
intended to be a low-level backend for the higher level bindings.
Much of the libdbus API is only useful for binding implementation.
</p></li></ul></div><p>
</p><p>
libdbus only supports one-to-one connections, just like a raw network
socket. However, rather than sending byte streams over the connection, you
send <em class="firstterm">messages</em>. Messages have a header identifying
the kind of message, and a body containing a data payload. libdbus also
abstracts the exact transport used (sockets vs. whatever else), and
handles details such as authentication.
</p><p>
The message bus daemon forms the hub of a wheel. Each spoke of the wheel
is a one-to-one connection to an application using libdbus. An
application sends a message to the bus daemon over its spoke, and the bus
daemon forwards the message to other connected applications as
appropriate. Think of the daemon as a router.
</p><p>
The bus daemon has multiple instances on a typical computer. The
first instance is a machine-global singleton, that is, a system daemon
similar to sendmail or Apache. This instance has heavy security
restrictions on what messages it will accept, and is used for systemwide
communication. The other instances are created one per user login session.
These instances allow applications in the user's session to communicate
with one another.
</p><p>
The systemwide and per-user daemons are separate. Normal within-session
IPC does not involve the systemwide message bus process and vice versa.
</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="uses"></a>D-Bus applications</h3></div></div></div><p>
There are many, many technologies in the world that have "Inter-process
communication" or "networking" in their stated purpose: <a class="ulink" href="http://www.omg.org" target="_top">CORBA</a>, <a class="ulink" href="http://www.opengroup.org/dce/" target="_top">DCE</a>, <a class="ulink" href="http://www.microsoft.com/com/" target="_top">DCOM</a>, <a class="ulink" href="http://developer.kde.org/documentation/library/kdeqt/dcop.html" target="_top">DCOP</a>, <a class="ulink" href="http://www.xmlrpc.com" target="_top">XML-RPC</a>, <a class="ulink" href="http://www.w3.org/TR/SOAP/" target="_top">SOAP</a>, <a class="ulink" href="http://www.mbus.org/" target="_top">MBUS</a>, <a class="ulink" href="http://www.zeroc.com/ice.html" target="_top">Internet Communications Engine (ICE)</a>,
and probably hundreds more.
Each of these is tailored for particular kinds of application.
D-Bus is designed for two specific cases:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
Communication between desktop applications in the same desktop
session; to allow integration of the desktop session as a whole,
and address issues of process lifecycle (when do desktop components
start and stop running).
</p></li><li class="listitem"><p>
Communication between the desktop session and the operating system,
where the operating system would typically include the kernel
and any system daemons or processes.
</p></li></ul></div><p>
</p><p>
For the within-desktop-session use case, the GNOME and KDE desktops
have significant previous experience with different IPC solutions
such as CORBA and DCOP. D-Bus is built on that experience and
carefully tailored to meet the needs of these desktop projects
in particular. D-Bus may or may not be appropriate for other
applications; the FAQ has some comparisons to other IPC systems.
</p><p>
The problem solved by the systemwide or communication-with-the-OS case
is explained well by the following text from the Linux Hotplug project:
</p><div class="blockquote"><blockquote class="blockquote"><p>
A gap in current Linux support is that policies with any sort of
dynamic "interact with user" component aren't currently
supported. For example, that's often needed the first time a network
adapter or printer is connected, and to determine appropriate places
to mount disk drives. It would seem that such actions could be
supported for any case where a responsible human can be identified:
single user workstations, or any system which is remotely
administered.
</p><p>
This is a classic "remote sysadmin" problem, where in this case
hotplugging needs to deliver an event from one security domain
(operating system kernel, in this case) to another (desktop for
logged-in user, or remote sysadmin). Any effective response must go
the other way: the remote domain taking some action that lets the
kernel expose the desired device capabilities. (The action can often
be taken asynchronously, for example letting new hardware be idle
until a meeting finishes.) At this writing, Linux doesn't have
widely adopted solutions to such problems. However, the new D-Bus
work may begin to solve that problem.
</p></blockquote></div><p>
</p><p>
D-Bus may happen to be useful for purposes other than the one it was
designed for. Its general properties that distinguish it from
other forms of IPC are:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
Binary protocol designed to be used asynchronously
(similar in spirit to the X Window System protocol).
</p></li><li class="listitem"><p>
Stateful, reliable connections held open over time.
</p></li><li class="listitem"><p>
The message bus is a daemon, not a "swarm" or
distributed architecture.
</p></li><li class="listitem"><p>
Many implementation and deployment issues are specified rather
than left ambiguous/configurable/pluggable.
</p></li><li class="listitem"><p>
Semantics are similar to the existing DCOP system, allowing
KDE to adopt it more easily.
</p></li><li class="listitem"><p>
Security features to support the systemwide mode of the
message bus.
</p></li></ul></div><p>
</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="concepts"></a>Concepts</h2></div></div></div><p>
Some basic concepts apply no matter what application framework you're
using to write a D-Bus application. The exact code you write will be
different for GLib vs. Qt vs. Python applications, however.
</p><p>
Here is a diagram (<a class="ulink" href="diagram.png" target="_top">png</a> <a class="ulink" href="diagram.svg" target="_top">svg</a>) that may help you visualize the concepts
that follow.
</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="objects"></a>Native Objects and Object Paths</h3></div></div></div><p>
Your programming framework probably defines what an "object" is like;
usually with a base class. For example: java.lang.Object, GObject, QObject,
python's base Object, or whatever. Let's call this a <em class="firstterm">native object</em>.
</p><p>
The low-level D-Bus protocol, and corresponding libdbus API, does not care about native objects.
However, it provides a concept called an
<em class="firstterm">object path</em>. The idea of an object path is that
higher-level bindings can name native object instances, and allow remote applications
to refer to them.
</p><p>
The object path
looks like a filesystem path, for example an object could be
named <code class="literal">/org/kde/kspread/sheets/3/cells/4/5</code>.
Human-readable paths are nice, but you are free to create an
object named <code class="literal">/com/mycompany/c5yo817y0c1y1c5b</code>
if it makes sense for your application.
</p><p>
Namespacing object paths is smart, by starting them with the components
of a domain name you own (e.g. <code class="literal">/org/kde</code>). This
keeps different code modules in the same process from stepping
on one another's toes.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="members"></a>Methods and Signals</h3></div></div></div><p>
Each object has <em class="firstterm">members</em>; the two kinds of member
are <em class="firstterm">methods</em> and
<em class="firstterm">signals</em>. Methods are operations that can be
invoked on an object, with optional input (aka arguments or "in
parameters") and output (aka return values or "out parameters").
Signals are broadcasts from the object to any interested observers
of the object; signals may contain a data payload.
</p><p>
Both methods and signals are referred to by name, such as
"Frobate" or "OnClicked".
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="interfaces"></a>Interfaces</h3></div></div></div><p>
Each object supports one or more <em class="firstterm">interfaces</em>.
Think of an interface as a named group of methods and signals,
just as it is in GLib or Qt or Java. Interfaces define the
<span class="emphasis"><em>type</em></span> of an object instance.
</p><p>
DBus identifies interfaces with a simple namespaced string,
something like <code class="literal">org.freedesktop.Introspectable</code>.
Most bindings will map these interface names directly to
the appropriate programming language construct, for example
to Java interfaces or C++ pure virtual classes.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="proxies"></a>Proxies</h3></div></div></div><p>
A <em class="firstterm">proxy object</em> is a convenient native object created to
represent a remote object in another process. The low-level DBus API involves manually creating
a method call message, sending it, then manually receiving and processing
the method reply message. Higher-level bindings provide proxies as an alternative.
Proxies look like a normal native object; but when you invoke a method on the proxy
object, the binding converts it into a DBus method call message, waits for the reply
message, unpacks the return value, and returns it from the native method..
</p><p>
In pseudocode, programming without proxies might look like this:
</p><pre class="programlisting">
Message message = new Message("/remote/object/path", "MethodName", arg1, arg2);
Connection connection = getBusConnection();
connection.send(message);
Message reply = connection.waitForReply(message);
if (reply.isError()) {
} else {
Object returnValue = reply.getReturnValue();
}
</pre><p>
</p><p>
Programming with proxies might look like this:
</p><pre class="programlisting">
Proxy proxy = new Proxy(getBusConnection(), "/remote/object/path");
Object returnValue = proxy.MethodName(arg1, arg2);
</pre><p>
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="bus-names"></a>Bus Names</h3></div></div></div><p>
When each application connects to the bus daemon, the daemon immediately
assigns it a name, called the <em class="firstterm">unique connection name</em>.
A unique name begins with a ':' (colon) character. These names are never
reused during the lifetime of the bus daemon - that is, you know
a given name will always refer to the same application.
An example of a unique name might be
<code class="literal">:34-907</code>. The numbers after the colon have
no meaning other than their uniqueness.
</p><p>
When a name is mapped
to a particular application's connection, that application is said to
<em class="firstterm">own</em> that name.
</p><p>
Applications may ask to own additional <em class="firstterm">well-known
names</em>. For example, you could write a specification to
define a name called <code class="literal">com.mycompany.TextEditor</code>.
Your definition could specify that to own this name, an application
should have an object at the path
<code class="literal">/com/mycompany/TextFileManager</code> supporting the
interface <code class="literal">org.freedesktop.FileHandler</code>.
</p><p>
Applications could then send messages to this bus name,
object, and interface to execute method calls.
</p><p>
You could think of the unique names as IP addresses, and the
well-known names as domain names. So
<code class="literal">com.mycompany.TextEditor</code> might map to something like
<code class="literal">:34-907</code> just as <code class="literal">mycompany.com</code> maps
to something like <code class="literal">192.168.0.5</code>.
</p><p>
Names have a second important use, other than routing messages. They
are used to track lifecycle. When an application exits (or crashes), its
connection to the message bus will be closed by the operating system
kernel. The message bus then sends out notification messages telling
remaining applications that the application's names have lost their
owner. By tracking these notifications, your application can reliably
monitor the lifetime of other applications.
</p><p>
Bus names can also be used to coordinate single-instance applications.
If you want to be sure only one
<code class="literal">com.mycompany.TextEditor</code> application is running for
example, have the text editor application exit if the bus name already
has an owner.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="addresses"></a>Addresses</h3></div></div></div><p>
Applications using D-Bus are either servers or clients. A server
listens for incoming connections; a client connects to a server. Once
the connection is established, it is a symmetric flow of messages; the
client-server distinction only matters when setting up the
connection.
</p><p>
If you're using the bus daemon, as you probably are, your application
will be a client of the bus daemon. That is, the bus daemon listens
for connections and your application initiates a connection to the bus
daemon.
</p><p>
A D-Bus <em class="firstterm">address</em> specifies where a server will
listen, and where a client will connect. For example, the address
<code class="literal">unix:path=/tmp/abcdef</code> specifies that the server will
listen on a UNIX domain socket at the path
<code class="literal">/tmp/abcdef</code> and the client will connect to that
socket. An address can also specify TCP/IP sockets, or any other
transport defined in future iterations of the D-Bus specification.
</p><p>
When using D-Bus with a message bus daemon,
libdbus automatically discovers the address of the per-session bus
daemon by reading an environment variable. It discovers the
systemwide bus daemon by checking a well-known UNIX domain socket path
(though you can override this address with an environment variable).
</p><p>
If you're using D-Bus without a bus daemon, it's up to you to
define which application will be the server and which will be
the client, and specify a mechanism for them to agree on
the server's address. This is an unusual case.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="bigpicture"></a>Big Conceptual Picture</h3></div></div></div><p>
Pulling all these concepts together, to specify a particular
method call on a particular object instance, a number of
nested components have to be named:
</p><pre class="programlisting">
Address -> [Bus Name] -> Path -> Interface -> Method
</pre><p>
The bus name is in brackets to indicate that it's optional -- you only
provide a name to route the method call to the right application
when using the bus daemon. If you have a direct connection to another
application, bus names aren't used; there's no bus daemon.
</p><p>
The interface is also optional, primarily for historical
reasons; DCOP does not require specifying the interface,
instead simply forbidding duplicate method names
on the same object instance. D-Bus will thus let you
omit the interface, but if your method name is ambiguous
it is undefined which method will be invoked.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="messages"></a>Messages - Behind the Scenes</h3></div></div></div><p>
D-Bus works by sending messages between processes. If you're using
a sufficiently high-level binding, you may never work with messages directly.
</p><p>
There are 4 message types:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
Method call messages ask to invoke a method
on an object.
</p></li><li class="listitem"><p>
Method return messages return the results
of invoking a method.
</p></li><li class="listitem"><p>
Error messages return an exception caused by
invoking a method.
</p></li><li class="listitem"><p>
Signal messages are notifications that a given signal
has been emitted (that an event has occurred).
You could also think of these as "event" messages.
</p></li></ul></div><p>
</p><p>
A method call maps very simply to messages: you send a method call
message, and receive either a method return message or an error message
in reply.
</p><p>
Each message has a <em class="firstterm">header</em>, including <em class="firstterm">fields</em>,
and a <em class="firstterm">body</em>, including <em class="firstterm">arguments</em>. You can think
of the header as the routing information for the message, and the body as the payload.
Header fields might include the sender bus name, destination bus name, method or signal name,
and so forth. One of the header fields is a <em class="firstterm">type signature</em> describing the
values found in the body. For example, the letter "i" means "32-bit integer" so the signature
"ii" means the payload has two 32-bit integers.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="callprocedure"></a>Calling a Method - Behind the Scenes</h3></div></div></div><p>
A method call in DBus consists of two messages; a method call message sent from process A to process B,
and a matching method reply message sent from process B to process A. Both the call and the reply messages
are routed through the bus daemon. The caller includes a different serial number in each call message, and the
reply message includes this number to allow the caller to match replies to calls.
</p><p>
The call message will contain any arguments to the method.
The reply message may indicate an error, or may contain data returned by the method.
</p><p>
A method invocation in DBus happens as follows:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
The language binding may provide a proxy, such that invoking a method on
an in-process object invokes a method on a remote object in another process. If so, the
application calls a method on the proxy, and the proxy
constructs a method call message to send to the remote process.
</p></li><li class="listitem"><p>
For more low-level APIs, the application may construct a method call message itself, without
using a proxy.
</p></li><li class="listitem"><p>
In either case, the method call message contains: a bus name belonging to the remote process; the name of the method;
the arguments to the method; an object path inside the remote process; and optionally the name of the
interface that specifies the method.
</p></li><li class="listitem"><p>
The method call message is sent to the bus daemon.
</p></li><li class="listitem"><p>
The bus daemon looks at the destination bus name. If a process owns that name,
the bus daemon forwards the method call to that process. Otherwise, the bus daemon
creates an error message and sends it back as the reply to the method call message.
</p></li><li class="listitem"><p>
The receiving process unpacks the method call message. In a simple low-level API situation, it
may immediately run the method and send a method reply message to the bus daemon.
When using a high-level binding API, the binding might examine the object path, interface,
and method name, and convert the method call message into an invocation of a method on
a native object (GObject, java.lang.Object, QObject, etc.), then convert the return
value from the native method into a method reply message.
</p></li><li class="listitem"><p>
The bus daemon receives the method reply message and sends it to the process that
made the method call.
</p></li><li class="listitem"><p>
The process that made the method call looks at the method reply and makes use of any
return values included in the reply. The reply may also indicate that an error occurred.
When using a binding, the method reply message may be converted into the return value of
of a proxy method, or into an exception.
</p></li></ul></div><p>
</p><p>
The bus daemon never reorders messages. That is, if you send two method call messages to the same recipient,
they will be received in the order they were sent. The recipient is not required to reply to the calls
in order, however; for example, it may process each method call in a separate thread, and return reply messages
in an undefined order depending on when the threads complete. Method calls have a unique serial
number used by the method caller to match reply messages to call messages.
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="signalprocedure"></a>Emitting a Signal - Behind the Scenes</h3></div></div></div><p>
A signal in DBus consists of a single message, sent by one process to any number of other processes.
That is, a signal is a unidirectional broadcast. The signal may contain arguments (a data payload), but
because it is a broadcast, it never has a "return value." Contrast this with a method call
(see <a class="xref" href="#callprocedure" title="Calling a Method - Behind the Scenes">the section called “Calling a Method - Behind the Scenes”</a>) where the method call message has a matching method reply message.
</p><p>
The emitter (aka sender) of a signal has no knowledge of the signal recipients. Recipients register
with the bus daemon to receive signals based on "match rules" - these rules would typically include the sender and
the signal name. The bus daemon sends each signal only to recipients who have expressed interest in that
signal.
</p><p>
A signal in DBus happens as follows:
</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
A signal message is created and sent to the bus daemon. When using the low-level API this may be
done manually, with certain bindings it may be done for you by the binding when a native object
emits a native signal or event.
</p></li><li class="listitem"><p>
The signal message contains the name of the interface that specifies the signal;
the name of the signal; the bus name of the process sending the signal; and
any arguments
</p></li><li class="listitem"><p>
Any process on the message bus can register "match rules" indicating which signals it
is interested in. The bus has a list of registered match rules.
</p></li><li class="listitem"><p>
The bus daemon examines the signal and determines which processes are interested in it.
It sends the signal message to these processes.
</p></li><li class="listitem"><p>
Each process receiving the signal decides what to do with it; if using a binding,
the binding may choose to emit a native signal on a proxy object. If using the
low-level API, the process may just look at the signal sender and name and decide
what to do based on that.
</p></li></ul></div><p>
</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="introspection"></a>Introspection</h3></div></div></div><p>
D-Bus objects may support the interface <code class="literal">org.freedesktop.DBus.Introspectable</code>.
This interface has one method <code class="literal">Introspect</code> which takes no arguments and returns
an XML string. The XML string describes the interfaces, methods, and signals of the object.
See the D-Bus specification for more details on this introspection format.
</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="glib-client"></a>GLib APIs</h2></div></div></div><p>
The recommended GLib API for D-Bus is GDBus, which has been
distributed with GLib since version 2.26. It is not documented here.
See <a class="ulink" href="https://developer.gnome.org/gio/stable/gdbus-convenience.html" target="_top">the
GLib documentation</a> for details of how to use GDBus.
</p><p>
An older API, dbus-glib, also exists. It is deprecated and should
not be used in new code. Whenever possible, porting existing code
from dbus-glib to GDBus is also recommended.
</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="python-client"></a>Python API</h2></div></div></div><p>
The Python API, dbus-python, is now documented separately in
<a class="ulink" href="http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html" target="_top">the dbus-python tutorial</a> (also available in doc/tutorial.txt,
and doc/tutorial.html if built with python-docutils, in the dbus-python
source distribution).
</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="qt-client"></a>Qt API</h2></div></div></div><p>
The Qt binding for libdbus, QtDBus, has been distributed with Qt
since version 4.2. It is not documented here. See
<a class="ulink" href="http://qt-project.org/doc/qt-5/qtdbus-index.html" target="_top">the Qt
documentation</a> for details of how to use QtDBus.
</p></div></div></body></html>
|