1 \input texinfo @c -*-texinfo-*-
2 @setfilename ../../info/dbus
4 @settitle Using of D-Bus
5 @c @setchapternewpage odd
12 Copyright @copyright{} 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
15 Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.3 or
17 any later version published by the Free Software Foundation; with no
18 Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
19 and with the Back-Cover Texts as in (a) below. A copy of the license
20 is included in the section entitled ``GNU Free Documentation License''.
22 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
23 modify this GNU manual. Buying copies from the FSF supports it in
24 developing GNU and promoting software freedom.''
30 * D-Bus: (dbus). Using D-Bus in Emacs.
36 @node Top, Overview, (dir), (dir)
37 @top D-Bus integration in Emacs
39 This manual documents an API for usage of D-Bus in Emacs. D-Bus is a
40 message bus system, a simple way for applications to talk to one
41 another. An overview of D-Bus can be found at
42 @uref{http://dbus.freedesktop.org/}.
49 * Overview:: An overview of D-Bus.
50 * Inspection:: Inspection of D-Bus services.
51 * Type Conversion:: Mapping Lisp types and D-Bus types.
52 * Synchronous Methods:: Calling methods in a blocking way.
53 * Asynchronous Methods:: Calling methods non-blocking.
54 * Receiving Method Calls:: Offering own methods.
55 * Signals:: Sending and receiving signals.
56 * Alternative Buses:: Alternative buses.
57 * Errors and Events:: Errors and events.
58 * Index:: Index including concepts, functions, variables.
60 * GNU Free Documentation License:: The license for this documentation.
65 @chapter An overview of D-Bus
68 D-Bus is an inter-process communication mechanism for applications
69 residing on the same host. The communication is based on
70 @dfn{messages}. Data in the messages is carried in a structured way,
71 it is not just a byte stream.
73 The communication is connection oriented to two kinds of message
74 buses: a so called @dfn{system bus}, and a @dfn{session bus}. On a
75 given machine, there is always one single system bus for miscellaneous
76 system-wide communication, like changing of hardware configuration.
77 On the other hand, the session bus is always related to a single
80 Every client application, which is connected to a bus, registers under
81 a @dfn{unique name} at the bus. This name is used for identifying the
82 client application. Such a unique name starts always with a colon,
83 and looks like @samp{:1.42}.
85 Additionally, a client application can register itself to a so called
86 @dfn{known name}, which is a series of identifiers separated by dots,
87 as in @samp{org.gnu.Emacs}. If several applications register to the
88 same known name, these registrations are queued, and only the first
89 application which has registered for the known name is reachable via
90 this name. If this application disconnects from the bus, the next
91 queued unique name becomes the owner of this known name.
93 An application can install one or several objects under its name.
94 Such objects are identified by an @dfn{object path}, which looks
95 similar to paths in a filesystem. An example of such an object path
96 could be @samp{/org/gnu/Emacs/}.
98 Applications might send a request to an object, that means sending a
99 message with some data as input parameters, and receiving a message
100 from that object with the result of this message, the output
101 parameters. Such a request is called @dfn{method} in D-Bus.
103 The other form of communication are @dfn{signals}. The underlying
104 message is emitted from an object and will be received by all other
105 applications which have registered for such a signal.
107 All methods and signals an object supports are called @dfn{interface}
108 of the object. Interfaces are specified under a hierarchical name in
109 D-Bus; an object can support several interfaces. Such an interface
110 name could be @samp{org.gnu.Emacs.TextEditor} or
111 @samp{org.gnu.Emacs.FileManager}.
115 @chapter Inspection of D-Bus services.
119 * Bus names:: Discovering D-Bus names.
120 * Introspection:: Knowing the details of D-Bus services.
121 * Nodes and Interfaces:: Detecting object paths and interfaces.
122 * Methods and Signal:: Applying the functionality.
123 * Properties and Annotations:: What else to know about interfaces.
124 * Arguments and Signatures:: The final details.
131 There are several basic functions which inspect the buses for
132 registered names. Internally they use the basic interface
133 @samp{org.freedesktop.DBus}, which is supported by all objects of a bus.
135 @defun dbus-list-activatable-names
136 This function returns the D-Bus service names, which can be activated.
137 An activatable service is described in a service registration file.
138 Under GNU/Linux, such files are located at
139 @file{/usr/share/dbus-1/services/}.
141 The result is a list of strings, which is @code{nil} when there are no
142 activatable service names at all.
145 @defun dbus-list-names bus
146 All service names, which are registered at D-Bus @var{bus}, are
147 returned. The result is a list of strings, which is @code{nil} when
148 there are no registered service names at all. Well known names are
149 strings like @samp{org.freedesktop.DBus}. Names starting with
150 @samp{:} are unique names for services.
152 @var{bus} must be either the symbol @code{:system} or the symbol
156 @defun dbus-list-known-names bus
157 Retrieves all services which correspond to a known name in @var{bus}.
158 A service has a known name if it doesn't start with @samp{:}. The
159 result is a list of strings, which is @code{nil} when there are no
162 @var{bus} must be either the symbol @code{:system} or the symbol
166 @defun dbus-list-queued-owners bus service
167 For a given service, registered at D-Bus @var{bus} under the name
168 @var{service}, all queued unique names are returned. The result is a
169 list of strings, or @code{nil} when there are no queued names for
170 @var{service} at all.
172 @var{bus} must be either the symbol @code{:system} or the symbol
173 @code{:session}. @var{service} must be a known service name as
177 @defun dbus-get-name-owner bus service
178 For a given service, registered at D-Bus @var{bus} under the name
179 @var{service}, the unique name of the name owner is returned. The
180 result is a string, or @code{nil} when there exist no name owner of
183 @var{bus} must be either the symbol @code{:system} or the symbol
184 @code{:session}. @var{service} must be a known service name as
188 @defun dbus-ping bus service &optional timeout
189 Check whether the service name @var{service} is registered at D-Bus
190 @var{bus}. @var{service} might not have been started yet, it is
191 autostarted if possible. The result is either @code{t} or @code{nil}.
193 @var{bus} must be either the symbol @code{:system} or the symbol
194 @code{:session}. @var{service} must be a string. @var{timeout}, a
195 nonnegative integer, specifies the maximum number of milliseconds
196 @code{dbus-ping} must return. The default value is 25,000. Example:
200 "%s screensaver on board."
202 ((dbus-ping :session "org.gnome.ScreenSaver" 100) "Gnome")
203 ((dbus-ping :session "org.freedesktop.ScreenSaver" 100) "KDE")
207 If it shall be checked whether @var{service} is already running
208 without autostarting it, one shall apply
211 (member service (dbus-list-known-names bus))
215 @defun dbus-get-unique-name bus
216 The unique name, under which Emacs is registered at D-Bus @var{bus},
217 is returned as string.
219 @var{bus} must be either the symbol @code{:system} or the symbol
225 @section Knowing the details of D-Bus services.
227 D-Bus services publish their interfaces. This can be retrieved and
228 analyzed during runtime, in order to understand the used
231 The resulting introspection data are in XML format. The root
232 introspection element is always a @code{node} element. It might have
233 a @code{name} attribute, which denotes the (absolute) object path an
234 interface is introspected.
236 The root @code{node} element may have @code{node} and @code{interface}
237 children. A child @code{node} element must have a @code{name}
238 attribute, this case it is the relative object path to the root
241 An @code{interface} element has just one attribute, @code{name}, which
242 is the full name of that interface. The default interface
243 @samp{org.freedesktop.DBus.Introspectable} is always present. Example:
246 <node name="/org/bluez">
247 <interface name="org.freedesktop.DBus.Introspectable">
250 <interface name="org.bluez.Manager">
253 <interface name="org.bluez.Database">
256 <interface name="org.bluez.Security">
259 <node name="service_audio"/>
260 <node name="service_input"/>
261 <node name="service_network"/>
262 <node name="service_serial"/>
266 Children of an @code{interface} element can be @code{method},
267 @code{signal} and @code{property} elements. A @code{method} element
268 stands for a D-Bus method of the surrounding interface. The element
269 itself has a @code{name} attribute, showing the method name. Children
270 elements @code{arg} stand for the arguments of a method. Example:
273 <method name="ResolveHostName">
274 <arg name="interface" type="i" direction="in"/>
275 <arg name="protocol" type="i" direction="in"/>
276 <arg name="name" type="s" direction="in"/>
277 <arg name="aprotocol" type="i" direction="in"/>
278 <arg name="flags" type="u" direction="in"/>
279 <arg name="interface" type="i" direction="out"/>
280 <arg name="protocol" type="i" direction="out"/>
281 <arg name="name" type="s" direction="out"/>
282 <arg name="aprotocol" type="i" direction="out"/>
283 <arg name="address" type="s" direction="out"/>
284 <arg name="flags" type="u" direction="out"/>
288 @code{arg} elements can have the attributes @code{name}, @code{type}
289 and @code{direction}. The @code{name} attribute is optional. The
290 @code{type} attribute stands for the @dfn{signature} of the argument
291 in D-Bus. For a discussion of D-Bus types and their Lisp
292 representation see @ref{Type Conversion}.@footnote{D-Bus signatures
293 are explained in the D-Bus specification
294 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures}.}
295 The @code{direction} attribute of an @code{arg} element can be only
296 @samp{in} or @samp{out}; in case it is omitted, it defaults to
299 A @code{signal} element of an @code{interface} has a similar
300 structure. The @code{direction} attribute of an @code{arg} child
301 element can be only @samp{out} here; which is also the default value.
305 <signal name="StateChanged">
306 <arg name="state" type="i"/>
307 <arg name="error" type="s"/>
311 A @code{property} element has no @code{arg} child
312 element. It just has the attributes @code{name}, @code{type} and
313 @code{access}, which are all mandatory. The @code{access} attribute
314 allows the values @samp{readwrite}, @samp{read}, and @samp{write}.
318 <property name="Status" type="u" direction="read"/>
321 @code{annotation} elements can be children of @code{interface},
322 @code{method}, @code{signal}, and @code{property} elements. Unlike
323 properties, which can change their values during lifetime of a D-Bus
324 object, annotations are static. Often they are used for code
325 generators of D-Bus langugae bindings. Example:
328 <annotation name="de.berlios.Pinot.GetStatistics" value="pinotDBus"/>
331 Annotations have just @code{name} and @code{value} attributes, both
334 @defun dbus-introspect bus service path
335 This function returns all interfaces and sub-nodes of @var{service},
336 registered at object path @var{path} at bus @var{bus}.
338 @var{bus} must be either the symbol @code{:system} or the symbol
339 @code{:session}. @var{service} must be a known service name, and
340 @var{path} must be a valid object path. The last two parameters are
341 strings. The result, the introspection data, is a string in XML
346 :system "org.freedesktop.Hal"
347 "/org/freedesktop/Hal/devices/computer")
349 @result{} "<!DOCTYPE node PUBLIC
350 "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
351 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
353 <interface name="org.freedesktop.Hal.Device">
354 <method name="GetAllProperties">
355 <arg name="properties" direction="out" type="a@{sv@}"/>
358 <signal name="PropertyModified">
359 <arg name="num_updates" type="i"/>
360 <arg name="updates" type="a(sbb)"/>
367 This example informs us, that the service @samp{org.freedesktop.Hal}
368 at object path @samp{/org/freedesktop/Hal/devices/computer} offers the
369 interface @samp{org.freedesktop.Hal.Device} (and 2 other interfaces
370 not documented here). This interface contains the method
371 @samp{GetAllProperties}, which needs no input parameters, but returns
372 as output parameter an array of dictionary entries (key-value pairs).
373 Every dictionary entry has a string as key, and a variant as value.
375 The interface offers also a signal, which returns 2 parameters: an
376 integer, and an array consisting of elements which are a struct of a
377 string and 2 boolean values.@footnote{ The interfaces of the service
378 @samp{org.freedesktop.Hal} are described at
379 @uref{http://people.freedesktop.org/~david/hal-spec/hal-spec.html#interfaces}.}
382 @defun dbus-introspect-xml bus service path
383 This function has the same intention as function
384 @code{dbus-introspect}. The returned value is a parsed XML tree,
385 which can be used for further analysis. Example:
389 :session "org.freedesktop.xesam.searcher"
390 "/org/freedesktop/xesam/searcher/main")
392 @result{} (node ((name . "/org/freedesktop/xesam/searcher/main"))
393 (interface ((name . "org.freedesktop.xesam.Search"))
394 (method ((name . "GetHitData"))
395 (arg ((name . "search") (type . "s") (direction . "in")))
396 (arg ((name . "hit_ids") (type . "au") (direction . "in")))
397 (arg ((name . "fields") (type . "as") (direction . "in")))
398 (arg ((name . "hit_data") (type . "aav") (direction . "out")))
401 (signal ((name . "HitsAdded"))
402 (arg ((name . "search") (type . "s")))
403 (arg ((name . "count") (type . "u")))
411 @defun dbus-introspect-get-attribute object attribute
412 It returns the @var{attribute} value of a D-Bus introspection
413 @var{object}. @var{object} can be every subtree of a parsed XML tree
414 as retrieved with @code{dbus-introspect-xml}. @var{attribute} must be
415 a string according to the attribute names in the D-Bus specification.
419 (dbus-introspect-get-attribute
420 (dbus-introspect-xml :system "org.freedesktop.SystemToolsBackends"
421 "/org/freedesktop/SystemToolsBackends/UsersConfig")
424 @result{} "/org/freedesktop/SystemToolsBackends/UsersConfig"
427 If @var{object} has no @var{attribute}, the function returns
432 @node Nodes and Interfaces
433 @section Detecting object paths and interfaces.
435 The first elements, to be introspected for a D-Bus object, are further
436 object paths and interfaces.
438 @defun dbus-introspect-get-node-names bus service path
439 All node names of @var{service} in D-Bus @var{bus} at object path
440 @var{path} are returned as list of strings. Example:
443 (dbus-introspect-get-node-names
444 :session "org.gnome.seahorse" "/org/gnome/seahorse")
446 @result{} ("crypto" "keys")
449 The node names stand for further object paths of the D-Bus
450 @var{service}, relative to @var{path}. In the example,
451 @samp{/org/gnome/seahorse/crypto} and @samp{/org/gnome/seahorse/keys}
452 are also object paths of the D-Bus service @samp{org.gnome.seahorse}.
455 @defun dbus-introspect-get-all-nodes bus service path
456 This function returns all node names of @var{service} in D-Bus
457 @var{bus} at object path @var{path}. It returns a list of strings
458 with all object paths of @var{service}, starting at @var{path}.
462 (dbus-introspect-get-all-nodes :session "org.gnome.seahorse" "/")
464 @result{} ("/" "/org" "/org/gnome" "/org/gnome/seahorse"
465 "/org/gnome/seahorse/crypto"
466 "/org/gnome/seahorse/keys"
467 "/org/gnome/seahorse/keys/openpgp"
468 "/org/gnome/seahorse/keys/openpgp/local"
469 "/org/gnome/seahorse/keys/openssh"
470 "/org/gnome/seahorse/keys/openssh/local")
474 @defun dbus-introspect-get-interface-names bus service path
475 There will be returned a list strings of all interface names of
476 @var{service} in D-Bus @var{bus} at object path @var{path}. This list
477 will contain the default interface @samp{org.freedesktop.DBus.Introspectable}.
479 Another default interface is @samp{org.freedesktop.DBus.Properties}.
480 If present, @code{interface} elements can also have @code{property}
484 (dbus-introspect-get-interface-names
485 :system "org.freedesktop.Hal"
486 "/org/freedesktop/Hal/devices/computer")
488 @result{} ("org.freedesktop.DBus.Introspectable"
489 "org.freedesktop.Hal.Device"
490 "org.freedesktop.Hal.Device.SystemPowerManagement"
491 "org.freedesktop.Hal.Device.CPUFreq")
495 @defun dbus-introspect-get-interface bus service path interface
496 Return @var{interface} of @var{service} in D-Bus @var{bus} at object
497 path @var{path}. The return value is an XML element. @var{interface}
498 must be a string, element of the list returned by
499 @code{dbus-introspect-get-interface-names}. Example:
502 (dbus-introspect-get-interface
503 :session "org.freedesktop.xesam.searcher"
504 "/org/freedesktop/xesam/searcher/main"
505 "org.freedesktop.xesam.Search")
507 @result{} (interface ((name . "org.freedesktop.xesam.Search"))
508 (method ((name . "GetHitData"))
509 (arg ((name . "search") (type . "s") (direction . "in")))
510 (arg ((name . "hit_ids") (type . "au") (direction . "in")))
511 (arg ((name . "fields") (type . "as") (direction . "in")))
512 (arg ((name . "hit_data") (type . "aav") (direction . "out")))
515 (signal ((name . "HitsAdded"))
516 (arg ((name . "search") (type . "s")))
517 (arg ((name . "count") (type . "u")))
524 With these functions, it is possible to retrieve all introspection
525 data from a running system:
528 (with-current-buffer (switch-to-buffer "*introspect*")
530 (dolist (service (dbus-list-known-names :session))
531 (dolist (path (dbus-introspect-get-all-nodes :session service "/"))
532 ;; We want to introspect only elements, which have more than
533 ;; the default interface "org.freedesktop.DBus.Introspectable".
535 "org.freedesktop.DBus.Introspectable"
536 (dbus-introspect-get-interface-names :session service path))
537 (insert (message "\nservice: \"%s\" path: \"%s\"\n" service path)
538 (dbus-introspect :session service path))
543 @node Methods and Signal
544 @section Applying the functionality.
546 Methods and signals are the communicatione means to D-Bus. The
547 following functions return their specifications.
549 @defun dbus-introspect-get-method-names bus service path interface
550 Return a list of strings of all method names of @var{interface} of
551 @var{service} in D-Bus @var{bus} at object path @var{path}. Example:
554 (dbus-introspect-get-method-names
555 :session "org.freedesktop.xesam.searcher"
556 "/org/freedesktop/xesam/searcher/main"
557 "org.freedesktop.xesam.Search")
559 @result{} ("GetState" "StartSearch" "GetHitCount" "GetHits" "NewSession"
560 "CloseSession" "GetHitData" "SetProperty" "NewSearch"
561 "GetProperty" "CloseSearch")
565 @defun dbus-introspect-get-method bus service path interface method
566 This function returns @var{method} of @var{interface} as XML element.
567 It must be located at @var{service} in D-Bus @var{bus} at object path
568 @var{path}. @var{method} must be a string, element of the list
569 returned by @code{dbus-introspect-get-method-names}. Example:
572 (dbus-introspect-get-method
573 :session "org.freedesktop.xesam.searcher"
574 "/org/freedesktop/xesam/searcher/main"
575 "org.freedesktop.xesam.Search" "GetHitData")
577 @result{} (method ((name . "GetHitData"))
578 (arg ((name . "search") (type . "s") (direction . "in")))
579 (arg ((name . "hit_ids") (type . "au") (direction . "in")))
580 (arg ((name . "fields") (type . "as") (direction . "in")))
581 (arg ((name . "hit_data") (type . "aav") (direction . "out")))
586 @defun dbus-introspect-get-signal-names bus service path interface
587 Return a list of strings of all signal names of @var{interface} of
588 @var{service} in D-Bus @var{bus} at object path @var{path}. Example:
591 (dbus-introspect-get-signal-names
592 :session "org.freedesktop.xesam.searcher"
593 "/org/freedesktop/xesam/searcher/main"
594 "org.freedesktop.xesam.Search")
596 @result{} ("StateChanged" "SearchDone" "HitsModified"
597 "HitsRemoved" "HitsAdded")
601 @defun dbus-introspect-get-signal bus service path interface signal
602 This function returns @var{signal} of @var{interface} as XML element.
603 It must be located at @var{service} in D-Bus @var{bus} at object path
604 @var{path}. @var{signal} must be a string, element of the list
605 returned by @code{dbus-introspect-get-signal-names}. Example:
608 (dbus-introspect-get-signal
609 :session "org.freedesktop.xesam.searcher"
610 "/org/freedesktop/xesam/searcher/main"
611 "org.freedesktop.xesam.Search" "HitsAdded")
613 @result{} (signal ((name . "HitsAdded"))
614 (arg ((name . "search") (type . "s")))
615 (arg ((name . "count") (type . "u")))
621 @node Properties and Annotations
622 @section What else to know about interfaces.
624 Interfaces can have properties. These can be exposed via the
625 @samp{org.freedesktop.DBus.Properties} interface@footnote{See
626 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties}}.
627 That is, properties can be retrieved and changed during lifetime of an
630 Annotations, on the other hand, are static values for an element.
631 Often, they are used to instruct generators, how to generate code from
632 the interface for a given language binding.
634 @defun dbus-introspect-get-property-names bus service path interface
635 Return a list of strings with all property names of @var{interface} of
636 @var{service} in D-Bus @var{bus} at object path @var{path}. Example:
639 (dbus-introspect-get-property-names
640 :session "org.kde.kded" "/modules/networkstatus"
641 "org.kde.Solid.Networking.Client")
646 If an interface declares properties, the corresponding element supports
647 also the @samp{org.freedesktop.DBus.Properties} interface.
650 @defun dbus-introspect-get-property bus service path interface property
651 This function returns @var{property} of @var{interface} as XML element.
652 It must be located at @var{service} in D-Bus @var{bus} at object path
653 @var{path}. @var{property} must be a string, element of the list
654 returned by @code{dbus-introspect-get-property-names}.
656 A @var{property} value can be retrieved by the function
657 @code{dbus-introspect-get-attribute}. Example:
660 (dbus-introspect-get-property
661 :session "org.kde.kded" "/modules/networkstatus"
662 "org.kde.Solid.Networking.Client" "Status")
664 @result{} (property ((access . "read") (type . "u") (name . "Status")))
666 (dbus-introspect-get-attribute
667 (dbus-introspect-get-property
668 :session "org.kde.kded" "/modules/networkstatus"
669 "org.kde.Solid.Networking.Client" "Status")
676 @defun dbus-get-property bus service path interface property
677 This function returns the value of @var{property} of @var{interface}.
678 It will be checked at @var{bus}, @var{service}, @var{path}. The
679 result can be any valid D-Bus value, or @code{nil} if there is no
680 @var{property}. Example:
684 :session "org.kde.kded" "/modules/networkstatus"
685 "org.kde.Solid.Networking.Client" "Status")
691 @defun dbus-set-property bus service path interface property value
692 Set value of @var{property} of @var{interface} to @var{value}. It
693 will be checked at @var{bus}, @var{service}, @var{path}. When the
694 value has been set successful, the result is @var{value}. Otherwise,
695 @code{nil} is returned. Example:
699 :session "org.kde.kaccess" "/MainApplication"
700 "com.trolltech.Qt.QApplication" "doubleClickInterval" 500)
706 @defun dbus-get-all-properties bus service path interface
707 This function returns all properties of @var{interface}. It will be
708 checked at @var{bus}, @var{service}, @var{path}. The result is a list
709 of cons. Every cons contains the name of the property, and its value.
710 If there are no properties, @code{nil} is returned. Example:
713 (dbus-get-all-properties
714 :session "org.kde.kaccess" "/MainApplication"
715 "com.trolltech.Qt.QApplication")
717 @result{} (("cursorFlashTime" . 1000) ("doubleClickInterval" . 500)
718 ("keyboardInputInterval" . 400) ("wheelScrollLines" . 3)
719 ("globalStrut" 0 0) ("startDragTime" . 500)
720 ("startDragDistance" . 4) ("quitOnLastWindowClosed" . t)
725 @defun dbus-introspect-get-annotation-names bus service path interface &optional name
726 Return a list of all annotation names as list of strings. If
727 @var{name} is @code{nil}, the annotations are children of
728 @var{interface}, otherwise @var{name} must be a @code{method},
729 @code{signal}, or @code{property} XML element, where the annotations
733 (dbus-introspect-get-annotation-names
734 :session "de.berlios.Pinot" "/de/berlios/Pinot"
735 "de.berlios.Pinot" "GetStatistics")
737 @result{} ("de.berlios.Pinot.GetStatistics")
740 Default annotation names@footnote{See
741 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format}}
745 @item org.freedesktop.DBus.Deprecated
746 Whether or not the entity is deprecated; defaults to @code{nil}
748 @item org.freedesktop.DBus.GLib.CSymbol
749 The C symbol; may be used for @code{methods} and @code{interfaces}
751 @item org.freedesktop.DBus.Method.NoReply
752 If set, don't expect a reply to the @code{method} call; defaults to @code{nil}
756 @defun dbus-introspect-get-annotation bus service path interface name annotation
757 Return annotation @var{ANNOTATION} as XML object. If @var{name} is
758 @code{nil}, @var{ANNOTATION} is a child of @var{interface}, otherwise
759 @var{name} must be the name of a @code{method}, @code{signal}, or
760 @code{property} XML element, where the @var{ANNOTATION} belongs to.
762 An attribute value can be retrieved by
763 @code{dbus-introspect-get-attribute}. Example:
766 (dbus-introspect-get-annotation
767 :session "de.berlios.Pinot" "/de/berlios/Pinot"
768 "de.berlios.Pinot" "GetStatistics"
769 "de.berlios.Pinot.GetStatistics")
771 @result{} (annotation ((name . "de.berlios.Pinot.GetStatistics")
772 (value . "pinotDBus")))
774 (dbus-introspect-get-attribute
775 (dbus-introspect-get-annotation
776 :session "de.berlios.Pinot" "/de/berlios/Pinot"
777 "de.berlios.Pinot" "GetStatistics"
778 "de.berlios.Pinot.GetStatistics")
781 @result{} "pinotDBus"
786 @node Arguments and Signatures
787 @section The final details.
789 Methods and signals have arguments. They are described in the
790 @code{arg} XML elements.
792 @defun dbus-introspect-get-argument-names bus service path interface name
793 Return a list of all argument names as list of strings. @var{name}
794 must be a @code{method} or @code{signal} XML element. Example:
797 (dbus-introspect-get-argument-names
798 :session "org.freedesktop.xesam.searcher"
799 "/org/freedesktop/xesam/searcher/main"
800 "org.freedesktop.xesam.Search" "GetHitData")
802 @result{} ("search" "hit_ids" "fields" "hit_data")
805 Argument names are optional; the function can return @code{nil}
806 therefore, even if the method or signal has arguments.
809 @defun dbus-introspect-get-argument bus service path interface name arg
810 Return argument @var{ARG} as XML object. @var{name}
811 must be a @code{method} or @code{signal} XML element. Example:
814 (dbus-introspect-get-argument
815 :session "org.freedesktop.xesam.searcher"
816 "/org/freedesktop/xesam/searcher/main"
817 "org.freedesktop.xesam.Search" "GetHitData" "search")
819 @result{} (arg ((name . "search") (type . "s") (direction . "in")))
823 @defun dbus-introspect-get-signature bus service path interface name &optional direction
824 Return signature of a @code{method} or @code{signal}, represented by
825 @var{name}, as string.
827 If @var{name} is a @code{method}, @var{direction} can be either
828 @samp{in} or @samp{out}. If @var{direction} is @code{nil}, @samp{in}
831 If @var{name} is a @code{signal}, and @var{direction} is
832 non-@code{nil}, @var{direction} must be @samp{out}. Example:
835 (dbus-introspect-get-signature
836 :session "org.freedesktop.xesam.searcher"
837 "/org/freedesktop/xesam/searcher/main"
838 "org.freedesktop.xesam.Search" "GetHitData" "in")
842 (dbus-introspect-get-signature
843 :session "org.freedesktop.xesam.searcher"
844 "/org/freedesktop/xesam/searcher/main"
845 "org.freedesktop.xesam.Search" "HitsAdded")
852 @node Type Conversion
853 @chapter Mapping Lisp types and D-Bus types.
854 @cindex type conversion
856 D-Bus method calls and signals accept usually several arguments as
857 parameters, either as input parameter, or as output parameter. Every
858 argument belongs to a D-Bus type.
860 Such arguments must be mapped between the value encoded as a D-Bus
861 type, and the corresponding type of Lisp objects. The mapping is
862 applied Lisp object @expansion{} D-Bus type for input parameters, and
863 D-Bus type @expansion{} Lisp object for output parameters.
866 @section Input parameters.
868 Input parameters for D-Bus methods and signals occur as arguments of a
869 Lisp function call. The following mapping to D-Bus types is
870 applied, when the corresponding D-Bus message is created:
873 @multitable {negative integer} {@expansion{}} {DBUS_TYPE_BOOLEAN}
874 @item Lisp type @tab @tab D-Bus type
876 @item @code{t} and @code{nil} @tab @expansion{} @tab DBUS_TYPE_BOOLEAN
877 @item natural number @tab @expansion{} @tab DBUS_TYPE_UINT32
878 @item negative integer @tab @expansion{} @tab DBUS_TYPE_INT32
879 @item float @tab @expansion{} @tab DBUS_TYPE_DOUBLE
880 @item string @tab @expansion{} @tab DBUS_TYPE_STRING
881 @item list @tab @expansion{} @tab DBUS_TYPE_ARRAY
885 Other Lisp objects, like symbols or hash tables, are not accepted as
888 If it is necessary to use another D-Bus type, a corresponding type
889 symbol can be preceeded to the corresponding Lisp object. Basic D-Bus
890 types are represented by the type symbols @code{:byte},
891 @code{:boolean}, @code{:int16}, @code{:uint16}, @code{:int32},
892 @code{:uint32}, @code{:int64}, @code{:uint64}, @code{:double},
893 @code{:string}, @code{:object-path} and @code{:signature}.
899 (dbus-call-method @dots{} @var{NAT-NUMBER} @var{STRING})
905 (dbus-call-method @dots{} :uint32 @var{NAT-NUMBER} :string @var{STRING})
911 (dbus-call-method @dots{} :int32 @var{NAT-NUMBER} :signature @var{STRING})
914 The value for a byte D-Bus type can be any integer in the range 0
915 through 255. If a character is used as argument, modifiers
916 represented outside this range are stripped of. For example,
917 @code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to
918 @code{:byte ?\C-x} or @code{:byte ?\M-\C-x}.
920 A D-Bus compound type is always represented as a list. The @sc{car}
921 of this list can be the type symbol @code{:array}, @code{:variant},
922 @code{:struct} or @code{:dict-entry}, which would result in a
923 corresponding D-Bus container. @code{:array} is optional, because
924 this is the default compound D-Bus type for a list.
926 The objects being elements of the list are checked according to the
927 D-Bus compound type rules.
930 @item An array must contain only elements of the same D-Bus type. It
933 @item A variant must contain only one single element.
935 @item A dictionary entry must be element of an array, and it must
936 contain only a key-value pair of two elements, with a basic D-Bus type
939 @item There is no restriction for structs.
942 If an empty array needs an element D-Bus type other than string, it
943 can contain exactly one element of D-Bus type @code{:signature}. The
944 value of this element (a string) is used as the signature of the
945 elements of this array. Example:
949 :session "org.freedesktop.Notifications"
950 "/org/freedesktop/Notifications"
951 "org.freedesktop.Notifications" "Notify"
952 "GNU Emacs" ;; Application name.
953 0 ;; No replacement of other notifications.
955 "Notification summary" ;; Summary.
957 "This is a test notification, raised from %s" (emacs-version))
958 '(:array) ;; No actions (empty array of strings).
959 '(:array :signature "@{sv@}") ;; No hints
960 ;; (empty array of dictionary entries).
961 :int32 -1) ;; Default timeout.
966 @defun dbus-string-to-byte-array string
967 Sometimes, D-Bus methods require as input parameter an array of bytes,
968 instead of a string. If it is guaranteed, that @var{string} is an
969 UTF8 string, this function performs the conversion. Example:
972 (dbus-string-to-byte-array "/etc/hosts")
974 @result{} (:array :byte 47 :byte 101 :byte 116 :byte 99 :byte 47
975 :byte 104 :byte 111 :byte 115 :byte 116 :byte 115)
979 @defun dbus-escape-as-identifier string
980 Escape an arbitrary @var{string} so it follows the rules for a C
981 identifier. The escaped string can be used as object path component,
982 interface element component, bus name component or member name in
985 The escaping consists of replacing all non-alphanumerics, and the
986 first character if it's a digit, with an underscore and two
987 lower-case hex digits. As a special case, "" is escaped to
991 (dbus-escape-as-identifier "0123abc_xyz\x01\xff")
993 @result{} "_30123abc_5fxyz_01_ff"
998 @section Output parameters.
1000 Output parameters of D-Bus methods and signals are mapped to Lisp
1004 @multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {natural number or float}
1005 @item D-Bus type @tab @tab Lisp type
1007 @item DBUS_TYPE_BOOLEAN @tab @expansion{} @tab @code{t} or @code{nil}
1008 @item DBUS_TYPE_BYTE @tab @expansion{} @tab natural number
1009 @item DBUS_TYPE_UINT16 @tab @expansion{} @tab natural number
1010 @item DBUS_TYPE_INT16 @tab @expansion{} @tab integer
1011 @item DBUS_TYPE_UINT32 @tab @expansion{} @tab natural number or float
1012 @item DBUS_TYPE_INT32 @tab @expansion{} @tab integer or float
1013 @item DBUS_TYPE_UINT64 @tab @expansion{} @tab natural number or float
1014 @item DBUS_TYPE_INT64 @tab @expansion{} @tab integer or float
1015 @item DBUS_TYPE_DOUBLE @tab @expansion{} @tab float
1016 @item DBUS_TYPE_STRING @tab @expansion{} @tab string
1017 @item DBUS_TYPE_OBJECT_PATH @tab @expansion{} @tab string
1018 @item DBUS_TYPE_SIGNATURE @tab @expansion{} @tab string
1019 @item DBUS_TYPE_ARRAY @tab @expansion{} @tab list
1020 @item DBUS_TYPE_VARIANT @tab @expansion{} @tab list
1021 @item DBUS_TYPE_STRUCT @tab @expansion{} @tab list
1022 @item DBUS_TYPE_DICT_ENTRY @tab @expansion{} @tab list
1026 A float object in case of @code{DBUS_TYPE_UINT32},
1027 @code{DBUS_TYPE_INT32}, @code{DBUS_TYPE_UINT64} and
1028 @code{DBUS_TYPE_INT6432} is returned, when the C value exceeds the
1029 Emacs number size range.
1031 The resulting list of the last 4 D-Bus compound types contains as
1032 elements the elements of the D-Bus container, mapped according to the
1035 The signal @code{PropertyModified}, discussed as example in
1036 @ref{Inspection}, would offer as Lisp data the following object
1037 (@var{BOOL} stands here for either @code{nil} or @code{t}):
1040 (@var{INTEGER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
1043 @defun dbus-byte-array-to-string byte-array
1044 If a D-Bus method or signal returns an array of bytes, which are known
1045 to represent an UTF8 string, this function converts @var{byte-array}
1046 to the corresponding string. Example:
1049 (dbus-byte-array-to-string '(47 101 116 99 47 104 111 115 116 115))
1051 @result{} "/etc/hosts"
1055 @defun dbus-unescape-from-identifier string
1056 Retrieve the original string from the encoded @var{string}.
1057 @var{string} must have been coded with
1058 @code{dbus-escape-as-identifier}. Example:
1061 (dbus-unescape-from-identifier "_30123abc_5fxyz_01_ff")
1064 @result{} "0123abc_xyz^Aÿ"
1067 @result{} "0123abc_xyz^A@"y"
1073 @node Synchronous Methods
1074 @chapter Calling methods in a blocking way.
1075 @cindex method calls, synchronous
1076 @cindex synchronous method calls
1078 Methods can be called synchronously (@dfn{blocking}) or asynchronously
1079 (@dfn{non-blocking}).
1081 At D-Bus level, a method call consist of two messages: one message
1082 which carries the input parameters to the object owning the method to
1083 be called, and a reply message returning the resulting output
1084 parameters from the object.
1086 @defun dbus-call-method bus service path interface method &optional :timeout timeout &rest args
1087 This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is
1088 either the symbol @code{:system} or the symbol @code{:session}.
1090 @var{service} is the D-Bus service name to be used. @var{path} is the
1091 D-Bus object path, @var{service} is registered at. @var{interface} is
1092 an interface offered by @var{service}. It must provide @var{method}.
1094 If the parameter @code{:timeout} is given, the following integer
1095 @var{timeout} specifies the maximum number of milliseconds the method
1096 call must return. The default value is 25,000. If the method call
1097 doesn't return in time, a D-Bus error is raised (@pxref{Errors and
1100 All other arguments args are passed to @var{method} as arguments.
1101 They are converted into D-Bus types as described in @ref{Type
1104 The function returns the resulting values of @var{method} as a list of
1105 Lisp objects, according to the type conversion rules described in
1106 @ref{Type Conversion}. Example:
1110 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
1111 "org.gnome.seahorse.Keys" "GetKeyField"
1112 "openpgp:657984B8C7A966DD" "simple-name")
1114 @result{} (t ("Philip R. Zimmermann"))
1117 If the result of the method call is just one value, the converted Lisp
1118 object is returned instead of a list containing this single Lisp
1123 :system "org.freedesktop.Hal"
1124 "/org/freedesktop/Hal/devices/computer"
1125 "org.freedesktop.Hal.Device" "GetPropertyString"
1126 "system.kernel.machine")
1131 With the @code{dbus-introspect} function it is possible to explore the
1132 interfaces of @samp{org.freedesktop.Hal} service. It offers the
1133 interfaces @samp{org.freedesktop.Hal.Manager} for the object at the
1134 path @samp{/org/freedesktop/Hal/Manager} as well as the interface
1135 @samp{org.freedesktop.Hal.Device} for all objects prefixed with the
1136 path @samp{/org/freedesktop/Hal/devices}. With the methods
1137 @samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to
1138 emulate the @code{lshal} command on GNU/Linux systems:
1143 :system "org.freedesktop.Hal"
1144 "/org/freedesktop/Hal/Manager"
1145 "org.freedesktop.Hal.Manager" "GetAllDevices"))
1146 (message "\nudi = %s" device)
1149 :system "org.freedesktop.Hal" device
1150 "org.freedesktop.Hal.Device" "GetAllProperties"))
1152 (car properties) (or (caar (cdr properties)) ""))))
1154 @print{} "udi = /org/freedesktop/Hal/devices/computer
1155 info.addons = (\"hald-addon-acpi\")
1156 info.bus = \"unknown\"
1157 info.product = \"Computer\"
1158 info.subsystem = \"unknown\"
1159 info.udi = \"/org/freedesktop/Hal/devices/computer\"
1160 linux.sysfs_path_device = \"(none)\"
1161 power_management.acpi.linux.version = \"20051216\"
1162 power_management.can_suspend_to_disk = t
1163 power_management.can_suspend_to_ram = \"\"
1164 power_management.type = \"acpi\"
1165 smbios.bios.release_date = \"11/07/2001\"
1166 system.chassis.manufacturer = \"COMPAL\"
1167 system.chassis.type = \"Notebook\"
1168 system.firmware.release_date = \"03/19/2005\"
1173 @defun dbus-call-method-non-blocking bus service path interface method &optional :timeout timeout &rest args
1174 Call @var{method} on the D-Bus @var{bus}, but don't block the event queue.
1175 This is necessary for communicating to registered D-Bus methods,
1176 which are running in the same Emacs process.
1178 The arguments are the same as in @code{dbus-call-method}. Example:
1181 (dbus-call-method-non-blocking
1182 :system "org.freedesktop.Hal"
1183 "/org/freedesktop/Hal/devices/computer"
1184 "org.freedesktop.Hal.Device" "GetPropertyString"
1185 "system.kernel.machine")
1192 @node Asynchronous Methods
1193 @chapter Calling methods non-blocking.
1194 @cindex method calls, asynchronous
1195 @cindex asynchronous method calls
1197 @defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout &rest args
1198 This function calls @var{method} on the D-Bus @var{bus}
1199 asynchronously. @var{bus} is either the symbol @code{:system} or the
1200 symbol @code{:session}.
1202 @var{service} is the D-Bus service name to be used. @var{path} is the
1203 D-Bus object path, @var{service} is registered at. @var{interface} is
1204 an interface offered by @var{service}. It must provide @var{method}.
1206 @var{handler} is a Lisp function, which is called when the
1207 corresponding return message has arrived. If @var{handler} is
1208 @code{nil}, no return message will be expected.
1210 If the parameter @code{:timeout} is given, the following integer
1211 @var{timeout} specifies the maximum number of milliseconds a reply
1212 message must arrive. The default value is 25,000. If there is no
1213 reply message in time, a D-Bus error is raised (@pxref{Errors and
1216 All other arguments args are passed to @var{method} as arguments.
1217 They are converted into D-Bus types as described in @ref{Type
1220 Unless @var{handler} is @code{nil}, the function returns a key into
1221 the hash table @code{dbus-registered-objects-table}. The
1222 corresponding entry in the hash table is removed, when the return
1223 message has been arrived, and @var{handler} is called. Example:
1226 (dbus-call-method-asynchronously
1227 :system "org.freedesktop.Hal"
1228 "/org/freedesktop/Hal/devices/computer"
1229 "org.freedesktop.Hal.Device" "GetPropertyString" 'message
1230 "system.kernel.machine")
1232 @result{} (:system 2)
1239 @node Receiving Method Calls
1240 @chapter Offering own methods.
1241 @cindex method calls, returning
1242 @cindex returning method calls
1244 Emacs can also offer own methods, which can be called by other
1245 applications. These methods could be an implementation of an
1246 interface of a well known service, like @samp{org.freedesktop.TextEditor}.
1248 It could be also an implementation of an own interface. In this case,
1249 the service name must be @samp{org.gnu.Emacs}. The object path shall
1250 begin with @samp{/org/gnu/Emacs/@strong{Application}/}, and the
1251 interface name shall be @code{org.gnu.Emacs.@strong{Application}}.
1252 @samp{@strong{Application}} is the name of the application which
1253 provides the interface.
1255 @deffn Constant dbus-service-emacs
1256 The well known service name of Emacs.
1259 @deffn Constant dbus-path-emacs
1260 The object path head "/org/gnu/Emacs" used by Emacs. All object
1261 paths, used by offered methods or signals, shall start with this
1265 @defun dbus-register-method bus service path interface method handler
1266 With this function, an application registers @var{method} on the D-Bus
1269 @var{bus} is either the symbol @code{:system} or the symbol
1272 @var{service} is the D-Bus service name of the D-Bus object
1273 @var{method} is registered for. It must be a known name.
1275 @var{path} is the D-Bus object path @var{service} is
1278 @var{interface} is the interface offered by @var{service}. It must
1279 provide @var{method}.
1281 @var{handler} is a Lisp function to be called when a @var{method} call
1282 is received. It must accept as arguments the input arguments of
1283 @var{method}. @var{handler} should return a list, whose elements are
1284 to be used as arguments for the reply message of @var{method}. This
1285 list can be composed like the input parameters in @ref{Type
1288 If @var{handler} wants to return just one Lisp object and it is not a
1289 cons cell, @var{handler} can return this object directly, instead of
1290 returning a list containing the object.
1292 In case @var{handler} shall return a reply message with an empty
1293 argument list, @var{handler} must return the symbol @code{:ignore}.
1295 The default D-Bus timeout when waiting for a message reply is 25
1296 seconds. This value could be even smaller, depending on the calling
1297 client. Therefore, @var{handler} shall not last longer than
1298 absolutely necessary.
1300 @code{dbus-register-method} returns a Lisp object, which can be used
1301 as argument in @code{dbus-unregister-object} for removing the
1302 registration for @var{method}. Example:
1305 (defun my-dbus-method-handler (filename)
1307 (if (find-file filename)
1308 (setq result '(:boolean t))
1309 (setq result '(:boolean nil)))
1312 @result{} my-dbus-method-handler
1314 (dbus-register-method
1315 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1316 "org.freedesktop.TextEditor" "OpenFile"
1317 'my-dbus-method-handler)
1319 @result{} ((:session "org.freedesktop.TextEditor" "OpenFile")
1320 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1321 my-dbus-method-handler))
1324 If you invoke the method @samp{org.freedesktop.TextEditor.OpenFile}
1325 from another D-Bus application with a filename as parameter, the file
1326 is opened in Emacs, and the method returns either @var{true} or
1327 @var{false}, indicating the success of the method. As test tool one
1328 could use the command line tool @code{dbus-send} in a shell:
1331 # dbus-send --session --print-reply \
1332 --dest="org.freedesktop.TextEditor" \
1333 "/org/freedesktop/TextEditor" \
1334 "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts"
1336 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2
1340 You can indicate an error by raising the Emacs signal
1341 @code{dbus-error}. The handler above could be changed like this:
1344 (defun my-dbus-method-handler (&rest args)
1345 (unless (and (= (length args) 1) (stringp (car args)))
1346 (signal 'dbus-error (list (format "Wrong argument list: %S" args))))
1348 (find-file (car args))
1349 (error (signal 'dbus-error (cdr err))))
1352 @result{} my-dbus-method-handler
1358 # dbus-send --session --print-reply \
1359 --dest="org.freedesktop.TextEditor" \
1360 "/org/freedesktop/TextEditor" \
1361 "org.freedesktop.TextEditor.OpenFile" \
1362 string:"/etc/hosts" string:"/etc/passwd"
1364 @print{} Error org.freedesktop.DBus.Error.Failed:
1365 Wrong argument list: ("/etc/hosts" "/etc/passwd")
1369 @defun dbus-register-property bus service path interface property access value &optional emits-signal
1370 With this function, an application declares a @var{property} on the D-Bus
1373 @var{bus} is either the symbol @code{:system} or the symbol
1376 @var{service} is the D-Bus service name of the D-Bus. It must be a
1379 @var{path} is the D-Bus object path @var{service} is
1382 @var{interface} is the name of the interface used at @var{path},
1383 @var{property} is the name of the property of @var{interface}.
1385 @var{access} indicates, whether the property can be changed by other
1386 services via D-Bus. It must be either the symbol @code{:read} or
1387 @code{:readwrite}. @var{value} is the initial value of the property,
1388 it can be of any valid type (see @code{dbus-call-method} for details).
1390 If @var{property} already exists on @var{path}, it will be
1391 overwritten. For properties with access type @code{:read} this is the
1392 only way to change their values. Properties with access type
1393 @code{:readwrite} can be changed by @code{dbus-set-property}.
1395 The interface @samp{org.freedesktop.DBus.Properties} is added to
1396 @var{path}, including a default handler for the @samp{Get},
1397 @samp{GetAll} and @samp{Set} methods of this interface. When
1398 @var{emits-signal} is non-@code{nil}, the signal
1399 @samp{PropertiesChanged} is sent when the property is changed by
1400 @code{dbus-set-property}.
1405 (dbus-register-property
1406 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1407 "org.freedesktop.TextEditor" "name" :read "GNU Emacs")
1409 @result{} ((:session "org.freedesktop.TextEditor" "name")
1410 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"))
1412 (dbus-register-property
1413 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1414 "org.freedesktop.TextEditor" "version" :readwrite emacs-version t)
1416 @result{} ((:session "org.freedesktop.TextEditor" "version")
1417 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"))
1420 Other D-Bus applications can read the property via the default methods
1421 @samp{org.freedesktop.DBus.Properties.Get} and
1422 @samp{org.freedesktop.DBus.Properties.GetAll}. Testing is also
1423 possible via the command line tool @code{dbus-send} in a shell:
1426 # dbus-send --session --print-reply \
1427 --dest="org.freedesktop.TextEditor" \
1428 "/org/freedesktop/TextEditor" \
1429 "org.freedesktop.DBus.Properties.GetAll" \
1430 string:"org.freedesktop.TextEditor"
1432 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=3
1436 variant string "GNU Emacs"
1440 variant string "23.1.50.5"
1445 It is also possible, to apply the @code{dbus-get-property},
1446 @code{dbus-get-all-properties} and @code{dbus-set-property} functions
1447 (@pxref{Properties and Annotations}).
1451 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1452 "org.freedesktop.TextEditor" "version" "23.1.50")
1457 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1458 "org.freedesktop.TextEditor" "version")
1464 @defun dbus-unregister-object object
1465 Unregister @var{object} from the D-Bus. @var{object} must be the
1466 result of a preceding @code{dbus-register-method},
1467 @code{dbus-register-property} or @code{dbus-register-signal} call
1468 (@pxref{Signals}). It returns @code{t} if @var{object} has been
1469 unregistered, @code{nil} otherwise.
1471 When @var{object} identifies the last method or property, which is
1472 registered for the respective service, Emacs releases its association
1473 to the service from D-Bus.
1476 @defun dbus-unregister-service bus service
1477 Unregister all objects from D-Bus @var{bus}, registered by Emacs for
1480 @var{bus} is either the symbol @code{:system} or the symbol
1483 @var{service} is the D-Bus service name of the D-Bus. It must be a
1484 known name. Emacs releases its association to @var{service} from
1490 @chapter Sending and receiving signals.
1493 Signals are broadcast messages. They carry input parameters, which
1494 are received by all objects which have registered for such a signal.
1496 @defun dbus-send-signal bus service path interface signal &rest args
1497 This function is similar to @code{dbus-call-method}. The difference
1498 is, that there are no returning output parameters.
1500 The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is
1501 either the symbol @code{:system} or the symbol @code{:session}. It
1502 doesn't matter whether another object has registered for @var{signal}.
1504 @var{service} is the D-Bus service name of the object the signal is
1505 emitted from. @var{path} is the corresponding D-Bus object path,
1506 @var{service} is registered at. @var{interface} is an interface
1507 offered by @var{service}. It must provide @var{signal}.
1509 All other arguments args are passed to @var{signal} as arguments.
1510 They are converted into D-Bus types as described in @ref{Type
1511 Conversion}. Example:
1515 :session dbus-service-emacs dbus-path-emacs
1516 (concat dbus-service-emacs ".FileManager") "FileModified"
1517 "/home/albinus/.emacs")
1521 @defun dbus-register-signal bus service path interface signal handler &rest args
1522 With this function, an application registers for @var{signal} on the
1525 @var{bus} is either the symbol @code{:system} or the symbol
1528 @var{service} is the D-Bus service name used by the sending D-Bus
1529 object. It can be either a known name or the unique name of the D-Bus
1530 object sending the signal. In case of a unique name, signals won't be
1531 received any longer once the object owning this unique name has
1532 disappeared, and a new queued object has replaced it.
1534 When @var{service} is @code{nil}, related signals from all D-Bus
1535 objects shall be accepted.
1537 @var{path} is the corresponding D-Bus object path, @var{service} is
1538 registered at. It can also be @code{nil} if the path name of incoming
1539 signals shall not be checked.
1541 @var{interface} is an interface offered by @var{service}. It must
1542 provide @var{signal}.
1544 @var{handler} is a Lisp function to be called when the @var{signal} is
1545 received. It must accept as arguments the output parameters
1546 @var{signal} is sending.
1548 All other arguments @var{args}, if specified, must be strings. They
1549 stand for the respective arguments of @var{signal} in their order, and
1550 are used for filtering as well. A @code{nil} argument might be used
1551 to preserve the order.
1553 @code{dbus-register-signal} returns a Lisp object, which can be used
1554 as argument in @code{dbus-unregister-object} for removing the
1555 registration for @var{signal}. Example:
1558 (defun my-dbus-signal-handler (device)
1559 (message "Device %s added" device))
1561 @result{} my-dbus-signal-handler
1563 (dbus-register-signal
1564 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
1565 "org.freedesktop.Hal.Manager" "DeviceAdded"
1566 'my-dbus-signal-handler)
1568 @result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
1569 ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
1573 As we know from the introspection data of interface
1574 @samp{org.freedesktop.Hal.Manager}, the signal @samp{DeviceAdded}
1575 provides one single parameter, which is mapped into a Lisp string.
1576 The callback function @code{my-dbus-signal-handler} must define one
1577 single string argument therefore. Plugging an USB device to your
1578 machine, when registered for signal @samp{DeviceAdded}, will show you
1579 which objects the GNU/Linux @code{hal} daemon adds.
1583 @node Alternative Buses
1584 @chapter Alternative buses.
1586 @cindex UNIX domain socket
1588 Until now, we have spoken about the system and the session buses,
1589 which are the default buses to be connected to. However, it is
1590 possible to connect to any bus, from which the address is known. This
1591 is a UNIX domain socket. Everywhere, where a @var{bus} is mentioned
1592 as argument of a function (the symbol @code{:system} or the symbol
1593 @code{:session}), this address can be used instead. The connection to
1594 this bus must be initialized first.
1596 @defun dbus-init-bus bus
1597 Establish the connection to D-Bus @var{bus}.
1599 @var{bus} can be either the symbol @code{:system} or the symbol
1600 @code{:session}, or it can be a string denoting the address of the
1601 corresponding bus. For the system and session busses, this function
1602 is called when loading @file{dbus.el}, there is no need to call it
1605 Example: You open another session bus in a terminal window on your host:
1608 # eval `dbus-launch --auto-syntax`
1609 # echo $DBUS_SESSION_BUS_ADDRESS
1611 @print{} unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e
1614 In Emacs, you can access to this bus via its address:
1618 "unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e")
1620 @result{} "unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e"
1622 (dbus-init-bus my-bus)
1626 (dbus-get-unique-name my-bus)
1633 @node Errors and Events
1634 @chapter Errors and events.
1639 The internal actions can be traced by running in a debug mode.
1642 If this variable is non-@code{nil}, D-Bus specific debug messages are raised.
1645 Input parameters of @code{dbus-call-method},
1646 @code{dbus-call-method-non-blocking},
1647 @code{dbus-call-method-asynchronously}, and
1648 @code{dbus-register-signal} are checked for correct D-Bus types. If
1649 there is a type mismatch, the Lisp error @code{wrong-type-argument}
1650 @code{D-Bus ARG} is raised.
1652 All errors raised by D-Bus are signaled with the error symbol
1653 @code{dbus-error}. If possible, error messages from D-Bus are
1654 appended to the @code{dbus-error}.
1656 @defspec dbus-ignore-errors forms@dots{}
1657 This executes @var{forms} exactly like a @code{progn}, except that
1658 @code{dbus-error} errors are ignored during the @var{forms}. These
1659 errors can be made visible when @code{dbus-debug} is set to @code{t}.
1662 Incoming D-Bus messages are handled as Emacs events, see @pxref{Misc
1663 Events, , , elisp}. They are retrieved only, when Emacs runs in
1664 interactive mode. The generated event has this form:
1667 (dbus-event @var{bus} @var{type} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler}
1671 @var{bus} identifies the D-Bus the message is coming from. It is
1672 either the symbol @code{:system} or the symbol @code{:session}.
1674 @var{type} is the D-Bus message type which has caused the event. It
1675 can be @code{dbus-message-type-invalid},
1676 @code{dbus-message-type-method-call},
1677 @code{dbus-message-type-method-return},
1678 @code{dbus-message-type-error}, or @code{dbus-message-type-signal}.
1679 @var{serial} is the serial number of the received D-Bus message.
1681 @var{service} and @var{path} are the unique name and the object path
1682 of the D-Bus object emitting the message. @var{interface} and
1683 @var{member} denote the message which has been sent.
1685 @var{handler} is the callback function which has been registered for
1686 this message (see @pxref{Signals}). When a @code{dbus-event} event
1687 arrives, @var{handler} is called with @var{args} as arguments.
1689 In order to inspect the @code{dbus-event} data, you could extend the
1690 definition of the callback function in @ref{Signals}:
1693 (defun my-dbus-signal-handler (&rest args)
1694 (message "my-dbus-signal-handler: %S" last-input-event))
1697 There exist convenience functions which could be called inside a
1698 callback function in order to retrieve the information from the event.
1700 @defun dbus-event-bus-name event
1701 Returns the bus name @var{event} is coming from.
1702 The result is either the symbol @code{:system} or the symbol @code{:session}.
1705 @defun dbus-event-message-type event
1706 Returns the message type of the corresponding D-Bus message. The
1707 result is a natural number.
1710 @defun dbus-event-serial-number event
1711 Returns the serial number of the corresponding D-Bus message.
1712 The result is a natural number.
1715 @defun dbus-event-service-name event
1716 Returns the unique name of the D-Bus object @var{event} is coming from.
1719 @defun dbus-event-path-name event
1720 Returns the object path of the D-Bus object @var{event} is coming from.
1723 @defun dbus-event-interface-name event
1724 Returns the interface name of the D-Bus object @var{event} is coming from.
1727 @defun dbus-event-member-name event
1728 Returns the member name of the D-Bus object @var{event} is coming
1729 from. It is either a signal name or a method name.
1732 D-Bus errors are not propagated during event handling, because it is
1733 usually not desired. D-Bus errors in events can be made visible by
1734 setting the variable @code{dbus-debug} to @code{t}. They can also be
1735 handled by a hook function.
1737 @defvar dbus-event-error-hooks
1738 This hook variable keeps a list of functions, which are called when a
1739 D-Bus error happens in the event handler. Every function must accept
1740 two arguments, the event and the error variable catched in
1741 @code{condition-case} by @code{dbus-error}.
1743 Such functions can be used the adapt the error signal to be raised.
1747 (defun my-dbus-event-error-handler (event error)
1748 (when (string-equal (concat dbus-service-emacs ".FileManager")
1749 (dbus-event-interface-name event))
1750 (message "my-dbus-event-error-handler: %S %S" event error)
1751 (signal 'file-error (cdr error))))
1753 (add-hook 'dbus-event-error-hooks 'my-dbus-event-error-handler)
1757 Hook functions shall take into account, that there might be other
1758 D-Bus applications running. Therefore, they shall check carefully,
1759 whether a given D-Bus error is related to them.
1768 @node GNU Free Documentation License
1769 @appendix GNU Free Documentation License
1770 @include doclicense.texi
1775 arch-tag: 2eeec19d-0caf-44e0-a193-329d7f9951d8