1 \input texinfo @c -*-texinfo-*-
2 @setfilename ../../info/dbus
4 @settitle Using of D-Bus
5 @c @setchapternewpage odd
9 Copyright @copyright{} 2007, 2008 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.2 or
14 any later version published by the Free Software Foundation; with no
15 Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
16 and with the Back-Cover Texts as in (a) below. A copy of the license
17 is included in the section entitled ``GNU Free Documentation License''.
19 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
20 modify this GNU manual. Buying copies from the FSF supports it in
21 developing GNU and promoting software freedom.''
27 * D-Bus: (dbus). Using D-Bus in Emacs.
31 @node Top, Overview, (dir), (dir)
32 @top D-Bus integration in Emacs
34 This manual documents an API for usage of D-Bus in
35 Emacs.@footnote{D-Bus is not enabled by default. You must run
36 @command{./configure --with-dbus} in Emacs' top level directory,
37 before you compile Emacs.} D-Bus is a message bus system, a simple
38 way for applications to talk to one another. An overview of D-Bus can
39 be found at @uref{http://dbus.freedesktop.org/}.
44 * Overview:: An overview of D-Bus.
45 * Inspection:: Inspection of D-Bus services.
46 * Type Conversion:: Mapping Lisp types and D-Bus types.
47 * Synchronous Methods:: Calling methods in a blocking way.
48 * Receiving Method Calls:: Offering own methods.
49 * Signals:: Sending and receiving signals.
50 * Errors and Events:: Errors and events.
51 * GNU Free Documentation License:: The license for this documentation.
56 @chapter An overview of D-Bus
59 D-Bus is an inter-process communication mechanism for applications
60 residing on the same host. The communication is based on
61 @dfn{messages}. Data in the messages is carried in a structured way,
62 it is not just a byte stream.
64 The communication is connection oriented to two kinds of message
65 buses: a so called @dfn{system bus}, and a @dfn{session bus}. On a
66 given machine, there is always one single system bus for miscellaneous
67 system-wide communication, like changing of hardware configuration.
68 On the other hand, the session bus is always related to a single
71 Every client application, which is connected to a bus, registers under
72 a @dfn{unique name} at the bus. This name is used for identifying the
73 client application. Such a unique name starts always with a colon,
74 and looks like @samp{:1.42}.
76 Additionally, a client application can register itself to a so called
77 @dfn{known name}, which is a series of identifiers separated by dots,
78 as in @samp{org.gnu.Emacs}. If several applications register to the
79 same known name, these registrations are queued, and only the first
80 application which has registered for the known name is reachable via
81 this name. If this application disconnects from the bus, the next
82 queued unique name becomes the owner of this known name.
84 An application can install one or several objects under its name.
85 Such objects are identified by an @dfn{object path}, which looks
86 similar to paths in a filesystem. An example of such an object path
87 could be @samp{/org/gnu/Emacs/}.
89 Applications might send a request to an object, that means sending a
90 message with some data as input parameters, and receiving a message
91 from that object with the result of this message, the output
92 parameters. Such a request is called @dfn{method} in D-Bus.
94 The other form of communication are @dfn{signals}. The underlying
95 message is emitted from an object and will be received by all other
96 applications which have registered for such a signal.
98 All methods and signals an object supports are called @dfn{interface}
99 of the object. Interfaces are specified under a hierarchical name in
100 D-Bus; an object can support several interfaces. Such an interface
101 name could be @samp{org.gnu.Emacs.TextEditor} or
102 @samp{org.gnu.Emacs.FileManager}.
106 @chapter Inspection of D-Bus services.
110 * Bus names:: Discovering D-Bus names.
111 * Introspection:: Knowing the details of D-Bus services.
112 * Nodes and Interfaces:: Detecting object paths and interfaces.
113 * Methods and Signal:: Applying the functionality.
114 * Properties and Annotations:: What else to know about interfaces.
115 * Arguments and Signatures:: The final details.
122 There are several basic functions which inspect the buses for
123 registered names. Internally they use the basic interface
124 @samp{org.freedesktop.DBus}, which is supported by all objects of a bus.
126 @defun dbus-list-activatable-names
127 This function returns the D-Bus service names, which can be activated.
128 An activatable service is described in a service registration file.
129 Under GNU/Linux, such files are located at
130 @file{/usr/share/dbus-1/services/}.
132 The result is a list of strings, which is @code{nil} when there are no
133 activatable service names at all.
136 @defun dbus-list-names bus
137 All service names, which are registered at D-Bus @var{bus}, are
138 returned. The result is a list of strings, which is @code{nil} when
139 there are no registered service names at all. Well known names are
140 strings like @samp{org.freedesktop.DBus}. Names starting with
141 @samp{:} are unique names for services.
143 @var{bus} must be either the symbol @code{:system} or the symbol
147 @defun dbus-list-known-names bus
148 Retrieves all services which correspond to a known name in @var{bus}.
149 A service has a known name if it doesn't start with @samp{:}. The
150 result is a list of strings, which is @code{nil} when there are no
153 @var{bus} must be either the symbol @code{:system} or the symbol
157 @defun dbus-list-queued-owners bus service
158 For a given service, registered at D-Bus @var{bus} under the name
159 @var{service}, all queued unique names are returned. The result is a
160 list of strings, or @code{nil} when there are no queued names for
161 @var{service} at all.
163 @var{bus} must be either the symbol @code{:system} or the symbol
164 @code{:session}. @var{service} must be a known service name as
168 @defun dbus-get-name-owner bus service
169 For a given service, registered at D-Bus @var{bus} under the name
170 @var{service}, the unique name of the name owner is returned. The
171 result is a string, or @code{nil} when there exist no name owner of
174 @var{bus} must be either the symbol @code{:system} or the symbol
175 @code{:session}. @var{service} must be a known service name as
179 @defun dbus-ping bus service
180 Check whether the service name @var{service} is registered at D-Bus
181 @var{bus}. @var{service} might not have been started yet. The result
182 is either @code{t} or @code{nil}.
184 @var{bus} must be either the symbol @code{:system} or the symbol
185 @code{:session}. @var{service} must be a string. Example:
189 "%s screensaver on board."
191 ((dbus-ping :session "org.gnome.ScreenSaver") "Gnome")
192 ((dbus-ping :session "org.freedesktop.ScreenSaver") "KDE")
197 @defun dbus-get-unique-name bus
198 The unique name, under which Emacs is registered at D-Bus @var{bus},
199 is returned as string.
201 @var{bus} must be either the symbol @code{:system} or the symbol
207 @section Knowing the details of D-Bus services.
209 D-Bus services publish their interfaces. This can be retrieved and
210 analyzed during runtime, in order to understand the used
213 The resulting introspection data are in XML format. The root
214 introspection element is always a @code{node} element. It might have
215 a @code{name} attribute, which denotes the (absolute) object path an
216 interface is introspected.
218 The root @code{node} element may have @code{node} and @code{interface}
219 children. A child @code{node} element must have a @code{name}
220 attribute, this case it is the relative object path to the root
223 An @code{interface} element has just one attribute, @code{name}, which
224 is the full name of that interface. The default interface
225 @samp{org.freedesktop.DBus.Introspectable} is always present. Example:
228 <node name="/org/bluez">
229 <interface name="org.freedesktop.DBus.Introspectable">
232 <interface name="org.bluez.Manager">
235 <interface name="org.bluez.Database">
238 <interface name="org.bluez.Security">
241 <node name="service_audio"/>
242 <node name="service_input"/>
243 <node name="service_network"/>
244 <node name="service_serial"/>
248 Children of an @code{interface} element can be @code{method},
249 @code{signal} and @code{property} elements. A @code{method} element
250 stands for a D-Bus method of the surrounding interface. The element
251 itself has a @code{name} attribute, showing the method name. Children
252 elements @code{arg} stand for the arguments of a method. Example:
255 <method name="ResolveHostName">
256 <arg name="interface" type="i" direction="in"/>
257 <arg name="protocol" type="i" direction="in"/>
258 <arg name="name" type="s" direction="in"/>
259 <arg name="aprotocol" type="i" direction="in"/>
260 <arg name="flags" type="u" direction="in"/>
261 <arg name="interface" type="i" direction="out"/>
262 <arg name="protocol" type="i" direction="out"/>
263 <arg name="name" type="s" direction="out"/>
264 <arg name="aprotocol" type="i" direction="out"/>
265 <arg name="address" type="s" direction="out"/>
266 <arg name="flags" type="u" direction="out"/>
270 @code{arg} elements can have the attributes @code{name}, @code{type}
271 and @code{direction}. The @code{name} attribute is optional. The
272 @code{type} attribute stands for the @dfn{signature} of the argument
273 in D-Bus. For a discussion of D-Bus types and their Lisp
274 representation see @ref{Type Conversion}.@footnote{D-Bus signatures
275 are explained in the D-Bus specification
276 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures}.}
277 The @code{direction} attribute of an @code{arg} element can be only
278 @samp{in} or @samp{out}; in case it is omitted, it defaults to
281 A @code{signal} element of an @code{interface} has a similar
282 structure. The @code{direction} attribute of an @code{arg} child
283 element can be only @samp{out} here; which is also the default value.
287 <signal name="StateChanged">
288 <arg name="state" type="i"/>
289 <arg name="error" type="s"/>
293 A @code{property} element has no @code{arg} child
294 element. It just has the attributes @code{name}, @code{type} and
295 @code{access}, which are all mandatory. The @code{access} attribute
296 allows the values @samp{readwrite}, @samp{read}, and @samp{write}.
300 <property name="Status" type="u" direction="read"/>
303 @code{annotation} elements can be children of @code{interface},
304 @code{method}, @code{signal}, and @code{property} elements. Unlike
305 properties, which can change their values during lifetime of a D-Bus
306 object, annotations are static. Often they are used for code
307 generators of D-Bus langugae bindings. Example:
310 <annotation name="de.berlios.Pinot.GetStatistics" value="pinotDBus"/>
313 Annotations have just @code{name} and @code{value} attributes, both
316 @defun dbus-introspect bus service path
317 This function returns all interfaces and sub-nodes of @var{service},
318 registered at object path @var{path} at bus @var{bus}.
320 @var{bus} must be either the symbol @code{:system} or the symbol
321 @code{:session}. @var{service} must be a known service name, and
322 @var{path} must be a valid object path. The last two parameters are
323 strings. The result, the introspection data, is a string in XML
328 :system "org.freedesktop.Hal"
329 "/org/freedesktop/Hal/devices/computer")
331 @result{} "<!DOCTYPE node PUBLIC
332 "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
333 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
335 <interface name="org.freedesktop.Hal.Device">
336 <method name="GetAllProperties">
337 <arg name="properties" direction="out" type="a@{sv@}"/>
340 <signal name="PropertyModified">
341 <arg name="num_updates" type="i"/>
342 <arg name="updates" type="a(sbb)"/>
349 This example informs us, that the service @samp{org.freedesktop.Hal}
350 at object path @samp{/org/freedesktop/Hal/devices/computer} offers the
351 interface @samp{org.freedesktop.Hal.Device} (and 2 other interfaces
352 not documented here). This interface contains the method
353 @samp{GetAllProperties}, which needs no input parameters, but returns
354 as output parameter an array of dictionary entries (key-value pairs).
355 Every dictionary entry has a string as key, and a variant as value.
357 The interface offers also a signal, which returns 2 parameters: an
358 integer, and an array consisting of elements which are a struct of a
359 string and 2 boolean values.@footnote{ The interfaces of the service
360 @samp{org.freedesktop.Hal} are described at
361 @uref{http://people.freedesktop.org/~david/hal-spec/hal-spec.html#interfaces}.}
364 @defun dbus-introspect-xml bus service path
365 This function has the same intention as function
366 @code{dbus-introspect}. The returned value is a parsed XML tree,
367 which can be used for further analysis. Example:
371 :session "org.freedesktop.xesam.searcher"
372 "/org/freedesktop/xesam/searcher/main")
374 @result{} (node ((name . "/org/freedesktop/xesam/searcher/main"))
375 (interface ((name . "org.freedesktop.xesam.Search"))
376 (method ((name . "GetHitData"))
377 (arg ((name . "search") (type . "s") (direction . "in")))
378 (arg ((name . "hit_ids") (type . "au") (direction . "in")))
379 (arg ((name . "fields") (type . "as") (direction . "in")))
380 (arg ((name . "hit_data") (type . "aav") (direction . "out")))
383 (signal ((name . "HitsAdded"))
384 (arg ((name . "search") (type . "s")))
385 (arg ((name . "count") (type . "u")))
393 @defun dbus-introspect-get-attribute object attribute
394 It returns the @var{attribute} value of a D-Bus introspection
395 @var{object}. @var{object} can be every subtree of a parsed XML tree
396 as retrieved with @code{dbus-introspect-xml}. @var{attribute} must be
397 a string according to the attribute names in the D-Bus specification.
401 (dbus-introspect-get-attribute
402 (dbus-introspect-xml :system "org.freedesktop.SystemToolsBackends"
403 "/org/freedesktop/SystemToolsBackends/UsersConfig")
406 @result{} "/org/freedesktop/SystemToolsBackends/UsersConfig"
409 If @var{object} has no @var{attribute}, the function returns nil.
413 @node Nodes and Interfaces
414 @section Detecting object paths and interfaces.
416 The first elements, to be introspected for a D-Bus object, are further
417 object paths and interfaces.
419 @defun dbus-introspect-get-node-names bus service path
420 All node names of @var{service} in D-Bus @var{bus} at object path
421 @var{path} are returned as list of strings. Example:
424 (dbus-introspect-get-node-names
425 :session "org.gnome.seahorse" "/org/gnome/seahorse")
427 @result{} ("crypto" "keys")
430 The node names stand for further object paths of the D-Bus
431 @var{service}, relative to @var{path}. In the example,
432 @samp{/org/gnome/seahorse/crypto} and @samp{/org/gnome/seahorse/keys}
433 are also object paths of the D-Bus service @samp{org.gnome.seahorse}.
436 @defun dbus-introspect-get-all-nodes bus service path
437 This function returns all node names of @var{service} in D-Bus
438 @var{bus} at object path @var{path}. It returns a list of strings
439 with all object paths of @var{service}, starting at @var{path}.
443 (dbus-introspect-get-all-nodes :session "org.gnome.seahorse" "/")
445 @result{} ("/" "/org" "/org/gnome" "/org/gnome/seahorse"
446 "/org/gnome/seahorse/crypto"
447 "/org/gnome/seahorse/keys"
448 "/org/gnome/seahorse/keys/openpgp"
449 "/org/gnome/seahorse/keys/openpgp/local"
450 "/org/gnome/seahorse/keys/openssh"
451 "/org/gnome/seahorse/keys/openssh/local")
455 @defun dbus-introspect-get-interface-names bus service path
456 There will be returned a list strings of all interface names of
457 @var{service} in D-Bus @var{bus} at object path @var{path}. This list
458 will contain the default interface @samp{org.freedesktop.DBus.Introspectable}.
460 Another default interface is @samp{org.freedesktop.DBus.Properties}.
461 If present, @code{interface} elements can also have @code{property}
465 (dbus-introspect-get-interface-names
466 :system "org.freedesktop.Hal"
467 "/org/freedesktop/Hal/devices/computer")
469 @result{} ("org.freedesktop.DBus.Introspectable"
470 "org.freedesktop.Hal.Device"
471 "org.freedesktop.Hal.Device.SystemPowerManagement"
472 "org.freedesktop.Hal.Device.CPUFreq")
476 @defun dbus-introspect-get-interface bus service path interface
477 Return @var{interface} of @var{service} in D-Bus @var{bus} at object
478 path @var{path}. The return value is an XML element. @var{interface}
479 must be a string, element of the list returned by
480 @code{dbus-introspect-get-interface-names}. Example:
483 (dbus-introspect-get-interface
484 :session "org.freedesktop.xesam.searcher"
485 "/org/freedesktop/xesam/searcher/main"
486 "org.freedesktop.xesam.Search")
488 @result{} (interface ((name . "org.freedesktop.xesam.Search"))
489 (method ((name . "GetHitData"))
490 (arg ((name . "search") (type . "s") (direction . "in")))
491 (arg ((name . "hit_ids") (type . "au") (direction . "in")))
492 (arg ((name . "fields") (type . "as") (direction . "in")))
493 (arg ((name . "hit_data") (type . "aav") (direction . "out")))
496 (signal ((name . "HitsAdded"))
497 (arg ((name . "search") (type . "s")))
498 (arg ((name . "count") (type . "u")))
505 With these functions, it is possible to retrieve all introspection
506 data from a running system:
509 (with-current-buffer (switch-to-buffer "*introspect*")
511 (dolist (service (dbus-list-known-names :session))
512 (dolist (path (dbus-introspect-get-all-nodes :session service "/"))
513 ;; We want to introspect only elements, which have more than
514 ;; the default interface "org.freedesktop.DBus.Introspectable".
516 "org.freedesktop.DBus.Introspectable"
517 (dbus-introspect-get-interface-names :session service path))
518 (insert (message "\nservice: \"%s\" path: \"%s\"\n" service path)
519 (dbus-introspect :session service path))
524 @node Methods and Signal
525 @section Applying the functionality.
527 Methods and signals are the communicatione means to D-Bus. The
528 following functions return their specifications.
530 @defun dbus-introspect-get-method-names bus service path interface
531 Return a list of strings of all method names of @var{interface} of
532 @var{service} in D-Bus @var{bus} at object path @var{path}. Example:
535 (dbus-introspect-get-method-names
536 :session "org.freedesktop.xesam.searcher"
537 "/org/freedesktop/xesam/searcher/main"
538 "org.freedesktop.xesam.Search")
540 @result{} ("GetState" "StartSearch" "GetHitCount" "GetHits" "NewSession"
541 "CloseSession" "GetHitData" "SetProperty" "NewSearch"
542 "GetProperty" "CloseSearch")
546 @defun dbus-introspect-get-method bus service path interface method
547 This function returns @var{method} of @var{interface} as XML element.
548 It must be located at @var{service} in D-Bus @var{bus} at object path
549 @var{path}. @var{method} must be a string, element of the list
550 returned by @code{dbus-introspect-get-method-names}. Example:
553 (dbus-introspect-get-method
554 :session "org.freedesktop.xesam.searcher"
555 "/org/freedesktop/xesam/searcher/main"
556 "org.freedesktop.xesam.Search" "GetHitData")
558 @result{} (method ((name . "GetHitData"))
559 (arg ((name . "search") (type . "s") (direction . "in")))
560 (arg ((name . "hit_ids") (type . "au") (direction . "in")))
561 (arg ((name . "fields") (type . "as") (direction . "in")))
562 (arg ((name . "hit_data") (type . "aav") (direction . "out")))
567 @defun dbus-introspect-get-signal-names bus service path interface
568 Return a list of strings of all signal names of @var{interface} of
569 @var{service} in D-Bus @var{bus} at object path @var{path}. Example:
572 (dbus-introspect-get-signal-names
573 :session "org.freedesktop.xesam.searcher"
574 "/org/freedesktop/xesam/searcher/main"
575 "org.freedesktop.xesam.Search")
577 @result{} ("StateChanged" "SearchDone" "HitsModified"
578 "HitsRemoved" "HitsAdded")
582 @defun dbus-introspect-get-signal bus service path interface signal
583 This function returns @var{signal} of @var{interface} as XML element.
584 It must be located at @var{service} in D-Bus @var{bus} at object path
585 @var{path}. @var{signal} must be a string, element of the list
586 returned by @code{dbus-introspect-get-signal-names}. Example:
589 (dbus-introspect-get-signal
590 :session "org.freedesktop.xesam.searcher"
591 "/org/freedesktop/xesam/searcher/main"
592 "org.freedesktop.xesam.Search" "HitsAdded")
594 @result{} (signal ((name . "HitsAdded"))
595 (arg ((name . "search") (type . "s")))
596 (arg ((name . "count") (type . "u")))
602 @node Properties and Annotations
603 @section What else to know about interfaces.
605 Interfaces can have properties. These can be exposed via the
606 @samp{org.freedesktop.DBus.Properties} interface@footnote{See
607 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties}}.
608 That is, properties can be retrieved and changed during lifetime of an
611 Annotations, on the other hand, are static values for an element.
612 Often, they are used to instruct generators, how to generate code from
613 the interface for a given language binding.
615 @defun dbus-introspect-get-property-names bus service path interface
616 Return a list of strings with all property names of @var{interface} of
617 @var{service} in D-Bus @var{bus} at object path @var{path}. Example:
620 (dbus-introspect-get-property-names
621 :session "org.kde.kded" "/modules/networkstatus"
622 "org.kde.Solid.Networking.Client")
627 If an interface declares properties, the corresponding element supports
628 also the @samp{org.freedesktop.DBus.Properties} interface.
631 @defun dbus-introspect-get-property bus service path interface property
632 This function returns @var{property} of @var{interface} as XML element.
633 It must be located at @var{service} in D-Bus @var{bus} at object path
634 @var{path}. @var{property} must be a string, element of the list
635 returned by @code{dbus-introspect-get-property-names}.
637 A @var{property} value can be retrieved by the function
638 @code{dbus-introspect-get-attribute}. Example:
641 (dbus-introspect-get-property
642 :session "org.kde.kded" "/modules/networkstatus"
643 "org.kde.Solid.Networking.Client" "Status")
645 @result{} (property ((access . "read") (type . "u") (name . "Status")))
647 (dbus-introspect-get-attribute
648 (dbus-introspect-get-property
649 :session "org.kde.kded" "/modules/networkstatus"
650 "org.kde.Solid.Networking.Client" "Status")
657 @defun dbus-get-property bus service path interface property
658 This function returns the value of @var{property} of @var{interface}.
659 It will be checked at @var{bus}, @var{service}, @var{path}. The
660 result can be any valid D-Bus value, or nil if there is no
661 @var{property}. Example:
665 :session "org.kde.kded" "/modules/networkstatus"
666 "org.kde.Solid.Networking.Client" "Status")
672 @defun dbus-set-property bus service path interface property value
673 Set value of @var{property} of @var{interface} to @var{value}. It
674 will be checked at @var{bus}, @var{service}, @var{path}. When the
675 value has been set successful, the result is @var{value}. Otherwise,
676 @code{nil} is returned. Example:
680 :session "org.kde.kaccess" "/MainApplication"
681 "com.trolltech.Qt.QApplication" "doubleClickInterval" 500)
687 @defun dbus-get-all-properties bus service path interface
688 This function returns all properties of @var{interface}. It will be
689 checked at @var{bus}, @var{service}, @var{path}. The result is a list
690 of cons. Every cons contains the name of the property, and its value.
691 If there are no properties, @code{nil} is returned. Example:
694 (dbus-get-all-properties
695 :session "org.kde.kaccess" "/MainApplication"
696 "com.trolltech.Qt.QApplication")
698 @result{} (("cursorFlashTime" . 1000) ("doubleClickInterval" . 500)
699 ("keyboardInputInterval" . 400) ("wheelScrollLines" . 3)
700 ("globalStrut" 0 0) ("startDragTime" . 500)
701 ("startDragDistance" . 4) ("quitOnLastWindowClosed" . t)
706 @defun dbus-introspect-get-annotation-names bus service path interface &optional name
707 Return a list of all annotation names as list of strings. If
708 @var{name} is @code{nil}, the annotations are children of
709 @var{interface}, otherwise @var{name} must be a @code{method},
710 @code{signal}, or @code{property} XML element, where the annotations
714 (dbus-introspect-get-annotation-names
715 :session "de.berlios.Pinot" "/de/berlios/Pinot"
716 "de.berlios.Pinot" "GetStatistics")
718 @result{} ("de.berlios.Pinot.GetStatistics")
721 Default annotation names@footnote{See
722 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format}}
726 @item org.freedesktop.DBus.Deprecated
727 Whether or not the entity is deprecated; defaults to @code{nil}
729 @item org.freedesktop.DBus.GLib.CSymbol
730 The C symbol; may be used for @code{methods} and @code{interfaces}
732 @item org.freedesktop.DBus.Method.NoReply
733 If set, don't expect a reply to the @code{method} call; defaults to @code{nil}
737 @defun dbus-introspect-get-annotation bus service path interface name annotation
738 Return annotation @var{ANNOTATION} as XML object. If @var{name} is
739 @code{nil}, @var{ANNOTATION} is a child of @var{interface}, otherwise
740 @var{name} must be the name of a @code{method}, @code{signal}, or
741 @code{property} XML element, where the @var{ANNOTATION} belongs to.
743 An attribute value can be retrieved by
744 @code{dbus-introspect-get-attribute}. Example:
747 (dbus-introspect-get-annotation
748 :session "de.berlios.Pinot" "/de/berlios/Pinot"
749 "de.berlios.Pinot" "GetStatistics"
750 "de.berlios.Pinot.GetStatistics")
752 @result{} (annotation ((name . "de.berlios.Pinot.GetStatistics")
753 (value . "pinotDBus")))
755 (dbus-introspect-get-attribute
756 (dbus-introspect-get-annotation
757 :session "de.berlios.Pinot" "/de/berlios/Pinot"
758 "de.berlios.Pinot" "GetStatistics"
759 "de.berlios.Pinot.GetStatistics")
762 @result{} "pinotDBus"
767 @node Arguments and Signatures
768 @section The final details.
770 Methods and signals have arguments. They are described in the
771 @code{arg} XML elements.
773 @defun dbus-introspect-get-argument-names bus service path interface name
774 Return a list of all argument names as list of strings. @var{name}
775 must be a @code{method} or @code{signal} XML element. Example:
778 (dbus-introspect-get-argument-names
779 :session "org.freedesktop.xesam.searcher"
780 "/org/freedesktop/xesam/searcher/main"
781 "org.freedesktop.xesam.Search" "GetHitData")
783 @result{} ("search" "hit_ids" "fields" "hit_data")
786 Argument names are optional; the function can return @code{nil}
787 therefore, even if the method or signal has arguments.
790 @defun dbus-introspect-get-argument bus service path interface name arg
791 Return argument @var{ARG} as XML object. @var{name}
792 must be a @code{method} or @code{signal} XML element. Example:
795 (dbus-introspect-get-argument
796 :session "org.freedesktop.xesam.searcher"
797 "/org/freedesktop/xesam/searcher/main"
798 "org.freedesktop.xesam.Search" "GetHitData" "search")
800 @result{} (arg ((name . "search") (type . "s") (direction . "in")))
804 @defun dbus-introspect-get-signature bus service path interface name &optional direction
805 Return signature of a @code{method} or @code{signal}, represented by
806 @var{name}, as string.
808 If @var{name} is a @code{method}, @var{direction} can be either
809 @samp{in} or @samp{out}. If @var{direction} is @code{nil}, @samp{in}
812 If @var{name} is a @code{signal}, and @var{direction} is
813 non-@code{nil}, @var{direction} must be @samp{out}. Example:
816 (dbus-introspect-get-signature
817 :session "org.freedesktop.xesam.searcher"
818 "/org/freedesktop/xesam/searcher/main"
819 "org.freedesktop.xesam.Search" "GetHitData" "in")
823 (dbus-introspect-get-signature
824 :session "org.freedesktop.xesam.searcher"
825 "/org/freedesktop/xesam/searcher/main"
826 "org.freedesktop.xesam.Search" "HitsAdded")
833 @node Type Conversion
834 @chapter Mapping Lisp types and D-Bus types.
835 @cindex type conversion
837 D-Bus method calls and signals accept usually several arguments as
838 parameters, either as input parameter, or as output parameter. Every
839 argument belongs to a D-Bus type.
841 Such arguments must be mapped between the value encoded as a D-Bus
842 type, and the corresponding type of Lisp objects. The mapping is
843 applied Lisp object @expansion{} D-Bus type for input parameters, and
844 D-Bus type @expansion{} Lisp object for output parameters.
847 @section Input parameters.
849 Input parameters for D-Bus methods and signals occur as arguments of a
850 Lisp function call. The following mapping to D-Bus types is
851 applied, when the corresponding D-Bus message is created:
854 @multitable {@code{t} and @code{nil}} {@expansion{}} {DBUS_TYPE_BOOLEAN}
855 @item Lisp type @tab @tab D-Bus type
857 @item @code{t} and @code{nil} @tab @expansion{} @tab DBUS_TYPE_BOOLEAN
858 @item number @tab @expansion{} @tab DBUS_TYPE_UINT32
859 @item integer @tab @expansion{} @tab DBUS_TYPE_INT32
860 @item float @tab @expansion{} @tab DBUS_TYPE_DOUBLE
861 @item string @tab @expansion{} @tab DBUS_TYPE_STRING
862 @item list @tab @expansion{} @tab DBUS_TYPE_ARRAY
866 Other Lisp objects, like symbols or hash tables, are not accepted as
869 If it is necessary to use another D-Bus type, a corresponding type
870 symbol can be preceeded to the corresponding Lisp object. Basic D-Bus
871 types are represented by the type symbols @code{:byte},
872 @code{:boolean}, @code{:int16}, @code{:uint16}, @code{:int32},
873 @code{:uint32}, @code{:int64}, @code{:uint64}, @code{:double},
874 @code{:string}, @code{:object-path} and @code{:signature}.
880 (dbus-call-method @dots{} @var{NUMBER} @var{STRING})
886 (dbus-call-method @dots{} :uint32 @var{NUMBER} :string @var{STRING})
892 (dbus-call-method @dots{} :int32 @var{NUMBER} :signature @var{STRING})
895 The value for a byte D-Bus type can be any integer in the range 0
896 through 255. If a character is used as argument, modifiers
897 represented outside this range are stripped of. For example,
898 @code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to
899 @code{:byte ?\C-x} or @code{:byte ?\M-\C-x}.
901 A D-Bus compound type is always represented as a list. The @sc{car}
902 of this list can be the type symbol @code{:array}, @code{:variant},
903 @code{:struct} or @code{:dict-entry}, which would result in a
904 corresponding D-Bus container. @code{:array} is optional, because
905 this is the default compound D-Bus type for a list.
907 The objects being elements of the list are checked according to the
908 D-Bus compound type rules.
911 @item An array must contain only elements of the same D-Bus type. It
914 @item A variant must contain only one single element.
916 @item A dictionary entry must be element of an array, and it must
917 contain only a key-value pair of two elements, with a basic D-Bus type
920 @item There is no restriction for structs.
923 If an empty array needs an element D-Bus type other than string, it
924 can contain exactly one element of D-Bus type @code{:signature}. The
925 value of this element (a string) is used as the signature of the
926 elements of this array. Example:
930 :session "org.freedesktop.Notifications"
931 "/org/freedesktop/Notifications"
932 "org.freedesktop.Notifications" "Notify"
933 "GNU Emacs" ;; Application name.
934 0 ;; No replacement of other notifications.
936 "Notification summary" ;; Summary.
938 "This is a test notification, raised from %s" (emacs-version))
939 '(:array) ;; No actions (empty array of strings).
940 '(:array :signature "@{sv@}") ;; No hints
941 ;; (empty array of dictionary entries).
942 ':int32 -1) ;; Default timeout.
948 @section Output parameters.
950 Output parameters of D-Bus methods and signals are mapped to Lisp
954 @multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {@code{t} or @code{nil}}
955 @item D-Bus type @tab @tab Lisp type
957 @item DBUS_TYPE_BOOLEAN @tab @expansion{} @tab @code{t} or @code{nil}
958 @item DBUS_TYPE_BYTE @tab @expansion{} @tab number
959 @item DBUS_TYPE_UINT16 @tab @expansion{} @tab number
960 @item DBUS_TYPE_INT16 @tab @expansion{} @tab number
961 @item DBUS_TYPE_UINT32 @tab @expansion{} @tab number or float
962 @item DBUS_TYPE_INT32 @tab @expansion{} @tab number or float
963 @item DBUS_TYPE_UINT64 @tab @expansion{} @tab number or float
964 @item DBUS_TYPE_INT64 @tab @expansion{} @tab number or float
965 @item DBUS_TYPE_DOUBLE @tab @expansion{} @tab float
966 @item DBUS_TYPE_STRING @tab @expansion{} @tab string
967 @item DBUS_TYPE_OBJECT_PATH @tab @expansion{} @tab string
968 @item DBUS_TYPE_SIGNATURE @tab @expansion{} @tab string
969 @item DBUS_TYPE_ARRAY @tab @expansion{} @tab list
970 @item DBUS_TYPE_VARIANT @tab @expansion{} @tab list
971 @item DBUS_TYPE_STRUCT @tab @expansion{} @tab list
972 @item DBUS_TYPE_DICT_ENTRY @tab @expansion{} @tab list
976 A float object in case of @code{DBUS_TYPE_UINT32},
977 @code{DBUS_TYPE_INT32}, @code{DBUS_TYPE_UINT64} and
978 @code{DBUS_TYPE_INT6432} is returned, when the C value exceeds the
979 Emacs number size range.
981 The resulting list of the last 4 D-Bus compound types contains as
982 elements the elements of the D-Bus container, mapped according to the
985 The signal @code{PropertyModified}, discussed as example in
986 @ref{Inspection}, would offer as Lisp data the following object
987 (@var{BOOL} stands here for either @code{nil} or @code{t}):
990 (@var{NUMBER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
994 @node Synchronous Methods
995 @chapter Calling methods in a blocking way.
996 @cindex method calls, synchronous
997 @cindex synchronous method calls
999 Methods can be called synchronously (@dfn{blocking}) or asynchronously
1000 (@dfn{non-blocking}). Currently, just synchronous methods are
1003 At D-Bus level, a method call consist of two messages: one message
1004 which carries the input parameters to the object owning the method to
1005 be called, and a reply message returning the resulting output
1006 parameters from the object.
1008 @defun dbus-call-method bus service path interface method &optional :timeout timeout &rest args
1009 This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is
1010 either the symbol @code{:system} or the symbol @code{:session}.
1012 @var{service} is the D-Bus service name to be used. @var{path} is the
1013 D-Bus object path, @var{service} is registered at. @var{interface} is
1014 an interface offered by @var{service}. It must provide @var{method}.
1016 If the parameter @code{:timeout} is given, the following integer
1017 @var{timeout} specifies the maximun number of milliseconds the method
1018 call must return. The default value is 25.000. If the method call
1019 doesn't return in time, a D-Bus error is raised (@pxref{Errors and
1022 All other arguments args are passed to @var{method} as arguments.
1023 They are converted into D-Bus types as described in @ref{Type
1026 The function returns the resulting values of @var{method} as a list of
1027 Lisp objects, according to the type conversion rules described in
1028 @ref{Type Conversion}. Example:
1032 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
1033 "org.gnome.seahorse.Keys" "GetKeyField"
1034 "openpgp:657984B8C7A966DD" "simple-name")
1036 @result{} (t ("Philip R. Zimmermann"))
1039 If the result of the method call is just one value, the converted Lisp
1040 object is returned instead of a list containing this single Lisp
1045 :system "org.freedesktop.Hal"
1046 "/org/freedesktop/Hal/devices/computer"
1047 "org.freedesktop.Hal.Device" "GetPropertyString"
1048 "system.kernel.machine")
1053 With the @code{dbus-introspect} function it is possible to explore the
1054 interfaces of @samp{org.freedesktop.Hal} service. It offers the
1055 interfaces @samp{org.freedesktop.Hal.Manager} for the object at the
1056 path @samp{/org/freedesktop/Hal/Manager} as well as the interface
1057 @samp{org.freedesktop.Hal.Device} for all objects prefixed with the
1058 path @samp{/org/freedesktop/Hal/devices}. With the methods
1059 @samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to
1060 emulate the @code{lshal} command on GNU/Linux systems:
1065 :system "org.freedesktop.Hal"
1066 "/org/freedesktop/Hal/Manager"
1067 "org.freedesktop.Hal.Manager" "GetAllDevices"))
1068 (message "\nudi = %s" device)
1071 :system "org.freedesktop.Hal" device
1072 "org.freedesktop.Hal.Device" "GetAllProperties"))
1074 (car properties) (or (caar (cdr properties)) ""))))
1076 @print{} "udi = /org/freedesktop/Hal/devices/computer
1077 info.addons = (\"hald-addon-acpi\")
1078 info.bus = \"unknown\"
1079 info.product = \"Computer\"
1080 info.subsystem = \"unknown\"
1081 info.udi = \"/org/freedesktop/Hal/devices/computer\"
1082 linux.sysfs_path_device = \"(none)\"
1083 power_management.acpi.linux.version = \"20051216\"
1084 power_management.can_suspend_to_disk = t
1085 power_management.can_suspend_to_ram = \"\"
1086 power_management.type = \"acpi\"
1087 smbios.bios.release_date = \"11/07/2001\"
1088 system.chassis.manufacturer = \"COMPAL\"
1089 system.chassis.type = \"Notebook\"
1090 system.firmware.release_date = \"03/19/2005\"
1096 @node Receiving Method Calls
1097 @chapter Offering own methods.
1098 @cindex method calls, returning
1099 @cindex returning method calls
1101 Emacs can also offer own methods, which can be called by other
1102 applications. These methods could be an implementation of an
1103 interface of a well known service, like @samp{org.freedesktop.TextEditor}.
1105 It could be also an implementation of an own interface. In this case,
1106 the service name must be @samp{org.gnu.Emacs}. The object path shall
1107 begin with @samp{/org/gnu/Emacs/@strong{Application}/}, and the
1108 interface name shall be @code{org.gnu.Emacs.@strong{Application}}.
1109 @samp{@strong{Application}} is the name of the application which
1110 provides the interface.
1112 @defun dbus-register-method bus service path interface method handler
1113 With this function, an application registers @var{method} on the D-Bus
1116 @var{bus} is either the symbol @code{:system} or the symbol
1119 @var{service} is the D-Bus service name of the D-Bus object
1120 @var{method} is registered for. It must be a known name.
1122 @var{path} is the D-Bus object path @var{service} is
1125 @var{interface} is the interface offered by @var{service}. It must
1126 provide @var{method}.
1128 @var{handler} is a Lisp function to be called when when a @var{method}
1129 call is is received. It must accept as arguments the input arguments
1130 of @var{method}. @var{handler} must return a list, which elements are
1131 used as arguments for the reply message of @var{method}. This list
1132 can be composed like the input parameters in @ref{Type Conversion}.
1134 The default D-Bus timeout when waiting for a message reply is 25
1135 seconds. This value could be even smaller, depending on the calling
1136 client. Therefore, @var{handler} shall not last longer than
1137 absolutely necessary.
1139 @code{dbus-register-method} returns a Lisp object, which can be used
1140 as argument in @code{dbus-unregister-object} for removing the
1141 registration for @var{method}. Example:
1144 (defun my-dbus-method-handler (filename)
1146 (if (find-file filename)
1147 (setq result '(:boolean t))
1148 (setq result '(:boolean nil)))
1151 @result{} my-dbus-method-handler
1153 (dbus-register-method
1154 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1155 "org.freedesktop.TextEditor" "OpenFile"
1156 'my-dbus-method-handler)
1158 @result{} ((:system "org.freedesktop.TextEditor" "OpenFile")
1159 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1163 If you invoke the method @samp{org.freedesktop.TextEditor.OpenFile}
1164 from another D-Bus application with a filename as parameter, the file
1165 is opened in Emacs, and the method returns either @var{true} or
1166 @var{false}, indicating the success if the method. As test tool one
1167 could use the command line tool @code{dbus-send} in a shell:
1170 # dbus-send --session --print-reply \
1171 --dest="org.freedesktop.TextEditor" \
1172 "/org/freedesktop/TextEditor" \
1173 "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts"
1175 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2
1182 @chapter Sending and receiving signals.
1185 Signals are broadcast messages. They carry input parameters, which
1186 are received by all objects which have registered for such a signal.
1188 @defun dbus-send-signal bus service path interface signal &rest args
1189 This function is similar to @code{dbus-call-method}. The difference
1190 is, that there are no returning output parameters.
1192 The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is
1193 either the symbol @code{:system} or the symbol @code{:session}. It
1194 doesn't matter whether another object has registered for @var{signal}.
1196 @var{service} is the D-Bus service name of the object the signal is
1197 emitted from. @var{path} is the corresponding D-Bus object path,
1198 @var{service} is registered at. @var{interface} is an interface
1199 offered by @var{service}. It must provide @var{signal}.
1201 All other arguments args are passed to @var{signal} as arguments.
1202 They are converted into D-Bus types as described in @ref{Type
1203 Conversion}. Example:
1207 :session "org.gnu.Emacs" "/org/gnu/Emacs"
1208 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
1212 @defun dbus-register-signal bus service path interface signal handler &rest args
1213 With this function, an application registers for @var{signal} on the
1216 @var{bus} is either the symbol @code{:system} or the symbol
1219 @var{service} is the D-Bus service name used by the sending D-Bus
1220 object. It can be either a known name or the unique name of the D-Bus
1221 object sending the signal. In case of a unique name, signals won't be
1222 received any longer once the object owning this unique name has
1223 disappeared, and a new queued object has replaced it.
1225 When @var{service} is @code{nil}, related signals from all D-Bus
1226 objects shall be accepted.
1228 @var{path} is the corresponding D-Bus object path, @var{service} is
1229 registered at. It can also be @code{nil} if the path name of incoming
1230 signals shall not be checked.
1232 @var{interface} is an interface offered by @var{service}. It must
1233 provide @var{signal}.
1235 @var{handler} is a Lisp function to be called when the @var{signal} is
1236 received. It must accept as arguments the output parameters
1237 @var{signal} is sending.
1239 All other arguments @var{args}, if specified, must be strings. They
1240 stand for the respective arguments of @var{signal} in their order, and
1241 are used for filtering as well. A @code{nil} argument might be used
1242 to preserve the order.
1244 @code{dbus-register-signal} returns a Lisp object, which can be used
1245 as argument in @code{dbus-unregister-object} for removing the
1246 registration for @var{signal}. Example:
1249 (defun my-dbus-signal-handler (device)
1250 (message "Device %s added" device))
1252 @result{} my-dbus-signal-handler
1254 (dbus-register-signal
1255 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
1256 "org.freedesktop.Hal.Manager" "DeviceAdded"
1257 'my-dbus-signal-handler)
1259 @result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
1260 ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
1264 As we know from the introspection data of interface
1265 @samp{org.freedesktop.Hal.Manager}, the signal @samp{DeviceAdded}
1266 provides one single parameter, which is mapped into a Lisp string.
1267 The callback function @code{my-dbus-signal-handler} must define one
1268 single string argument therefore. Plugging an USB device to your
1269 machine, when registered for signal @samp{DeviceAdded}, will show you
1270 which objects the GNU/Linux @code{hal} daemon adds.
1273 @defun dbus-unregister-object object
1274 Unregister @var{object} from the the D-Bus. @var{object} must be the
1275 result of a preceding @code{dbus-register-signal} or
1276 @code{dbus-register-method} call. It returns @code{t} if @var{object}
1277 has been unregistered, @code{nil} otherwise.
1281 @node Errors and Events
1282 @chapter Errors and events.
1286 Input parameters of @code{dbus-call-method} and
1287 @code{dbus-register-signal} are checked for correct D-Bus types. If
1288 there is a type mismatch, the Lisp error @code{wrong-type-argument}
1289 @code{D-Bus ARG} is raised.
1291 All errors raised by D-Bus are signaled with the error symbol
1292 @code{dbus-error}. If possible, error messages from D-Bus are
1293 appended to the @code{dbus-error}.
1295 @defspec dbus-ignore-errors forms@dots{}
1296 This executes @var{forms} exactly like a @code{progn}, except that
1297 @code{dbus-error} errors are ignored during the @var{forms}. These
1298 errors can be made visible when variable @code{dbus-debug} is set to
1302 Incoming D-Bus messages are handled as Emacs events (see @pxref{Misc
1303 Events, , , elisp}). The generated event has this form:
1306 (dbus-event @var{bus} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler} &rest @var{args})
1309 @var{bus} identifies the D-Bus the signal is coming from. It is
1310 either the symbol @code{:system} or the symbol @code{:session}.
1312 @var{serial} is the serial number of the received D-Bus message if it
1313 is a method call, or @code{nil}.
1315 @var{service} and @var{path} are the unique name and the object path
1316 of the D-Bus object emitting the message. @var{interface} and
1317 @var{member} denote the message which has been sent.
1319 @var{handler} is the callback function which has been registered for
1320 this message (see @pxref{Signals}). When a @code{dbus-event} event
1321 arrives, @var{handler} is called with @var{args} as arguments.
1323 In order to inspect the @code{dbus-event} data, you could extend the
1324 definition of the callback function in @ref{Signals}:
1327 (defun my-dbus-signal-handler (&rest args)
1328 (message "my-dbus-signal-handler: %S" last-input-event))
1331 There exist convenience functions which could be called inside a
1332 callback function in order to retrieve the information from the event.
1334 @defun dbus-event-bus-name event
1335 Returns the bus name @var{event} is coming from.
1336 The result is either the symbol @code{:system} or the symbol @code{:session}.
1339 @defun dbus-event-serial-number event
1340 Returns the serial number of the corresponding D-Bus message.
1341 The result is a number in case the D-Bus message is a method
1342 call, or @code{nil} for all other mesage types.
1345 @defun dbus-event-service-name event
1346 Returns the unique name of the D-Bus object @var{event} is coming from.
1349 @defun dbus-event-path-name event
1350 Returns the object path of the D-Bus object @var{event} is coming from.
1353 @defun dbus-event-interface-name event
1354 Returns the interface name of of the D-Bus object @var{event} is coming from.
1357 @defun dbus-event-member-name event
1358 Returns the member name of of the D-Bus object @var{event} is coming
1359 from. It is either a signal name or a method name.
1362 D-Bus errors are not propagated during event handling, because it is
1363 usually not desired. D-Bus errors in events can be made visible by
1364 setting the variable @code{dbus-debug} to @code{t}.
1367 @node GNU Free Documentation License
1368 @appendix GNU Free Documentation License
1369 @include doclicense.texi
1376 arch-tag: 2eeec19d-0caf-44e0-a193-329d7f9951d8