Comment.
[emacs.git] / doc / misc / dbus.texi
blobe303eb08599d194816d949cd64cfa7134c1d951f
1 \input texinfo   @c -*-texinfo-*-
2 @setfilename ../../info/dbus
3 @c %**start of header
4 @settitle Using of D-Bus
5 @c @setchapternewpage odd
6 @c %**end of header
8 @copying
9 Copyright @copyright{} 2007, 2008 Free Software Foundation, Inc.
11 @quotation
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
16 Manual'', and with the Back-Cover Texts as in (a) below.  A copy of the
17 license is included in the section entitled ``GNU Free Documentation
18 License'' in the Emacs manual.
20 (a) The FSF's Back-Cover Text is: ``You have freedom to copy and modify
21 this GNU Manual, like GNU software.  Copies published by the Free
22 Software Foundation raise funds for GNU development.''
24 This document is part of a collection distributed under the GNU Free
25 Documentation License.  If you want to distribute this document
26 separately from the collection, you can do so by adding a copy of the
27 license to the document, as described in section 6 of the license.
28 @end quotation
29 @end copying
31 @dircategory Emacs
32 @direntry
33 * D-Bus: (dbus).                Using D-Bus in Emacs.
34 @end direntry
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
40 Emacs.@footnote{D-Bus is not enabled by default.  You must run
41 @command{./configure --with-dbus} in Emacs' top level directory,
42 before you compile Emacs.}  D-Bus is a message bus system, a simple
43 way for applications to talk to one another.  An overview of D-Bus can
44 be found at @uref{http://dbus.freedesktop.org/}.
46 @insertcopying
48 @menu
49 * Overview::                    An overview of D-Bus.
50 * Inspection::                  Inspection of the bus names.
51 * Type Conversion::             Mapping Lisp types and D-Bus types.
52 * Synchronous Methods::         Calling methods in a blocking way.
53 * Receiving Method Calls::      Offering own methods.
54 * Signals::                     Sending and receiving signals.
55 * Errors and Events::           Errors and events.
56 * GNU Free Documentation License:: The license for this documentation.
57 @end menu
59 @node Overview
60 @chapter An overview of D-Bus
61 @cindex overview
63 D-Bus is an inter-process communication mechanism for applications
64 residing on the same host.  The communication is based on
65 @dfn{messages}.  Data in the messages is carried in a structured way,
66 it is not just a byte stream.
68 The communication is connection oriented to two kinds of message
69 buses: a so called @dfn{system bus}, and a @dfn{session bus}.  On a
70 given machine, there is always one single system bus for miscellaneous
71 system-wide communication, like changing of hardware configuration.
72 On the other hand, the session bus is always related to a single
73 user's session.
75 Every client application, which is connected to a bus, registers under
76 a @dfn{unique name} at the bus.  This name is used for identifying the
77 client application.  Such a unique name starts always with a colon,
78 and looks like @samp{:1.42}.
80 Additionally, a client application can register itself to a so called
81 @dfn{known name}, which is a series of identifiers separated by dots,
82 as in @samp{org.gnu.Emacs}.  If several applications register to the
83 same known name, these registrations are queued, and only the first
84 application which has registered for the known name is reachable via
85 this name.  If this application disconnects from the bus, the next
86 queued unique name becomes the owner of this known name.
88 An application can install one or several objects under its name.
89 Such objects are identified by an @dfn{object path}, which looks
90 similar to paths in a filesystem.  An example of such an object path
91 could be @samp{/org/gnu/Emacs/}.
93 Applications might send a request to an object, that means sending a
94 message with some data as input parameters, and receiving a message
95 from that object with the result of this message, the output
96 parameters.  Such a request is called @dfn{method} in D-Bus.
98 The other form of communication are @dfn{signals}.  The underlying
99 message is emitted from an object and will be received by all other
100 applications which have registered for such a signal.
102 All methods and signals an object supports are called @dfn{interface}
103 of the object.  Interfaces are specified under a hierarchical name in
104 D-Bus; an object can support several interfaces.  Such an interface
105 name could be @samp{org.gnu.Emacs.TextEditor} or
106 @samp{org.gnu.Emacs.FileManager}.
109 @node Inspection
110 @chapter Inspection of the bus names.
111 @cindex inspection
113 There are several basic functions which inspect the buses for
114 registered names.  Internally they use the basic interface
115 @samp{org.freedesktop.DBus}, which is supported by all objects of a bus.
117 @defun dbus-list-activatable-names
118 This function returns the D-Bus service names, which can be activated.
119 An activatable service is described in a service registration file.
120 Under GNU/Linux, such files are located at
121 @file{/usr/share/dbus-1/services/}.
123 The result is a list of strings, which is @code{nil} when there are no
124 activatable service names at all.
125 @end defun
127 @defun dbus-list-names bus
128 All service names, which are registered at D-Bus @var{bus}, are
129 returned.  The result is a list of strings, which is @code{nil} when
130 there are no registered service names at all.  Well known names are
131 strings like @samp{org.freedesktop.DBus}.  Names starting with
132 @samp{:} are unique names for services.
134 @var{bus} must be either the symbol @code{:system} or the symbol
135 @code{:session}.
136 @end defun
138 @defun dbus-list-known-names bus
139 Retrieves all services which correspond to a known name in @var{bus}.
140 A service has a known name if it doesn't start with @samp{:}.  The
141 result is a list of strings, which is @code{nil} when there are no
142 known names at all.
144 @var{bus} must be either the symbol @code{:system} or the symbol
145 @code{:session}.
146 @end defun
148 @defun dbus-list-queued-owners bus service
149 For a given service, registered at D-Bus @var{bus} under the name
150 @var{service}, all queued unique names are returned.  The result is a
151 list of strings, or @code{nil} when there are no queued names for
152 @var{service} at all.
154 @var{bus} must be either the symbol @code{:system} or the symbol
155 @code{:session}.  @var{service} must be a known service name as
156 string.
157 @end defun
159 @defun dbus-get-name-owner bus service
160 For a given service, registered at D-Bus @var{bus} under the name
161 @var{service}, the unique name of the name owner is returned.  The
162 result is a string, or @code{nil} when there exist no name owner of
163 @var{service}.
165 @var{bus} must be either the symbol @code{:system} or the symbol
166 @code{:session}.  @var{service} must be a known service name as
167 string.
168 @end defun
170 @defun dbus-ping bus service
171 Check whether the service name @var{service} is registered at D-Bus
172 @var{bus}.  @var{service} might not have been started yet.  The result
173 is either @code{t} or @code{nil}.
175 @var{bus} must be either the symbol @code{:system} or the symbol
176 @code{:session}.  @var{service} must be a string.  Example:
178 @lisp
179 (message
180    "%s screensaver on board."
181    (cond
182      ((dbus-ping :session "org.gnome.ScreenSaver") "Gnome")
183      ((dbus-ping :session "org.freedesktop.ScreenSaver") "KDE")
184      (t "No")))
185 @end lisp
186 @end defun
188 @defun dbus-get-unique-name bus
189 The unique name, under which Emacs is registered at D-Bus @var{bus},
190 is returned as string.
192 @var{bus} must be either the symbol @code{:system} or the symbol
193 @code{:session}.
194 @end defun
196 @defun dbus-introspect bus service path
197 Objects can publish there interfaces to the D-Bus.  This function
198 returns all interfaces of @var{service}, registered at object path
199 @var{path} at bus @var{bus}.
201 @var{bus} must be either the symbol @code{:system} or the symbol
202 @code{:session}.  @var{service} must be a known service name, and
203 @var{path} must be a valid object path.  The last two parameters are
204 strings.  The result, the introspection data, is a string in XML
205 format. Example:
207 @lisp
208 (dbus-introspect
209   :system "org.freedesktop.Hal"
210   "/org/freedesktop/Hal/devices/computer")
212 @result{} "<!DOCTYPE node PUBLIC
213     \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"
214     \"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">
215     <node>
216       <interface name=\"org.freedesktop.Hal.Device\">
217         <method name=\"GetAllProperties\">
218           <arg name=\"properties\" direction=\"out\" type=\"a@{sv@}\"/>
219         </method>
220         @dots{}
221         <signal name=\"PropertyModified\">
222           <arg name=\"num_updates\" type=\"i\"/>
223           <arg name=\"updates\" type=\"a(sbb)\"/>
224         </signal>
225       </interface>
226       @dots{}
227     </node>"
228 @end lisp
230 This example informs us, that the service @code{org.freedesktop.Hal}
231 at object path @code{/org/freedesktop/Hal/devices/computer} offers the
232 interface @code{org.freedesktop.Hal.Device} (and 2 other interfaces
233 not documented here).  This interface contains the method
234 @code{GetAllProperties}, which needs no input parameters, but returns
235 as output parameter an array of dictionary entries (key-value pairs).
236 Every dictionary entry has a string as key, and a variant as value.
238 The interface offers also a signal, which returns 2 parameters: an
239 integer, and an array consisting of elements which are a struct of a
240 string and 2 boolean values.
242 Such type descriptions are called @dfn{signature} in D-Bus.  For a
243 discussion of D-Bus types and their Lisp representation see @ref{Type
244 Conversion}.@footnote{D-Bus signatures are explained in the D-Bus
245 specification
246 @uref{http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures}.
247 The interfaces of the service @code{org.freedesktop.Hal} are described
249 @uref{http://people.freedesktop.org/~david/hal-spec/hal-spec.html#interfaces}.}
250 @end defun
253 @node Type Conversion
254 @chapter Mapping Lisp types and D-Bus types.
255 @cindex type conversion
257 D-Bus method calls and signals accept usually several arguments as
258 parameters, either as input parameter, or as output parameter.  Every
259 argument belongs to a D-Bus type.
261 Such arguments must be mapped between the value encoded as a D-Bus
262 type, and the corresponding type of Lisp objects.  The mapping is
263 applied Lisp object @expansion{} D-Bus type for input parameters, and
264 D-Bus type @expansion{} Lisp object for output parameters.
267 @section Input parameters.
269 Input parameters for D-Bus methods and signals occur as arguments of a
270 Lisp function call.  The following mapping to D-Bus types is
271 applied, when the corresponding D-Bus message is created:
273 @example
274 @multitable {@code{t} and @code{nil}} {@expansion{}} {DBUS_TYPE_BOOLEAN}
275 @item Lisp type               @tab              @tab D-Bus type
276 @item
277 @item @code{t} and @code{nil} @tab @expansion{} @tab DBUS_TYPE_BOOLEAN
278 @item number                  @tab @expansion{} @tab DBUS_TYPE_UINT32
279 @item integer                 @tab @expansion{} @tab DBUS_TYPE_INT32
280 @item float                   @tab @expansion{} @tab DBUS_TYPE_DOUBLE
281 @item string                  @tab @expansion{} @tab DBUS_TYPE_STRING
282 @item list                    @tab @expansion{} @tab DBUS_TYPE_ARRAY
283 @end multitable
284 @end example
286 Other Lisp objects, like symbols or hash tables, are not accepted as
287 input parameter.
289 If it is necessary to use another D-Bus type, a corresponding type
290 symbol can be preceeded to the corresponding Lisp object. Basic D-Bus
291 types are represented by the type symbols @code{:byte},
292 @code{:boolean}, @code{:int16}, @code{:uint16}, @code{:int32},
293 @code{:uint32}, @code{:int64}, @code{:uint64}, @code{:double},
294 @code{:string}, @code{:object-path} and @code{:signature}.
296 @noindent
297 Example:
299 @lisp
300 (dbus-call-method @dots{} @var{NUMBER} @var{STRING})
301 @end lisp
303 is equivalent to
305 @lisp
306 (dbus-call-method @dots{} :uint32 @var{NUMBER} :string @var{STRING})
307 @end lisp
309 but different to
311 @lisp
312 (dbus-call-method @dots{} :int32 @var{NUMBER} :signature @var{STRING})
313 @end lisp
315 The value for a byte D-Bus type can be any integer in the range 0
316 through 255.  If a character is used as argument, modifiers
317 represented outside this range are stripped of.  For example,
318 @code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to
319 @code{:byte ?\C-x} or @code{:byte ?\M-\C-x}.
321 A D-Bus compound type is always represented as a list.  The @sc{car}
322 of this list can be the type symbol @code{:array}, @code{:variant},
323 @code{:struct} or @code{:dict-entry}, which would result in a
324 corresponding D-Bus container.  @code{:array} is optional, because
325 this is the default compound D-Bus type for a list.
327 The objects being elements of the list are checked according to the
328 D-Bus compound type rules.
330 @itemize
331 @item An array must contain only elements of the same D-Bus type.  It
332 can be empty.
334 @item A variant must contain only one single element.
336 @item A dictionary entry must be element of an array, and it must
337 contain only a key-value pair of two elements, with a basic D-Bus type
338 key.
340 @item There is no restriction for structs.
341 @end itemize
343 If an empty array needs an element D-Bus type other than string, it
344 can contain exactly one element of D-Bus type @code{:signature}.  The
345 value of this element (a string) is used as the signature of the
346 elements of this array.  Example:
348 @lisp
349 (dbus-call-method
350   :session "org.freedesktop.Notifications"
351   "/org/freedesktop/Notifications"
352   "org.freedesktop.Notifications" "Notify"
353   "GNU Emacs"                 ;; Application name.
354   0                           ;; No replacement of other notifications.
355   ""                          ;; No icon.
356   "Notification summary"      ;; Summary.
357   (format                     ;; Body.
358     "This is a test notification, raised from %s" (emacs-version))
359   '(:array)                   ;; No actions (empty array of strings).
360   '(:array :signature "@{sv@}") ;; No hints
361                               ;; (empty array of dictionary entries).
362   ':int32 -1)                 ;; Default timeout.
364 @result{} 3
365 @end lisp
368 @section Output parameters.
370 Output parameters of D-Bus methods and signals are mapped to Lisp
371 objects.
373 @example
374 @multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {@code{t} or @code{nil}}
375 @item D-Bus type            @tab              @tab Lisp type
376 @item
377 @item DBUS_TYPE_BOOLEAN     @tab @expansion{} @tab @code{t} or @code{nil}
378 @item DBUS_TYPE_BYTE        @tab @expansion{} @tab number
379 @item DBUS_TYPE_UINT16      @tab @expansion{} @tab number
380 @item DBUS_TYPE_INT16       @tab @expansion{} @tab number
381 @item DBUS_TYPE_UINT32      @tab @expansion{} @tab number or float
382 @item DBUS_TYPE_INT32       @tab @expansion{} @tab number or float
383 @item DBUS_TYPE_UINT64      @tab @expansion{} @tab number or float
384 @item DBUS_TYPE_INT64       @tab @expansion{} @tab number or float
385 @item DBUS_TYPE_DOUBLE      @tab @expansion{} @tab float
386 @item DBUS_TYPE_STRING      @tab @expansion{} @tab string
387 @item DBUS_TYPE_OBJECT_PATH @tab @expansion{} @tab string
388 @item DBUS_TYPE_SIGNATURE   @tab @expansion{} @tab string
389 @item DBUS_TYPE_ARRAY       @tab @expansion{} @tab list
390 @item DBUS_TYPE_VARIANT     @tab @expansion{} @tab list
391 @item DBUS_TYPE_STRUCT      @tab @expansion{} @tab list
392 @item DBUS_TYPE_DICT_ENTRY  @tab @expansion{} @tab list
393 @end multitable
394 @end example
396 A float object in case of @code{DBUS_TYPE_UINT32},
397 @code{DBUS_TYPE_INT32}, @code{DBUS_TYPE_UINT64} and
398 @code{DBUS_TYPE_INT6432} is returned, when the C value exceeds the
399 Emacs number size range.
401 The resulting list of the last 4 D-Bus compound types contains as
402 elements the elements of the D-Bus container, mapped according to the
403 same rules.
405 The signal @code{PropertyModified}, discussed as example in
406 @ref{Inspection}, would offer as Lisp data the following object
407 (@var{BOOL} stands here for either @code{nil} or @code{t}):
409 @lisp
410 (@var{NUMBER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
411 @end lisp
414 @node Synchronous Methods
415 @chapter Calling methods in a blocking way.
416 @cindex method calls, synchronous
417 @cindex synchronous method calls
419 Methods can be called synchronously (@dfn{blocking}) or asynchronously
420 (@dfn{non-blocking}).  Currently, just synchronous methods are
421 implemented.
423 At D-Bus level, a method call consist of two messages: one message
424 which carries the input parameters to the object owning the method to
425 be called, and a reply message returning the resulting output
426 parameters from the object.
428 @defun dbus-call-method bus service path interface method &rest args
429 This function calls @var{method} on the D-Bus @var{bus}.  @var{bus} is
430 either the symbol @code{:system} or the symbol @code{:session}.
432 @var{service} is the D-Bus service name to be used.  @var{path} is the
433 D-Bus object path, @var{service} is registered at.  @var{interface} is
434 an interface offered by @var{service}.  It must provide @var{method}.
436 All other arguments args are passed to @var{method} as arguments.
437 They are converted into D-Bus types as described in @ref{Type
438 Conversion}.
440 The function returns the resulting values of @var{method} as a list of
441 Lisp objects, according to the type conversion rules described in
442 @ref{Type Conversion}.  Example:
444 @lisp
445 (dbus-call-method
446   :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
447   "org.gnome.seahorse.Keys" "GetKeyField"
448   "openpgp:657984B8C7A966DD" "simple-name")
450 @result{} (t ("Philip R. Zimmermann"))
451 @end lisp
453 If the result of the method call is just one value, the converted Lisp
454 object is returned instead of a list containing this single Lisp
455 object.  Example:
457 @lisp
458 (dbus-call-method
459   :system "org.freedesktop.Hal"
460   "/org/freedesktop/Hal/devices/computer"
461   "org.freedesktop.Hal.Device" "GetPropertyString"
462   "system.kernel.machine")
464 @result{} "i686"
465 @end lisp
467 With the @code{dbus-introspect} function it is possible to explore the
468 interfaces of @samp{org.freedesktop.Hal} service. It offers the
469 interfaces @samp{org.freedesktop.Hal.Manager} for the object at the
470 path @samp{/org/freedesktop/Hal/Manager} as well as the interface
471 @samp{org.freedesktop.Hal.Device} for all objects prefixed with the
472 path @samp{/org/freedesktop/Hal/devices}.  With the methods
473 @samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to
474 emulate the @code{lshal} command on GNU/Linux systems:
476 @lisp
477 (dolist (device
478           (dbus-call-method
479             :system "org.freedesktop.Hal"
480             "/org/freedesktop/Hal/Manager"
481             "org.freedesktop.Hal.Manager" "GetAllDevices"))
482   (message "\nudi = %s" device)
483   (dolist (properties
484             (dbus-call-method
485               :system "org.freedesktop.Hal" device
486               "org.freedesktop.Hal.Device" "GetAllProperties"))
487     (message "  %s = %S"
488              (car properties) (or (caar (cdr properties)) ""))))
490 @print{} "udi = /org/freedesktop/Hal/devices/computer
491       info.addons = (\"hald-addon-acpi\")
492       info.bus = \"unknown\"
493       info.product = \"Computer\"
494       info.subsystem = \"unknown\"
495       info.udi = \"/org/freedesktop/Hal/devices/computer\"
496       linux.sysfs_path_device = \"(none)\"
497       power_management.acpi.linux.version = \"20051216\"
498       power_management.can_suspend_to_disk = t
499       power_management.can_suspend_to_ram = \"\"
500       power_management.type = \"acpi\"
501       smbios.bios.release_date = \"11/07/2001\"
502       system.chassis.manufacturer = \"COMPAL\"
503       system.chassis.type = \"Notebook\"
504       system.firmware.release_date = \"03/19/2005\"
505       @dots{}"
506 @end lisp
507 @end defun
510 @node Receiving Method Calls
511 @chapter Offering own methods.
512 @cindex method calls, returning
513 @cindex returning method calls
515 Emacs can also offer own methods, which can be called by other
516 applications.  These methods could be an implementation of an
517 interface of a well known service, like @code{org.freedesktop.TextEditor}.
519 It could be also an implementation of an own interface.  In this case,
520 the service name must be @code{org.gnu.Emacs}.  The object path shall
521 begin with @code{/org/gnu/Emacs/@strong{Application}/}, and the
522 interface name shall be @code{org.gnu.Emacs.@strong{Application}}.
523 @code{@strong{Application}} is the name of the application which
524 provides the interface.
526 @defun dbus-register-method bus service path interface method handler
527 With this function, an application registers @var{method} on the D-Bus
528 @var{bus}.
530 @var{bus} is either the symbol @code{:system} or the symbol
531 @code{:session}.
533 @var{service} is the D-Bus service name of the D-Bus object
534 @var{method} is registered for.  It must be a known name.
536 @var{path} is the D-Bus object path @var{service} is
537 registered.
539 @var{interface} is the interface offered by @var{service}.  It must
540 provide @var{method}.
542 @var{handler} is a Lisp function to be called when when a @var{method}
543 call is is received.  It must accept as arguments the input arguments
544 of @var{method}.  @var{handler} must return a list, which elements are
545 used as arguments for the reply message of @var{method}.  This list
546 can be composed like the input parameters in @ref{Type Conversion}.
548 The default D-Bus timeout when waiting for a message reply is 25
549 seconds.  Therefore, @var{handler} shall not last longer than
550 absolutely necessary.
552 @code{dbus-register-method} returns a Lisp symbol, which can be used
553 as argument in @code{dbus-unregister-object} for removing the
554 registration for @var{method}.  Example:
556 @lisp
557 (defun my-dbus-method-handler (filename)
558   (let (result)
559     (if (find-file filename)
560         (setq result '(:boolean t))
561       (setq result '(:boolean nil)))
562     result))
564 @result{} my-dbus-method-handler
566 (dbus-register-method
567   :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
568   "org.freedesktop.TextEditor" "OpenFile"
569   'my-dbus-method-handler)
571 @result{} ((:system "org.freedesktop.TextEditor" "OpenFile")
572     ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
573      my-method-handler))
574 @end lisp
576 If you invoke the method @code{org.freedesktop.TextEditor.OpenFile}
577 from another D-Bus application with a filename as parameter, the file
578 is opened in Emacs, and the method returns either @var{true} or
579 @var{false}, indicating the success if the method.  As test tool one
580 could use the command line tool @code{dbus-send} in a shell:
582 @example
583 # dbus-send --session --print-reply \
584     --dest="org.freedesktop.TextEditor" \
585     "/org/freedesktop/TextEditor" \
586     "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts"
588 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2
589      boolean true
590 @end example
591 @end defun
594 @node Signals
595 @chapter Sending and receiving signals.
596 @cindex signals
598 Signals are broadcast messages.  They carry input parameters, which
599 are received by all objects which have registered for such a signal.
601 @defun dbus-send-signal bus service path interface signal &rest args
602 This function is similar to @code{dbus-call-method}.  The difference
603 is, that there are no returning output parameters.
605 The function emits @var{signal} on the D-Bus @var{bus}.  @var{bus} is
606 either the symbol @code{:system} or the symbol @code{:session}.  It
607 doesn't matter whether another object has registered for @var{signal}.
609 @var{service} is the D-Bus service name of the object the signal is
610 emitted from.  @var{path} is the corresponding D-Bus object path,
611 @var{service} is registered at.  @var{interface} is an interface
612 offered by @var{service}.  It must provide @var{signal}.
614 All other arguments args are passed to @var{signal} as arguments.
615 They are converted into D-Bus types as described in @ref{Type
616 Conversion}.  Example:
618 @lisp
619 (dbus-send-signal
620   :session "org.gnu.Emacs" "/org/gnu/Emacs"
621   "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
622 @end lisp
623 @end defun
625 @defun dbus-register-signal bus service path interface signal handler
626 With this function, an application registers for @var{signal} on the
627 D-Bus @var{bus}.
629 @var{bus} is either the symbol @code{:system} or the symbol
630 @code{:session}.
632 @var{service} is the D-Bus service name used by the sending D-Bus
633 object.  It can be either a known name or the unique name of the D-Bus
634 object sending the signal.  In case of a unique name, signals won't be
635 received any longer once the object owning this unique name has
636 disappeared, and a new queued object has replaced it.
638 When @var{service} is @code{nil}, related signals from all D-Bus
639 objects shall be accepted.
641 @var{path} is the corresponding D-Bus object path, @var{service} is
642 registered at.  It can also be @code{nil} if the path name of incoming
643 signals shall not be checked.
645 @var{interface} is an interface offered by @var{service}.  It must
646 provide @var{signal}.
648 @var{handler} is a Lisp function to be called when the @var{signal} is
649 received.  It must accept as arguments the output parameters
650 @var{signal} is sending.  Example:
652 @lisp
653 (defun my-dbus-signal-handler (device)
654   (message "Device %s added" device))
656 @result{} my-dbus-signal-handler
658 (dbus-register-signal
659   :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
660   "org.freedesktop.Hal.Manager" "DeviceAdded"
661   'my-dbus-signal-handler)
663 @result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
664     ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
665      my-signal-handler))
666 @end lisp
668 As we know from the inspection data of interface
669 @code{org.freedesktop.Hal.Manager}, the signal @code{DeviceAdded}
670 provides one single parameter, which is mapped into a Lisp string.
671 The callback function @code{my-dbus-signal-handler} must define one
672 single string argument therefore.  Plugging an USB device to your
673 machine, when registered for signal @code{DeviceAdded}, will show you
674 which objects the GNU/Linux @code{hal} daemon adds.
676 @code{dbus-register-signal} returns a Lisp symbol, which can be used
677 as argument in @code{dbus-unregister-object} for removing the
678 registration for @var{signal}.
679 @end defun
681 @defun dbus-unregister-object object
682 Unregister @var{object} from the the D-Bus.  @var{object} must be the
683 result of a preceding @code{dbus-register-signal} or
684 @code{dbus-register-method} call.  It returns @code{t} if @var{object}
685 has been unregistered, @code{nil} otherwise.
686 @end defun
689 @node Errors and Events
690 @chapter Errors and events.
691 @cindex errors
692 @cindex events
694 Input parameters of @code{dbus-call-method} and
695 @code{dbus-register-signal} are checked for correct D-Bus types. If
696 there is a type mismatch, the Lisp error @code{wrong-type-argument}
697 @code{D-Bus ARG} is raised.
699 All errors raised by D-Bus are signaled with the error symbol
700 @code{dbus-error}.  If possible, error messages from D-Bus are
701 appended to the @code{dbus-error}.
703 @defspec dbus-ignore-errors forms@dots{}
704 This executes @var{forms} exactly like a @code{progn}, except that
705 @code{dbus-error} errors are ignored during the @var{forms}.  These
706 errors can be made visible when variable @code{dbus-debug} is set to
707 @code{t}.
708 @end defspec
710 Incoming D-Bus messages are handled as Emacs events (see @pxref{Misc
711 Events, , , elisp}).  The generated event has this form:
713 @lisp
714 (dbus-event @var{bus} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler} &rest @var{args})
715 @end lisp
717 @var{bus} identifies the D-Bus the signal is coming from.  It is
718 either the symbol @code{:system} or the symbol @code{:session}.
720 @var{serial} is the serial number of the received D-Bus message if it
721 is a method call, or @code{nil}.
723 @var{service} and @var{path} are the unique name and the object path
724 of the D-Bus object emitting the message.  @var{interface} and
725 @var{member} denote the message which has been sent.
727 @var{handler} is the callback function which has been registered for
728 this message (see @pxref{Signals}).  When a @code{dbus-event} event
729 arrives, @var{handler} is called with @var{args} as arguments.
731 In order to inspect the @code{dbus-event} data, you could extend the
732 definition of the callback function in @ref{Signals}:
734 @lisp
735 (defun my-dbus-signal-handler (&rest args)
736   (message "my-dbus-signal-handler: %S" last-input-event))
737 @end lisp
739 There exist convenience functions which could be called inside a
740 callback function in order to retrieve the information from the event.
742 @defun dbus-event-bus-name event
743 Returns the bus name @var{event} is coming from.
744 The result is either the symbol @code{:system} or the symbol @code{:session}.
745 @end defun
747 @defun dbus-event-serial-number event
748 Returns the serial number of the corresponding D-Bus message.
749 The result is a number in case the D-Bus message is a method
750 call, or @code{nil} for all other mesage types.
751 @end defun
753 @defun dbus-event-service-name event
754 Returns the unique name of the D-Bus object @var{event} is coming from.
755 @end defun
757 @defun dbus-event-path-name event
758 Returns the object path of the D-Bus object @var{event} is coming from.
759 @end defun
761 @defun dbus-event-interface-name event
762 Returns the interface name of of the D-Bus object @var{event} is coming from.
763 @end defun
765 @defun dbus-event-member-name event
766 Returns the member name of of the D-Bus object @var{event} is coming
767 from.  It is either a signal name or a method name.
768 @end defun
770 D-Bus errors are not propagated during event handling, because it is
771 usually not desired.  D-Bus errors in events can be made visible by
772 setting the variable @code{dbus-debug} to @code{t}.
775 @node GNU Free Documentation License
776 @appendix GNU Free Documentation License
777 @include doclicense.texi
779 @contents
780 @c End of dbus.texi
781 @bye
783 @ignore
784    arch-tag: 2eeec19d-0caf-44e0-a193-329d7f9951d8
785 @end ignore