aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2007-12-02 16:28:13 +0000
committerMichael Albinus2007-12-02 16:28:13 +0000
commit22d8ac3a6aedbb0755e7c84549bc2d9aa1239d87 (patch)
tree300ffa4b278c6f1d8b396ebc0391572864241a2f
parent3a993e3de8b36b9b66a0ec440bf493946451769c (diff)
downloademacs-22d8ac3a6aedbb0755e7c84549bc2d9aa1239d87.tar.gz
emacs-22d8ac3a6aedbb0755e7c84549bc2d9aa1239d87.zip
* dbus.texi: New file.
-rw-r--r--doc/misc/ChangeLog4
-rw-r--r--doc/misc/dbus.texi562
2 files changed, 566 insertions, 0 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index 5526b66fb4f..92a1a718b2d 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,7 @@
12007-12-02 Michael Albinus <michael.albinus@gmx.de>
2
3 * dbus.texi: New file.
4
12007-11-24 Romain Francoise <romain@orebokech.com> 52007-11-24 Romain Francoise <romain@orebokech.com>
2 6
3 * nxml-mode.texi: Add description in @direntry. 7 * nxml-mode.texi: Add description in @direntry.
diff --git a/doc/misc/dbus.texi b/doc/misc/dbus.texi
new file mode 100644
index 00000000000..df968f02d60
--- /dev/null
+++ b/doc/misc/dbus.texi
@@ -0,0 +1,562 @@
1\input texinfo @c -*-texinfo-*-
2@setfilename ../../info/dbus
3@c %**start of header
4@settitle Using of D-Bus
5@c @setchapternewpage odd
6@c %**end of header
7
8@copying
9Copyright @copyright{} 2007 Free Software Foundation, Inc.
10
11@quotation
12Permission is granted to copy, distribute and/or modify this document
13under the terms of the GNU Free Documentation License, Version 1.2 or
14any later version published by the Free Software Foundation; with no
15Invariant Sections, with the Front-Cover texts being ``A GNU
16Manual'', and with the Back-Cover Texts as in (a) below. A copy of the
17license is included in the section entitled ``GNU Free Documentation
18License'' in the Emacs manual.
19
20(a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
21this GNU Manual, like GNU software. Copies published by the Free
22Software Foundation raise funds for GNU development.''
23
24This document is part of a collection distributed under the GNU Free
25Documentation License. If you want to distribute this document
26separately from the collection, you can do so by adding a copy of the
27license to the document, as described in section 6 of the license.
28@end quotation
29@end copying
30
31@dircategory Emacs
32@direntry
33* D-Bus: (dbus). Using D-Bus in Emacs.
34@end direntry
35
36@node Top, Overview, (dir), (dir)
37@top D-Bus integration in Emacs
38
39This manual documents an API for usage of D-Bus in
40Emacs.@footnote{D-Bus is not enabled by default. You must run
41@command{./configure --with-dbus} in Emacs' top level directory,
42before you compile Emacs.} D-Bus is a message bus system, a simple
43way for applications to talk to one another. An overview of D-Bus can
44be found at @uref{http://dbus.freedesktop.org/}.
45
46@insertcopying
47
48@menu
49* Overview:: An overview of D-Bus.
50* Inspection:: Inspection of the bus names.
51* Type Conversion:: Mapping Lisp types and D-Bus types.
52* Synchronous Methods:: Calling methods in a blocking way.
53* Signals:: Sending and receiving signals.
54* Errors and Events:: Errors and events.
55* GNU Free Documentation License:: The license for this documentation.
56@end menu
57
58@node Overview
59@chapter An overview of D-Bus
60@cindex overview
61
62D-Bus is an inter-process communication mechanism for applications
63residing on the same host. The communication is based on
64@dfn{messages}. Data in the messages is carried in a structured way,
65it is not just a byte stream.
66
67The communication is connection oriented to two kinds of message
68buses: a so called @dfn{system bus}, and a @dfn{session bus}. On a
69given machine, there is always one single system bus for miscellaneous
70system-wide communication, like changing of hardware configuration.
71On the other hand, the session bus is always related to a single
72user's session.
73
74Every client application, which is connected to a bus, registers under
75a @dfn{unique name} at the bus. This name is used for identifying the
76client application. Such a unique name starts always with a colon,
77and looks like @samp{:1.42}.
78
79Additionally, a client application can register itself to a so called
80@dfn{known name}, which is a series of identifiers separated by dots,
81e.g. @samp{org.gnu.Emacs}. If several applications register to the
82same known name, these registrations are queued, and only the first
83application which has registered for the known name is reachable via
84this name. If this application disconnects from the bus, the next
85queued unique name becomes the owner of this known name.
86
87An application can install one or several objects under its name.
88Such objects are identified by an @dfn{object path}, which looks
89similar to paths in a filesystem. An example of such an object path
90could be @samp{/org/gnu/Emacs/}.
91
92Applications might send a request to an object, that means sending a
93message with some data as input parameters, and receiving a message
94from that object with the result of this message, the output
95parameters. Such a request is called @dfn{method} in D-Bus.
96
97The other form of communication are @dfn{signals}. The underlying
98message is emitted from an object and will be received by all other
99applications which have registered for such a signal.
100
101All methods and signals an object supports are called @dfn{interface}
102of the object. Interfaces are specified under a hierarchical name in
103D-Bus; an object can support several interfaces. Such an interface
104name could be @samp{org.gnu.Emacs.TextEditor} or
105@samp{org.gnu.Emacs.FileManager}.
106
107
108@node Inspection
109@chapter Inspection of the bus names.
110@cindex inspection
111
112There are several basic functions which inspect the buses for
113registered names. Internally they use the basic interface
114@samp{org.freedesktop.DBus}, which is supported by all objects of a bus.
115
116@defun dbus-list-activatable-names
117
118This function returns the D-Bus service names, which can be activated.
119An activatable service is described in a service registration file.
120Under GNU/Linux, such files are located at
121@file{/usr/share/dbus-1/services/}.
122
123The result is a list of strings, which is @code{nil} when there are no
124activatable service names at all.
125@end defun
126
127@defun dbus-list-names bus
128
129All service names, which are registered at D-Bus @var{bus}, are
130returned. The result is a list of strings, which is @code{nil} when
131there are no registered service names at all. Well known names are
132strings like @samp{org.freedesktop.DBus}. Names starting with
133@samp{:} are unique names for services.
134
135@var{bus} must be either the symbol @code{:system} or the symbol
136@code{:session}.
137@end defun
138
139@defun dbus-list-known-names bus
140
141Retrieves all services which correspond to a known name in @var{bus}.
142A service has a known name if it doesn't start with @samp{:}. The
143result is a list of strings, which is @code{nil} when there are no
144known names at all.
145
146@var{bus} must be either the symbol @code{:system} or the symbol
147@code{:session}.
148@end defun
149
150@defun dbus-list-queued-owners bus service
151
152For a given service, registered at D-Bus @var{bus} under the name
153@var{service}, all queued unique names are returned. The result is a
154list of strings, or @code{nil} when there are no queued names for
155@var{service} at all.
156
157@var{bus} must be either the symbol @code{:system} or the symbol
158@code{:session}. @var{service} must be a known service name as
159string.
160@end defun
161
162@defun dbus-get-name-owner bus service
163
164For a given service, registered at D-Bus @var{bus} under the name
165@var{service}, the unique name of the name owner is returned. The result is a
166string, or @code{nil} when there exist no name owner of @var{service}.
167
168@var{bus} must be either the symbol @code{:system} or the symbol
169@code{:session}. @var{service} must be a known service name as
170string.
171@end defun
172
173@defun dbus-get-unique-name bus
174
175The unique name, under which Emacs is registered at D-Bus @var{bus},
176is returned as string.
177
178@var{bus} must be either the symbol @code{:system} or the symbol
179@code{:session}.
180@end defun
181
182@defun dbus-introspect bus service path
183
184Objects can publish there interfaces to the D-Bus. This function
185returns all interfaces of @var{service}, registered at object path
186@var{path} at bus @var{bus}.
187
188@var{bus} must be either the symbol @code{:system} or the symbol
189@code{:session}. @var{service} must be a known service name, and
190@var{path} must be a valid object path. The last two parameters are
191strings. The result, the introspection data, is a string in XML
192format. Example:
193
194@example
195(dbus-introspect
196 :system "org.freedesktop.Hal"
197 "/org/freedesktop/Hal/devices/computer")
198
199@result{} <!DOCTYPE node PUBLIC
200 "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
201 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
202 <node>
203 <interface name="org.freedesktop.Hal.Device">
204 <method name="GetAllProperties">
205 <arg name="properties" direction="out" type="a@{sv@}"/>
206 </method>
207 ...
208 <signal name="PropertyModified">
209 <arg name="num_updates" type="i"/>
210 <arg name="updates" type="a(sbb)"/>
211 </signal>
212 </interface>
213 ...
214 </node>
215@end example
216
217This example informs us, that the service @code{org.freedesktop.Hal}
218at object path @code{/org/freedesktop/Hal/devices/computer} offers the
219interface @code{org.freedesktop.Hal.Device} (and 2 other interfaces
220not documented here). This interface contains the method
221@code{GetAllProperties}, which needs no input parameters, but returns
222as output parameter an array of dictionary entries (key-value pairs).
223Every dictionary entry has a string as key, and a variant as value.
224
225The interface offers also a signal, which returns 2 parameters: an
226integer, and an array consisting of elements which are a struct of a
227string and 2 boolean values.
228
229Such type descriptions are called @dfn{signature} in D-Bus. For a
230discussion of D-Bus types and their Lisp representation see @ref{Type
231Conversion}.@footnote{D-Bus signatures are explained in the D-Bus
232specification
233@uref{http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures}.
234The interfaces of the service @code{org.freedesktop.Hal} are described
235at
236@uref{http://people.freedesktop.org/~david/hal-spec/hal-spec.html#interfaces}.}
237@end defun
238
239
240@node Type Conversion
241@chapter Mapping Lisp types and D-Bus types.
242@cindex type conversion
243
244D-Bus method calls and signals accept usually several arguments as
245parameters, either as input parameter, or as output parameter. Every
246argument belongs to a D-Bus type.
247
248Such arguments must be mapped between the the value encoded as a D-Bus
249type, and the corresponding type of Lisp objects. The mapping is
250applied Lisp object @expansion{} D-Bus type for input parameters, and
251D-Bus type @expansion{} Lisp object for output parameters.
252
253
254@section Input parameters.
255
256Input parameters for D-Bus methods and signals occur as arguments of a
257Lisp function call. Only some primitive Lisp types are supported in
258the current implementation. The following mapping to D-Bus types is
259applied, when the corresponding D-Bus message is created:
260
261@example
262@multitable {@code{t} and @code{nil}} {@expansion{}} {DBUS_TYPE_BOOLEAN}
263@item Lisp type @tab @tab D-Bus type
264@item
265@item @code{t} and @code{nil} @tab @expansion{} @tab DBUS_TYPE_BOOLEAN
266@item number @tab @expansion{} @tab DBUS_TYPE_UINT32
267@item integer @tab @expansion{} @tab DBUS_TYPE_INT32
268@item float @tab @expansion{} @tab DBUS_TYPE_DOUBLE
269@item string @tab @expansion{} @tab DBUS_TYPE_STRING
270@end multitable
271@end example
272
273@noindent
274Other Lisp types, especially lists, are not supported (yet).
275
276
277@section Output parameters.
278
279Output parameters of D-Bus methods and signals are mapped to Lisp
280objects. This mapping is more powerful than the one for input
281parameters, i.e. more types are supported by the current
282implementation.
283
284@example
285@multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {@code{t} or @code{nil}}
286@item D-Bus type @tab @tab Lisp type
287@item
288@item DBUS_TYPE_BOOLEAN @tab @expansion{} @tab @code{t} or @code{nil}
289@item DBUS_TYPE_UINT32 @tab @expansion{} @tab number
290@item DBUS_TYPE_INT32 @tab @expansion{} @tab number
291@item DBUS_TYPE_DOUBLE @tab @expansion{} @tab float
292@item DBUS_TYPE_STRING @tab @expansion{} @tab string
293@item DBUS_TYPE_OBJECT_PATH @tab @expansion{} @tab string
294@item DBUS_TYPE_ARRAY @tab @expansion{} @tab list
295@item DBUS_TYPE_VARIANT @tab @expansion{} @tab list
296@item DBUS_TYPE_STRUCT @tab @expansion{} @tab list
297@item DBUS_TYPE_DICT_ENTRY @tab @expansion{} @tab list
298@end multitable
299@end example
300
301The resulting list of the last 4 D-Bus compound types contains as
302elements the elements of the D-Bus container, mapped according to the
303same rules.
304
305The signal @code{PropertyModified}, discussed as example in
306@ref{Inspection}, would offer as Lisp data the following object
307(@var{BOOL} stands here for either @code{nil} or @code{t}):
308
309@lisp
310(@var{NUMBER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) ...))
311@end lisp
312
313
314@node Synchronous Methods
315@chapter Calling methods in a blocking way.
316@cindex method calls, synchronous
317@cindex synchronous method calls
318
319Methods can be called synchronously (@dfn{blocking}) or asynchronously
320(@dfn{non-blocking}). Currently, just synchronous methods are
321implemented.
322
323At D-Bus level, a method call consist of two messages: one message
324which carries the input parameters to the object owning the method to
325be called, and a reply message returning the resulting output
326parameters from the object.
327
328@defun dbus-call-method bus method service path interface &rest args
329
330This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is
331either the symbol @code{:system} or the symbol @code{:session}.
332
333@var{service} is the D-Bus service name to be used. @var{path} is the
334D-Bus object path, @var{service} is registered at. @var{interface} is
335an interface offered by @var{service}. It must provide @var{method}.
336
337All other arguments args are passed to @var{method} as arguments.
338They are converted into D-Bus types as described in @ref{Type
339Conversion}.
340
341The function returns the resulting values of @var{method} as a list of
342Lisp objects, according to the type conversion rules described in
343@ref{Type Conversion}. Example:
344
345@example
346(dbus-call-method
347 :session "GetKeyField" "org.gnome.seahorse"
348 "/org/gnome/seahorse/keys/openpgp" "org.gnome.seahorse.Keys"
349 "openpgp:657984B8C7A966DD" "simple-name")
350
351@result{} (t ("Philip R. Zimmermann"))
352@end example
353
354If the result of the method call is just one value, the converted Lisp
355object is returned instead of a list containing this single Lisp
356object. Example:
357
358@example
359(dbus-call-method
360 :system "GetPropertyString" "org.freedesktop.Hal"
361 "/org/freedesktop/Hal/devices/computer" "org.freedesktop.Hal.Device"
362 "system.kernel.machine")
363
364@result{} "i686"
365@end example
366
367With the @code{dbus-introspect} function it is possible to explore the
368interfaces of @samp{org.freedesktop.Hal} service. It offers the
369interfaces @samp{org.freedesktop.Hal.Manager} for the object at the
370path @samp{/org/freedesktop/Hal/Manager} as well as the interface
371@samp{org.freedesktop.Hal.Device} for all objects prefixed with the
372path @samp{/org/freedesktop/Hal/devices}. With the methods
373@samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to
374emulate the @code{lshal} command on GNU/Linux systems:
375
376@example
377(dolist (device
378 (dbus-call-method
379 :system "GetAllDevices" "org.freedesktop.Hal"
380 "/org/freedesktop/Hal/Manager"
381 "org.freedesktop.Hal.Manager"))
382 (message "\nudi = %s" device)
383 (dolist (properties
384 (dbus-call-method
385 :system "GetAllProperties" "org.freedesktop.Hal"
386 device "org.freedesktop.Hal.Device"))
387 (message " %s = %S"
388 (car properties) (or (caar (cdr properties)) ""))))
389
390@result{} udi = /org/freedesktop/Hal/devices/computer
391 info.addons = ("hald-addon-acpi")
392 info.bus = "unknown"
393 info.product = "Computer"
394 info.subsystem = "unknown"
395 info.udi = "/org/freedesktop/Hal/devices/computer"
396 linux.sysfs_path_device = "(none)"
397 power_management.acpi.linux.version = "20051216"
398 power_management.can_suspend_to_disk = t
399 power_management.can_suspend_to_ram = ""
400 power_management.type = "acpi"
401 smbios.bios.release_date = "11/07/2001"
402 system.chassis.manufacturer = "COMPAL"
403 system.chassis.type = "Notebook"
404 system.firmware.release_date = "03/19/2005"
405 ...
406@end example
407@end defun
408
409
410@node Signals
411@chapter Sending and receiving signals.
412@cindex signals
413
414Signals are broadcast messages. They carry input parameters, which
415are received by all objects which have registered for such a signal.
416
417@defun dbus-send-signal bus signal service path interface &rest args
418
419This function is similar to @code{dbus-call-method}. The difference
420is, that there are no returning output parameters.
421
422The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is
423either the symbol @code{:system} or the symbol @code{:session}. It
424doesn't matter whether another object has registered for @var{signal}.
425
426@var{service} is the D-Bus service name of the object the signal is
427emitted from. @var{path} is the corresponding D-Bus object path,
428@var{service} is registered at. @var{interface} is an interface
429offered by @var{service}. It must provide @var{signal}.
430
431All other arguments args are passed to @var{signal} as arguments.
432They are converted into D-Bus types as described in @ref{Type
433Conversion}. Example:
434
435@example
436(dbus-send-signal
437 :session "FileModified" "org.gnu.Emacs" "/org/gnu/Emacs"
438 "org.gnu.Emacs.FileManager" "/home/albinus/.emacs")
439@end example
440@end defun
441
442@defun dbus-register-signal bus signal service path interface handler
443
444With this function, an application registers for @var{signal} on the
445D-Bus @var{bus}.
446
447@var{bus} is either the symbol @code{:system} or the symbol
448@code{:session}.
449
450@var{service} is the D-Bus service name of the object the signal is
451emitted from. @var{path} is the corresponding D-Bus object path,
452@var{service} is registered at. @var{interface} is an interface
453offered by @var{service}. It must provide @var{signal}.
454
455@var{handler} is a Lisp function to be called when the @var{signal} is
456received. It must accept as arguments the output parameters
457@var{signal} is sending. Example:
458
459@example
460(defun my-dbus-signal-handler (device)
461 (message "Device %s added" device))
462
463(dbus-register-signal
464 :system "DeviceAdded" "org.freedesktop.Hal"
465 "/org/freedesktop/Hal/Manager" "org.freedesktop.Hal.Manager"
466 'my-dbus-signal-handler)
467
468@result{} :system.org.freedesktop.Hal.Manager.DeviceAdded
469@end example
470
471As we know from the inspection data of interface
472@code{org.freedesktop.Hal.Manager}, the signal @code{DeviceAdded}
473provides one single parameter, which is mapped into a Lisp string.
474The callback function @code{my-dbus-signal-handler} must define one
475single string argument therefore. Plugging an USB device to your
476machine, when registered for signal @code{DeviceAdded}, will show you
477which objects the GNU/Linux @code{hal} daemon adds.
478
479@code{dbus-register-signal} returns a Lisp symbol, which can be used
480as argument in @code{dbus-unregister-signal} for removing the
481registration for @var{signal}.
482@end defun
483
484@defun dbus-unregister-signal object
485
486Unregister @var{object} from the the D-Bus. @var{object} must be the
487result of a preceding @code{dbus-register-signal} call.
488@end defun
489
490
491@node Errors and Events
492@chapter Errors and events.
493@cindex errors
494@cindex events
495
496All errors raised by D-Bus are signaled with the error symbol
497@code{dbus-error}. As usual, such an error can be trapped with a
498@code{condition-case} form. If possible, error messages from D-Bus
499are appended to the @code{dbus-error}.
500
501Incoming D-Bus messages are handled as Emacs event (see @pxref{Misc
502Events, , , elisp}). The generated event has this form:
503
504@example
505(dbus-event @var{symbol} @var{service} @var{path} &rest @var{args})
506@end example
507
508@var{symbol} is the interned Lisp symbol which has been generated
509during signal registration (see @pxref{Signals}). Its function cell
510is the argument @var{handler}, the callback function which was
511provided by @code{dbus-register-signal}. When a @code{dbus-event}
512event arrives, @var{handler} is called with @var{args} as arguments.
513
514@var{service} and @var{path} are the unique name and the object path
515of the D-Bus object emitting the signal.
516
517In order to inspect the @code{dbus-event} data, you could extend the
518definition of the callback function in @ref{Signals}:
519
520@example
521(defun my-dbus-signal-handler (&rest args)
522 (message "my-dbus-signal-handler: %S" last-input-event))
523@end example
524
525There exist convenience functions which could be called inside a
526callback function in order to retrieve the information from the event.
527
528@defun dbus-event-bus-name event
529
530Returns the bus name @var{event} is coming from.
531The result is either the symbol @code{:system} or the symbol @code{:session}.
532@end defun
533
534@defun dbus-event-service-name event
535
536Returns the unique name of the D-Bus object @var{event} is coming from.
537@end defun
538
539@defun dbus-event-path-name event
540
541Returns the object path of the D-Bus object @var{event} is coming from.
542@end defun
543
544@defun dbus-event-interface-name event
545
546Returns the interface name of of the D-Bus object @var{event} is coming from.
547@end defun
548
549@defun dbus-event-member-name event
550
551Returns the member name of of the D-Bus object @var{event} is coming
552from. It is either a signal name or a method name.
553@end defun
554
555
556@node GNU Free Documentation License
557@appendix GNU Free Documentation License
558@include doclicense.texi
559
560@contents
561@c End of dbus.texi
562@bye