Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / doc / misc / dbus.texi
CommitLineData
22d8ac3a
MA
1\input texinfo @c -*-texinfo-*-
2@setfilename ../../info/dbus
3@c %**start of header
4@settitle Using of D-Bus
5@c @setchapternewpage odd
6@c %**end of header
7
5bd55c3c
MA
8@syncodeindex vr cp
9@syncodeindex fn cp
10
22d8ac3a 11@copying
73b0cd50 12Copyright @copyright{} 2007-2011 Free Software Foundation, Inc.
22d8ac3a
MA
13
14@quotation
15Permission is granted to copy, distribute and/or modify this document
6a2c4aec 16under the terms of the GNU Free Documentation License, Version 1.3 or
22d8ac3a 17any later version published by the Free Software Foundation; with no
debf4439
GM
18Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
19and with the Back-Cover Texts as in (a) below. A copy of the license
20is included in the section entitled ``GNU Free Documentation License''.
22d8ac3a 21
6f093307
GM
22(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
23modify this GNU manual. Buying copies from the FSF supports it in
24developing GNU and promoting software freedom.''
22d8ac3a
MA
25@end quotation
26@end copying
27
28@dircategory Emacs
29@direntry
30* D-Bus: (dbus). Using D-Bus in Emacs.
31@end direntry
32
5dc584b5 33@contents
cd71b9ae 34
977640ed 35
22d8ac3a
MA
36@node Top, Overview, (dir), (dir)
37@top D-Bus integration in Emacs
38
78176e69
MA
39This manual documents an API for usage of D-Bus in Emacs. D-Bus is a
40message bus system, a simple way for applications to talk to one
41another. An overview of D-Bus can be found at
42@uref{http://dbus.freedesktop.org/}.
22d8ac3a 43
5dc584b5 44@ifnottex
22d8ac3a 45@insertcopying
5dc584b5 46@end ifnottex
22d8ac3a
MA
47
48@menu
49* Overview:: An overview of D-Bus.
cd71b9ae 50* Inspection:: Inspection of D-Bus services.
22d8ac3a
MA
51* Type Conversion:: Mapping Lisp types and D-Bus types.
52* Synchronous Methods:: Calling methods in a blocking way.
21956b56 53* Asynchronous Methods:: Calling methods non-blocking.
addb7f2e 54* Receiving Method Calls:: Offering own methods.
22d8ac3a 55* Signals:: Sending and receiving signals.
7457f7b6 56* Alternative Buses:: Alternative buses.
22d8ac3a 57* Errors and Events:: Errors and events.
5bd55c3c
MA
58* Index:: Index including concepts, functions, variables.
59
22d8ac3a
MA
60* GNU Free Documentation License:: The license for this documentation.
61@end menu
62
cd71b9ae 63
22d8ac3a
MA
64@node Overview
65@chapter An overview of D-Bus
66@cindex overview
67
68D-Bus is an inter-process communication mechanism for applications
69residing on the same host. The communication is based on
70@dfn{messages}. Data in the messages is carried in a structured way,
71it is not just a byte stream.
72
73The communication is connection oriented to two kinds of message
74buses: a so called @dfn{system bus}, and a @dfn{session bus}. On a
75given machine, there is always one single system bus for miscellaneous
76system-wide communication, like changing of hardware configuration.
77On the other hand, the session bus is always related to a single
78user's session.
79
80Every client application, which is connected to a bus, registers under
81a @dfn{unique name} at the bus. This name is used for identifying the
82client application. Such a unique name starts always with a colon,
83and looks like @samp{:1.42}.
84
85Additionally, a client application can register itself to a so called
86@dfn{known name}, which is a series of identifiers separated by dots,
7ef92bc9 87as in @samp{org.gnu.Emacs}. If several applications register to the
22d8ac3a
MA
88same known name, these registrations are queued, and only the first
89application which has registered for the known name is reachable via
90this name. If this application disconnects from the bus, the next
91queued unique name becomes the owner of this known name.
92
93An application can install one or several objects under its name.
94Such objects are identified by an @dfn{object path}, which looks
95similar to paths in a filesystem. An example of such an object path
96could be @samp{/org/gnu/Emacs/}.
97
98Applications might send a request to an object, that means sending a
99message with some data as input parameters, and receiving a message
100from that object with the result of this message, the output
101parameters. Such a request is called @dfn{method} in D-Bus.
102
103The other form of communication are @dfn{signals}. The underlying
104message is emitted from an object and will be received by all other
105applications which have registered for such a signal.
106
107All methods and signals an object supports are called @dfn{interface}
108of the object. Interfaces are specified under a hierarchical name in
109D-Bus; an object can support several interfaces. Such an interface
110name could be @samp{org.gnu.Emacs.TextEditor} or
111@samp{org.gnu.Emacs.FileManager}.
112
113
114@node Inspection
cd71b9ae 115@chapter Inspection of D-Bus services.
22d8ac3a
MA
116@cindex inspection
117
cd71b9ae
MA
118@menu
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.
125@end menu
126
127
128@node Bus names
129@section Bus names.
130
22d8ac3a
MA
131There are several basic functions which inspect the buses for
132registered names. Internally they use the basic interface
133@samp{org.freedesktop.DBus}, which is supported by all objects of a bus.
134
135@defun dbus-list-activatable-names
22d8ac3a
MA
136This function returns the D-Bus service names, which can be activated.
137An activatable service is described in a service registration file.
138Under GNU/Linux, such files are located at
139@file{/usr/share/dbus-1/services/}.
140
141The result is a list of strings, which is @code{nil} when there are no
142activatable service names at all.
143@end defun
144
145@defun dbus-list-names bus
22d8ac3a
MA
146All service names, which are registered at D-Bus @var{bus}, are
147returned. The result is a list of strings, which is @code{nil} when
148there are no registered service names at all. Well known names are
149strings like @samp{org.freedesktop.DBus}. Names starting with
150@samp{:} are unique names for services.
151
152@var{bus} must be either the symbol @code{:system} or the symbol
153@code{:session}.
154@end defun
155
156@defun dbus-list-known-names bus
22d8ac3a
MA
157Retrieves all services which correspond to a known name in @var{bus}.
158A service has a known name if it doesn't start with @samp{:}. The
159result is a list of strings, which is @code{nil} when there are no
160known names at all.
161
162@var{bus} must be either the symbol @code{:system} or the symbol
163@code{:session}.
164@end defun
165
166@defun dbus-list-queued-owners bus service
22d8ac3a
MA
167For 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
169list of strings, or @code{nil} when there are no queued names for
170@var{service} at all.
171
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
174string.
175@end defun
176
177@defun dbus-get-name-owner bus service
22d8ac3a 178For a given service, registered at D-Bus @var{bus} under the name
06c0751a
MA
179@var{service}, the unique name of the name owner is returned. The
180result is a string, or @code{nil} when there exist no name owner of
181@var{service}.
22d8ac3a
MA
182
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
185string.
186@end defun
187
ecd3d54f 188@defun dbus-ping bus service &optional timeout
06c0751a 189Check whether the service name @var{service} is registered at D-Bus
ecd3d54f
MA
190@var{bus}. @var{service} might not have been started yet, it is
191autostarted if possible. The result is either @code{t} or @code{nil}.
06c0751a
MA
192
193@var{bus} must be either the symbol @code{:system} or the symbol
ecd3d54f
MA
194@code{:session}. @var{service} must be a string. @var{timeout}, a
195nonnegative integer, specifies the maximum number of milliseconds
196@code{dbus-ping} must return. The default value is 25,000. Example:
06c0751a
MA
197
198@lisp
199(message
200 "%s screensaver on board."
201 (cond
ecd3d54f
MA
202 ((dbus-ping :session "org.gnome.ScreenSaver" 100) "Gnome")
203 ((dbus-ping :session "org.freedesktop.ScreenSaver" 100) "KDE")
06c0751a
MA
204 (t "No")))
205@end lisp
ecd3d54f
MA
206
207If it shall be checked whether @var{service} is already running
208without autostarting it, one shall apply
209
210@lisp
211(member service (dbus-list-known-names bus))
212@end lisp
06c0751a
MA
213@end defun
214
22d8ac3a 215@defun dbus-get-unique-name bus
22d8ac3a
MA
216The unique name, under which Emacs is registered at D-Bus @var{bus},
217is returned as string.
218
219@var{bus} must be either the symbol @code{:system} or the symbol
220@code{:session}.
221@end defun
222
cd71b9ae
MA
223
224@node Introspection
225@section Knowing the details of D-Bus services.
226
227D-Bus services publish their interfaces. This can be retrieved and
228analyzed during runtime, in order to understand the used
229implementation.
230
231The resulting introspection data are in XML format. The root
232introspection element is always a @code{node} element. It might have
233a @code{name} attribute, which denotes the (absolute) object path an
234interface is introspected.
235
236The root @code{node} element may have @code{node} and @code{interface}
237children. A child @code{node} element must have a @code{name}
238attribute, this case it is the relative object path to the root
239@code{node} element.
240
241An @code{interface} element has just one attribute, @code{name}, which
242is the full name of that interface. The default interface
243@samp{org.freedesktop.DBus.Introspectable} is always present. Example:
244
245@example
246<node name="/org/bluez">
247 <interface name="org.freedesktop.DBus.Introspectable">
248 @dots{}
249 </interface>
250 <interface name="org.bluez.Manager">
251 @dots{}
252 </interface>
253 <interface name="org.bluez.Database">
254 @dots{}
255 </interface>
256 <interface name="org.bluez.Security">
257 @dots{}
258 </interface>
259 <node name="service_audio"/>
260 <node name="service_input"/>
261 <node name="service_network"/>
262 <node name="service_serial"/>
263</node>
264@end example
265
266Children of an @code{interface} element can be @code{method},
267@code{signal} and @code{property} elements. A @code{method} element
268stands for a D-Bus method of the surrounding interface. The element
269itself has a @code{name} attribute, showing the method name. Children
270elements @code{arg} stand for the arguments of a method. Example:
271
272@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"/>
285</method>
286@end example
287
288@code{arg} elements can have the attributes @code{name}, @code{type}
289and @code{direction}. The @code{name} attribute is optional. The
290@code{type} attribute stands for the @dfn{signature} of the argument
291in D-Bus. For a discussion of D-Bus types and their Lisp
292representation see @ref{Type Conversion}.@footnote{D-Bus signatures
293are explained in the D-Bus specification
294@uref{http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-signatures}.}
295The @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
297@samp{in}.
298
299A @code{signal} element of an @code{interface} has a similar
300structure. The @code{direction} attribute of an @code{arg} child
301element can be only @samp{out} here; which is also the default value.
302Example:
303
304@example
305<signal name="StateChanged">
306 <arg name="state" type="i"/>
307 <arg name="error" type="s"/>
308</signal>
309@end example
310
311A @code{property} element has no @code{arg} child
312element. It just has the attributes @code{name}, @code{type} and
313@code{access}, which are all mandatory. The @code{access} attribute
314allows the values @samp{readwrite}, @samp{read}, and @samp{write}.
315Example:
316
317@example
318<property name="Status" type="u" direction="read"/>
319@end example
320
321@code{annotation} elements can be children of @code{interface},
322@code{method}, @code{signal}, and @code{property} elements. Unlike
323properties, which can change their values during lifetime of a D-Bus
324object, annotations are static. Often they are used for code
325generators of D-Bus langugae bindings. Example:
326
327@example
328<annotation name="de.berlios.Pinot.GetStatistics" value="pinotDBus"/>
329@end example
330
331Annotations have just @code{name} and @code{value} attributes, both
332must be strings.
333
22d8ac3a 334@defun dbus-introspect bus service path
cd71b9ae
MA
335This function returns all interfaces and sub-nodes of @var{service},
336registered at object path @var{path} at bus @var{bus}.
22d8ac3a
MA
337
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
341strings. The result, the introspection data, is a string in XML
cd71b9ae 342format. Example:
22d8ac3a 343
06c0751a 344@lisp
22d8ac3a
MA
345(dbus-introspect
346 :system "org.freedesktop.Hal"
347 "/org/freedesktop/Hal/devices/computer")
348
d9e21158 349@result{} "<!DOCTYPE node PUBLIC
cd71b9ae
MA
350 "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
351 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
d9e21158 352 <node>
cd71b9ae
MA
353 <interface name="org.freedesktop.Hal.Device">
354 <method name="GetAllProperties">
355 <arg name="properties" direction="out" type="a@{sv@}"/>
d9e21158 356 </method>
c9ecb5a7 357 @dots{}
cd71b9ae
MA
358 <signal name="PropertyModified">
359 <arg name="num_updates" type="i"/>
360 <arg name="updates" type="a(sbb)"/>
d9e21158
MA
361 </signal>
362 </interface>
c9ecb5a7 363 @dots{}
d9e21158 364 </node>"
06c0751a 365@end lisp
22d8ac3a 366
cd71b9ae
MA
367This example informs us, that the service @samp{org.freedesktop.Hal}
368at object path @samp{/org/freedesktop/Hal/devices/computer} offers the
369interface @samp{org.freedesktop.Hal.Device} (and 2 other interfaces
22d8ac3a 370not documented here). This interface contains the method
cd71b9ae 371@samp{GetAllProperties}, which needs no input parameters, but returns
22d8ac3a
MA
372as output parameter an array of dictionary entries (key-value pairs).
373Every dictionary entry has a string as key, and a variant as value.
374
375The interface offers also a signal, which returns 2 parameters: an
376integer, and an array consisting of elements which are a struct of a
cd71b9ae
MA
377string and 2 boolean values.@footnote{ The interfaces of the service
378@samp{org.freedesktop.Hal} are described at
22d8ac3a
MA
379@uref{http://people.freedesktop.org/~david/hal-spec/hal-spec.html#interfaces}.}
380@end defun
381
cd71b9ae
MA
382@defun dbus-introspect-xml bus service path
383This function has the same intention as function
384@code{dbus-introspect}. The returned value is a parsed XML tree,
385which can be used for further analysis. Example:
386
387@lisp
388(dbus-introspect-xml
389 :session "org.freedesktop.xesam.searcher"
390 "/org/freedesktop/xesam/searcher/main")
391
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")))
399 )
400 @dots{}
401 (signal ((name . "HitsAdded"))
402 (arg ((name . "search") (type . "s")))
403 (arg ((name . "count") (type . "u")))
404 )
405 )
406 @dots{}
407 )
408@end lisp
409@end defun
410
411@defun dbus-introspect-get-attribute object attribute
412It returns the @var{attribute} value of a D-Bus introspection
413@var{object}. @var{object} can be every subtree of a parsed XML tree
414as retrieved with @code{dbus-introspect-xml}. @var{attribute} must be
415a string according to the attribute names in the D-Bus specification.
416Example:
417
418@lisp
419(dbus-introspect-get-attribute
420 (dbus-introspect-xml :system "org.freedesktop.SystemToolsBackends"
421 "/org/freedesktop/SystemToolsBackends/UsersConfig")
422 "name")
423
424@result{} "/org/freedesktop/SystemToolsBackends/UsersConfig"
425@end lisp
426
5bd55c3c
MA
427If @var{object} has no @var{attribute}, the function returns
428@code{nil}.
cd71b9ae
MA
429@end defun
430
431
432@node Nodes and Interfaces
433@section Detecting object paths and interfaces.
434
435The first elements, to be introspected for a D-Bus object, are further
436object paths and interfaces.
437
438@defun dbus-introspect-get-node-names bus service path
439All node names of @var{service} in D-Bus @var{bus} at object path
440@var{path} are returned as list of strings. Example:
441
442@lisp
443(dbus-introspect-get-node-names
444 :session "org.gnome.seahorse" "/org/gnome/seahorse")
445
446@result{} ("crypto" "keys")
447@end lisp
448
449The 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}
452are also object paths of the D-Bus service @samp{org.gnome.seahorse}.
453@end defun
454
455@defun dbus-introspect-get-all-nodes bus service path
456This 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
458with all object paths of @var{service}, starting at @var{path}.
459Example:
460
461@lisp
462(dbus-introspect-get-all-nodes :session "org.gnome.seahorse" "/")
463
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")
471@end lisp
472@end defun
473
474@defun dbus-introspect-get-interface-names bus service path
475There 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
477will contain the default interface @samp{org.freedesktop.DBus.Introspectable}.
478
479Another default interface is @samp{org.freedesktop.DBus.Properties}.
480If present, @code{interface} elements can also have @code{property}
481children. Example:
482
483@lisp
484(dbus-introspect-get-interface-names
485 :system "org.freedesktop.Hal"
486 "/org/freedesktop/Hal/devices/computer")
487
488@result{} ("org.freedesktop.DBus.Introspectable"
489 "org.freedesktop.Hal.Device"
490 "org.freedesktop.Hal.Device.SystemPowerManagement"
491 "org.freedesktop.Hal.Device.CPUFreq")
492@end lisp
493@end defun
494
495@defun dbus-introspect-get-interface bus service path interface
496Return @var{interface} of @var{service} in D-Bus @var{bus} at object
497path @var{path}. The return value is an XML element. @var{interface}
498must be a string, element of the list returned by
499@code{dbus-introspect-get-interface-names}. Example:
500
501@lisp
502(dbus-introspect-get-interface
503 :session "org.freedesktop.xesam.searcher"
504 "/org/freedesktop/xesam/searcher/main"
505 "org.freedesktop.xesam.Search")
506
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")))
513 )
514 @dots{}
515 (signal ((name . "HitsAdded"))
516 (arg ((name . "search") (type . "s")))
517 (arg ((name . "count") (type . "u")))
518 )
519 )
520@end lisp
521@end defun
522
523@noindent
524With these functions, it is possible to retrieve all introspection
525data from a running system:
526
527@lisp
528(with-current-buffer (switch-to-buffer "*introspect*")
529 (erase-buffer)
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".
534 (when (delete
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))
539 (redisplay t)))))
540@end lisp
541
542
543@node Methods and Signal
544@section Applying the functionality.
545
546Methods and signals are the communicatione means to D-Bus. The
547following functions return their specifications.
548
549@defun dbus-introspect-get-method-names bus service path interface
550Return 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:
552
553@lisp
554(dbus-introspect-get-method-names
555 :session "org.freedesktop.xesam.searcher"
556 "/org/freedesktop/xesam/searcher/main"
557 "org.freedesktop.xesam.Search")
558
559@result{} ("GetState" "StartSearch" "GetHitCount" "GetHits" "NewSession"
560 "CloseSession" "GetHitData" "SetProperty" "NewSearch"
561 "GetProperty" "CloseSearch")
562@end lisp
563@end defun
564
565@defun dbus-introspect-get-method bus service path interface method
566This function returns @var{method} of @var{interface} as XML element.
567It 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
569returned by @code{dbus-introspect-get-method-names}. Example:
570
571@lisp
572(dbus-introspect-get-method
573 :session "org.freedesktop.xesam.searcher"
574 "/org/freedesktop/xesam/searcher/main"
575 "org.freedesktop.xesam.Search" "GetHitData")
576
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")))
582 )
583@end lisp
584@end defun
585
586@defun dbus-introspect-get-signal-names bus service path interface
587Return 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:
589
590@lisp
591(dbus-introspect-get-signal-names
592 :session "org.freedesktop.xesam.searcher"
593 "/org/freedesktop/xesam/searcher/main"
594 "org.freedesktop.xesam.Search")
595
596@result{} ("StateChanged" "SearchDone" "HitsModified"
597 "HitsRemoved" "HitsAdded")
598@end lisp
599@end defun
600
601@defun dbus-introspect-get-signal bus service path interface signal
602This function returns @var{signal} of @var{interface} as XML element.
603It 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
605returned by @code{dbus-introspect-get-signal-names}. Example:
606
607@lisp
608(dbus-introspect-get-signal
609 :session "org.freedesktop.xesam.searcher"
610 "/org/freedesktop/xesam/searcher/main"
611 "org.freedesktop.xesam.Search" "HitsAdded")
612
613@result{} (signal ((name . "HitsAdded"))
614 (arg ((name . "search") (type . "s")))
615 (arg ((name . "count") (type . "u")))
616 )
617@end lisp
618@end defun
619
620
621@node Properties and Annotations
622@section What else to know about interfaces.
623
624Interfaces 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}}.
627That is, properties can be retrieved and changed during lifetime of an
628element.
629
630Annotations, on the other hand, are static values for an element.
631Often, they are used to instruct generators, how to generate code from
632the interface for a given language binding.
633
634@defun dbus-introspect-get-property-names bus service path interface
635Return 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:
637
638@lisp
639(dbus-introspect-get-property-names
640 :session "org.kde.kded" "/modules/networkstatus"
641 "org.kde.Solid.Networking.Client")
642
643@result{} ("Status")
644@end lisp
645
646If an interface declares properties, the corresponding element supports
647also the @samp{org.freedesktop.DBus.Properties} interface.
648@end defun
649
650@defun dbus-introspect-get-property bus service path interface property
651This function returns @var{property} of @var{interface} as XML element.
652It 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
654returned by @code{dbus-introspect-get-property-names}.
655
656A @var{property} value can be retrieved by the function
657@code{dbus-introspect-get-attribute}. Example:
658
659@lisp
660(dbus-introspect-get-property
661 :session "org.kde.kded" "/modules/networkstatus"
662 "org.kde.Solid.Networking.Client" "Status")
663
664@result{} (property ((access . "read") (type . "u") (name . "Status")))
665
666(dbus-introspect-get-attribute
667 (dbus-introspect-get-property
668 :session "org.kde.kded" "/modules/networkstatus"
669 "org.kde.Solid.Networking.Client" "Status")
670 "access")
671
672@result{} "read"
673@end lisp
674@end defun
675
676@defun dbus-get-property bus service path interface property
677This function returns the value of @var{property} of @var{interface}.
678It will be checked at @var{bus}, @var{service}, @var{path}. The
5bd55c3c 679result can be any valid D-Bus value, or @code{nil} if there is no
cd71b9ae
MA
680@var{property}. Example:
681
682@lisp
683(dbus-get-property
684 :session "org.kde.kded" "/modules/networkstatus"
685 "org.kde.Solid.Networking.Client" "Status")
686
687@result{} 4
688@end lisp
689@end defun
690
691@defun dbus-set-property bus service path interface property value
692Set value of @var{property} of @var{interface} to @var{value}. It
693will be checked at @var{bus}, @var{service}, @var{path}. When the
694value has been set successful, the result is @var{value}. Otherwise,
695@code{nil} is returned. Example:
696
697@lisp
698(dbus-set-property
699 :session "org.kde.kaccess" "/MainApplication"
700 "com.trolltech.Qt.QApplication" "doubleClickInterval" 500)
701
702@result{} 500
703@end lisp
704@end defun
705
706@defun dbus-get-all-properties bus service path interface
707This function returns all properties of @var{interface}. It will be
708checked at @var{bus}, @var{service}, @var{path}. The result is a list
709of cons. Every cons contains the name of the property, and its value.
710If there are no properties, @code{nil} is returned. Example:
711
712@lisp
713(dbus-get-all-properties
714 :session "org.kde.kaccess" "/MainApplication"
715 "com.trolltech.Qt.QApplication")
716
717@result{} (("cursorFlashTime" . 1000) ("doubleClickInterval" . 500)
718 ("keyboardInputInterval" . 400) ("wheelScrollLines" . 3)
719 ("globalStrut" 0 0) ("startDragTime" . 500)
720 ("startDragDistance" . 4) ("quitOnLastWindowClosed" . t)
721 ("styleSheet" . ""))
722@end lisp
723@end defun
724
725@defun dbus-introspect-get-annotation-names bus service path interface &optional name
726Return 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
730belong to. Example:
731
732@lisp
733(dbus-introspect-get-annotation-names
734 :session "de.berlios.Pinot" "/de/berlios/Pinot"
735 "de.berlios.Pinot" "GetStatistics")
736
737@result{} ("de.berlios.Pinot.GetStatistics")
738@end lisp
739
740Default annotation names@footnote{See
741@uref{http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format}}
742are
743
744@table @samp
745@item org.freedesktop.DBus.Deprecated
746Whether or not the entity is deprecated; defaults to @code{nil}
747
748@item org.freedesktop.DBus.GLib.CSymbol
749The C symbol; may be used for @code{methods} and @code{interfaces}
750
751@item org.freedesktop.DBus.Method.NoReply
752If set, don't expect a reply to the @code{method} call; defaults to @code{nil}
753@end table
754@end defun
755
756@defun dbus-introspect-get-annotation bus service path interface name annotation
757Return 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.
761
762An attribute value can be retrieved by
763@code{dbus-introspect-get-attribute}. Example:
764
765@lisp
766(dbus-introspect-get-annotation
767 :session "de.berlios.Pinot" "/de/berlios/Pinot"
768 "de.berlios.Pinot" "GetStatistics"
769 "de.berlios.Pinot.GetStatistics")
770
771@result{} (annotation ((name . "de.berlios.Pinot.GetStatistics")
772 (value . "pinotDBus")))
773
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")
779 "value")
780
781@result{} "pinotDBus"
782@end lisp
783@end defun
784
785
786@node Arguments and Signatures
787@section The final details.
788
789Methods and signals have arguments. They are described in the
790@code{arg} XML elements.
791
792@defun dbus-introspect-get-argument-names bus service path interface name
793Return a list of all argument names as list of strings. @var{name}
794must be a @code{method} or @code{signal} XML element. Example:
795
796@lisp
797(dbus-introspect-get-argument-names
798 :session "org.freedesktop.xesam.searcher"
799 "/org/freedesktop/xesam/searcher/main"
800 "org.freedesktop.xesam.Search" "GetHitData")
801
802@result{} ("search" "hit_ids" "fields" "hit_data")
803@end lisp
804
805Argument names are optional; the function can return @code{nil}
806therefore, even if the method or signal has arguments.
807@end defun
808
809@defun dbus-introspect-get-argument bus service path interface name arg
810Return argument @var{ARG} as XML object. @var{name}
811must be a @code{method} or @code{signal} XML element. Example:
812
813@lisp
814(dbus-introspect-get-argument
815 :session "org.freedesktop.xesam.searcher"
816 "/org/freedesktop/xesam/searcher/main"
817 "org.freedesktop.xesam.Search" "GetHitData" "search")
818
819@result{} (arg ((name . "search") (type . "s") (direction . "in")))
820@end lisp
821@end defun
822
823@defun dbus-introspect-get-signature bus service path interface name &optional direction
824Return signature of a @code{method} or @code{signal}, represented by
825@var{name}, as string.
826
827If @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}
829is assumed.
830
831If @var{name} is a @code{signal}, and @var{direction} is
832non-@code{nil}, @var{direction} must be @samp{out}. Example:
833
834@lisp
835(dbus-introspect-get-signature
836 :session "org.freedesktop.xesam.searcher"
837 "/org/freedesktop/xesam/searcher/main"
838 "org.freedesktop.xesam.Search" "GetHitData" "in")
839
840@result{} "sauas"
841
842(dbus-introspect-get-signature
843 :session "org.freedesktop.xesam.searcher"
844 "/org/freedesktop/xesam/searcher/main"
845 "org.freedesktop.xesam.Search" "HitsAdded")
846
21956b56 847@result{} "su"
cd71b9ae
MA
848@end lisp
849@end defun
850
22d8ac3a
MA
851
852@node Type Conversion
853@chapter Mapping Lisp types and D-Bus types.
854@cindex type conversion
855
856D-Bus method calls and signals accept usually several arguments as
857parameters, either as input parameter, or as output parameter. Every
858argument belongs to a D-Bus type.
859
6a31c819 860Such arguments must be mapped between the value encoded as a D-Bus
22d8ac3a
MA
861type, and the corresponding type of Lisp objects. The mapping is
862applied Lisp object @expansion{} D-Bus type for input parameters, and
863D-Bus type @expansion{} Lisp object for output parameters.
864
865
866@section Input parameters.
867
868Input parameters for D-Bus methods and signals occur as arguments of a
6a31c819 869Lisp function call. The following mapping to D-Bus types is
22d8ac3a
MA
870applied, when the corresponding D-Bus message is created:
871
872@example
5bd55c3c 873@multitable {negative integer} {@expansion{}} {DBUS_TYPE_BOOLEAN}
22d8ac3a
MA
874@item Lisp type @tab @tab D-Bus type
875@item
876@item @code{t} and @code{nil} @tab @expansion{} @tab DBUS_TYPE_BOOLEAN
5bd55c3c
MA
877@item natural number @tab @expansion{} @tab DBUS_TYPE_UINT32
878@item negative integer @tab @expansion{} @tab DBUS_TYPE_INT32
22d8ac3a
MA
879@item float @tab @expansion{} @tab DBUS_TYPE_DOUBLE
880@item string @tab @expansion{} @tab DBUS_TYPE_STRING
6a31c819 881@item list @tab @expansion{} @tab DBUS_TYPE_ARRAY
22d8ac3a
MA
882@end multitable
883@end example
884
6a31c819
MA
885Other Lisp objects, like symbols or hash tables, are not accepted as
886input parameter.
887
888If it is necessary to use another D-Bus type, a corresponding type
889symbol can be preceeded to the corresponding Lisp object. Basic D-Bus
d4e67bc5
MA
890types 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},
6f8fc60c
MA
893@code{:string}, @code{:object-path}, @code{:signature} and
894@code{:unix-fd}.
6a31c819 895
22d8ac3a 896@noindent
6a31c819
MA
897Example:
898
899@lisp
5bd55c3c 900(dbus-call-method @dots{} @var{NAT-NUMBER} @var{STRING})
6a31c819
MA
901@end lisp
902
903is equivalent to
904
905@lisp
5bd55c3c 906(dbus-call-method @dots{} :uint32 @var{NAT-NUMBER} :string @var{STRING})
6a31c819
MA
907@end lisp
908
909but different to
910
911@lisp
5bd55c3c 912(dbus-call-method @dots{} :int32 @var{NAT-NUMBER} :signature @var{STRING})
6a31c819
MA
913@end lisp
914
4db2806c
MA
915The value for a byte D-Bus type can be any integer in the range 0
916through 255. If a character is used as argument, modifiers
917represented outside this range are stripped of. For example,
918@code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to
919@code{:byte ?\C-x} or @code{:byte ?\M-\C-x}.
c9ecb5a7 920
4db2806c
MA
921A D-Bus compound type is always represented as a list. The @sc{car}
922of this list can be the type symbol @code{:array}, @code{:variant},
d4e67bc5
MA
923@code{:struct} or @code{:dict-entry}, which would result in a
924corresponding D-Bus container. @code{:array} is optional, because
4db2806c 925this is the default compound D-Bus type for a list.
6a31c819
MA
926
927The objects being elements of the list are checked according to the
928D-Bus compound type rules.
929
930@itemize
4db2806c
MA
931@item An array must contain only elements of the same D-Bus type. It
932can be empty.
933
6a31c819 934@item A variant must contain only one single element.
4db2806c 935
6a31c819 936@item A dictionary entry must be element of an array, and it must
4db2806c
MA
937contain only a key-value pair of two elements, with a basic D-Bus type
938key.
939
6a31c819
MA
940@item There is no restriction for structs.
941@end itemize
942
4db2806c
MA
943If an empty array needs an element D-Bus type other than string, it
944can contain exactly one element of D-Bus type @code{:signature}. The
945value of this element (a string) is used as the signature of the
946elements of this array. Example:
6a31c819
MA
947
948@lisp
4db2806c
MA
949(dbus-call-method
950 :session "org.freedesktop.Notifications"
951 "/org/freedesktop/Notifications"
952 "org.freedesktop.Notifications" "Notify"
953 "GNU Emacs" ;; Application name.
954 0 ;; No replacement of other notifications.
955 "" ;; No icon.
956 "Notification summary" ;; Summary.
957 (format ;; Body.
958 "This is a test notification, raised from %s" (emacs-version))
959 '(:array) ;; No actions (empty array of strings).
960 '(:array :signature "@{sv@}") ;; No hints
961 ;; (empty array of dictionary entries).
0ecd3c90 962 :int32 -1) ;; Default timeout.
4db2806c
MA
963
964@result{} 3
6a31c819 965@end lisp
22d8ac3a 966
ace706d1
MA
967@defun dbus-string-to-byte-array string
968Sometimes, D-Bus methods require as input parameter an array of bytes,
969instead of a string. If it is guaranteed, that @var{string} is an
970UTF8 string, this function performs the conversion. Example:
971
972@lisp
973(dbus-string-to-byte-array "/etc/hosts")
974
975@result{} (:array :byte 47 :byte 101 :byte 116 :byte 99 :byte 47
976 :byte 104 :byte 111 :byte 115 :byte 116 :byte 115)
977@end lisp
978@end defun
979
980@defun dbus-escape-as-identifier string
981Escape an arbitrary @var{string} so it follows the rules for a C
982identifier. The escaped string can be used as object path component,
983interface element component, bus name component or member name in
984D-Bus.
985
986The escaping consists of replacing all non-alphanumerics, and the
987first character if it's a digit, with an underscore and two
988lower-case hex digits. As a special case, "" is escaped to
989"_". Example:
990
991@lisp
992(dbus-escape-as-identifier "0123abc_xyz\x01\xff")
993
994@result{} "_30123abc_5fxyz_01_ff"
995@end lisp
996@end defun
997
22d8ac3a
MA
998
999@section Output parameters.
1000
1001Output parameters of D-Bus methods and signals are mapped to Lisp
6a31c819 1002objects.
22d8ac3a
MA
1003
1004@example
5bd55c3c 1005@multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {natural number or float}
22d8ac3a
MA
1006@item D-Bus type @tab @tab Lisp type
1007@item
1008@item DBUS_TYPE_BOOLEAN @tab @expansion{} @tab @code{t} or @code{nil}
5bd55c3c
MA
1009@item DBUS_TYPE_BYTE @tab @expansion{} @tab natural number
1010@item DBUS_TYPE_UINT16 @tab @expansion{} @tab natural number
1011@item DBUS_TYPE_INT16 @tab @expansion{} @tab integer
1012@item DBUS_TYPE_UINT32 @tab @expansion{} @tab natural number or float
6f8fc60c 1013@item DBUS_TYPE_UNIX_FD @tab @expansion{} @tab natural number or float
5bd55c3c
MA
1014@item DBUS_TYPE_INT32 @tab @expansion{} @tab integer or float
1015@item DBUS_TYPE_UINT64 @tab @expansion{} @tab natural number or float
1016@item DBUS_TYPE_INT64 @tab @expansion{} @tab integer or float
22d8ac3a
MA
1017@item DBUS_TYPE_DOUBLE @tab @expansion{} @tab float
1018@item DBUS_TYPE_STRING @tab @expansion{} @tab string
1019@item DBUS_TYPE_OBJECT_PATH @tab @expansion{} @tab string
6a31c819 1020@item DBUS_TYPE_SIGNATURE @tab @expansion{} @tab string
22d8ac3a
MA
1021@item DBUS_TYPE_ARRAY @tab @expansion{} @tab list
1022@item DBUS_TYPE_VARIANT @tab @expansion{} @tab list
1023@item DBUS_TYPE_STRUCT @tab @expansion{} @tab list
1024@item DBUS_TYPE_DICT_ENTRY @tab @expansion{} @tab list
1025@end multitable
1026@end example
1027
d4e67bc5 1028A float object in case of @code{DBUS_TYPE_UINT32},
6f8fc60c
MA
1029@code{DBUS_TYPE_INT32}, @code{DBUS_TYPE_UINT64},
1030@code{DBUS_TYPE_INT64} and @code{DBUS_TYPE_UNIX_FD} is returned, when
1031the C value exceeds the Emacs number size range.
d4e67bc5 1032
22d8ac3a
MA
1033The resulting list of the last 4 D-Bus compound types contains as
1034elements the elements of the D-Bus container, mapped according to the
1035same rules.
1036
1037The signal @code{PropertyModified}, discussed as example in
1038@ref{Inspection}, would offer as Lisp data the following object
1039(@var{BOOL} stands here for either @code{nil} or @code{t}):
1040
1041@lisp
5bd55c3c 1042(@var{INTEGER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
22d8ac3a
MA
1043@end lisp
1044
ace706d1
MA
1045@defun dbus-byte-array-to-string byte-array
1046If a D-Bus method or signal returns an array of bytes, which are known
1047to represent an UTF8 string, this function converts @var{byte-array}
1048to the corresponding string. Example:
1049
1050@lisp
1051(dbus-byte-array-to-string '(47 101 116 99 47 104 111 115 116 115))
1052
1053@result{} "/etc/hosts"
1054@end lisp
1055@end defun
1056
1057@defun dbus-unescape-from-identifier string
1058Retrieve the original string from the encoded @var{string}.
1059@var{string} must have been coded with
1060@code{dbus-escape-as-identifier}. Example:
1061
1062@lisp
1063(dbus-unescape-from-identifier "_30123abc_5fxyz_01_ff")
1064
fa0f81b0
AS
1065@ifinfo
1066@result{} "0123abc_xyz^Aÿ"
1067@end ifinfo
1068@ifnotinfo
1069@result{} "0123abc_xyz^A@"y"
1070@end ifnotinfo
ace706d1
MA
1071@end lisp
1072@end defun
1073
22d8ac3a
MA
1074
1075@node Synchronous Methods
1076@chapter Calling methods in a blocking way.
1077@cindex method calls, synchronous
1078@cindex synchronous method calls
1079
1080Methods can be called synchronously (@dfn{blocking}) or asynchronously
21956b56 1081(@dfn{non-blocking}).
22d8ac3a
MA
1082
1083At D-Bus level, a method call consist of two messages: one message
1084which carries the input parameters to the object owning the method to
1085be called, and a reply message returning the resulting output
1086parameters from the object.
1087
134ce16c 1088@defun dbus-call-method bus service path interface method &optional :timeout timeout &rest args
22d8ac3a
MA
1089This function calls @var{method} on the D-Bus @var{bus}. @var{bus} is
1090either the symbol @code{:system} or the symbol @code{:session}.
1091
1092@var{service} is the D-Bus service name to be used. @var{path} is the
1093D-Bus object path, @var{service} is registered at. @var{interface} is
1094an interface offered by @var{service}. It must provide @var{method}.
1095
134ce16c 1096If the parameter @code{:timeout} is given, the following integer
21956b56 1097@var{timeout} specifies the maximum number of milliseconds the method
ecd3d54f 1098call must return. The default value is 25,000. If the method call
134ce16c
MA
1099doesn't return in time, a D-Bus error is raised (@pxref{Errors and
1100Events}).
1101
22d8ac3a
MA
1102All other arguments args are passed to @var{method} as arguments.
1103They are converted into D-Bus types as described in @ref{Type
1104Conversion}.
1105
1106The function returns the resulting values of @var{method} as a list of
1107Lisp objects, according to the type conversion rules described in
1108@ref{Type Conversion}. Example:
1109
06c0751a 1110@lisp
22d8ac3a 1111(dbus-call-method
0ce574ef
MA
1112 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
1113 "org.gnome.seahorse.Keys" "GetKeyField"
22d8ac3a
MA
1114 "openpgp:657984B8C7A966DD" "simple-name")
1115
1116@result{} (t ("Philip R. Zimmermann"))
06c0751a 1117@end lisp
22d8ac3a
MA
1118
1119If the result of the method call is just one value, the converted Lisp
1120object is returned instead of a list containing this single Lisp
1121object. Example:
1122
06c0751a 1123@lisp
22d8ac3a 1124(dbus-call-method
0ce574ef
MA
1125 :system "org.freedesktop.Hal"
1126 "/org/freedesktop/Hal/devices/computer"
1127 "org.freedesktop.Hal.Device" "GetPropertyString"
22d8ac3a
MA
1128 "system.kernel.machine")
1129
1130@result{} "i686"
06c0751a 1131@end lisp
22d8ac3a
MA
1132
1133With the @code{dbus-introspect} function it is possible to explore the
1134interfaces of @samp{org.freedesktop.Hal} service. It offers the
1135interfaces @samp{org.freedesktop.Hal.Manager} for the object at the
1136path @samp{/org/freedesktop/Hal/Manager} as well as the interface
1137@samp{org.freedesktop.Hal.Device} for all objects prefixed with the
1138path @samp{/org/freedesktop/Hal/devices}. With the methods
1139@samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to
1140emulate the @code{lshal} command on GNU/Linux systems:
1141
06c0751a 1142@lisp
22d8ac3a
MA
1143(dolist (device
1144 (dbus-call-method
0ce574ef 1145 :system "org.freedesktop.Hal"
22d8ac3a 1146 "/org/freedesktop/Hal/Manager"
0ce574ef 1147 "org.freedesktop.Hal.Manager" "GetAllDevices"))
22d8ac3a
MA
1148 (message "\nudi = %s" device)
1149 (dolist (properties
1150 (dbus-call-method
0ce574ef
MA
1151 :system "org.freedesktop.Hal" device
1152 "org.freedesktop.Hal.Device" "GetAllProperties"))
22d8ac3a
MA
1153 (message " %s = %S"
1154 (car properties) (or (caar (cdr properties)) ""))))
1155
7b13a0f2 1156@print{} "udi = /org/freedesktop/Hal/devices/computer
d9e21158
MA
1157 info.addons = (\"hald-addon-acpi\")
1158 info.bus = \"unknown\"
1159 info.product = \"Computer\"
1160 info.subsystem = \"unknown\"
1161 info.udi = \"/org/freedesktop/Hal/devices/computer\"
1162 linux.sysfs_path_device = \"(none)\"
1163 power_management.acpi.linux.version = \"20051216\"
1164 power_management.can_suspend_to_disk = t
1165 power_management.can_suspend_to_ram = \"\"
1166 power_management.type = \"acpi\"
1167 smbios.bios.release_date = \"11/07/2001\"
1168 system.chassis.manufacturer = \"COMPAL\"
1169 system.chassis.type = \"Notebook\"
1170 system.firmware.release_date = \"03/19/2005\"
c9ecb5a7 1171 @dots{}"
06c0751a 1172@end lisp
22d8ac3a
MA
1173@end defun
1174
21956b56
MA
1175@defun dbus-call-method-non-blocking bus service path interface method &optional :timeout timeout &rest args
1176Call @var{method} on the D-Bus @var{bus}, but don't block the event queue.
1177This is necessary for communicating to registered D-Bus methods,
1178which are running in the same Emacs process.
1179
1180The arguments are the same as in @code{dbus-call-method}. Example:
1181
1182@lisp
1183(dbus-call-method-non-blocking
1184 :system "org.freedesktop.Hal"
1185 "/org/freedesktop/Hal/devices/computer"
1186 "org.freedesktop.Hal.Device" "GetPropertyString"
1187 "system.kernel.machine")
1188
1189@result{} "i686"
1190@end lisp
1191@end defun
1192
1193
1194@node Asynchronous Methods
1195@chapter Calling methods non-blocking.
1196@cindex method calls, asynchronous
1197@cindex asynchronous method calls
1198
1199@defun dbus-call-method-asynchronously bus service path interface method handler &optional :timeout timeout &rest args
1200This function calls @var{method} on the D-Bus @var{bus}
1201asynchronously. @var{bus} is either the symbol @code{:system} or the
1202symbol @code{:session}.
1203
1204@var{service} is the D-Bus service name to be used. @var{path} is the
1205D-Bus object path, @var{service} is registered at. @var{interface} is
1206an interface offered by @var{service}. It must provide @var{method}.
1207
1208@var{handler} is a Lisp function, which is called when the
4f22e84d
MA
1209corresponding return message has arrived. If @var{handler} is
1210@code{nil}, no return message will be expected.
21956b56
MA
1211
1212If the parameter @code{:timeout} is given, the following integer
1213@var{timeout} specifies the maximum number of milliseconds a reply
ecd3d54f 1214message must arrive. The default value is 25,000. If there is no
21956b56
MA
1215reply message in time, a D-Bus error is raised (@pxref{Errors and
1216Events}).
1217
1218All other arguments args are passed to @var{method} as arguments.
1219They are converted into D-Bus types as described in @ref{Type
1220Conversion}.
1221
4f22e84d 1222Unless @var{handler} is @code{nil}, the function returns a key into
0ecd3c90 1223the hash table @code{dbus-registered-objects-table}. The
4f22e84d
MA
1224corresponding entry in the hash table is removed, when the return
1225message has been arrived, and @var{handler} is called. Example:
21956b56
MA
1226
1227@lisp
1228(dbus-call-method-asynchronously
1229 :system "org.freedesktop.Hal"
1230 "/org/freedesktop/Hal/devices/computer"
1231 "org.freedesktop.Hal.Device" "GetPropertyString" 'message
1232 "system.kernel.machine")
1233
1234@result{} (:system 2)
1235
1236@print{} i686
1237@end lisp
1238@end defun
1239
22d8ac3a 1240
addb7f2e
MA
1241@node Receiving Method Calls
1242@chapter Offering own methods.
1243@cindex method calls, returning
1244@cindex returning method calls
1245
8c904d82
MA
1246In order to register methods on the D-Bus, Emacs has to request a well
1247known name on the D-Bus under which it will be available for other
1248clients. Names on the D-Bus can be registered and unregistered using
1249the following functions:
1250
1251@defun dbus-register-service bus service &rest flags
1252Register the known name @var{service} on D-Bus @var{bus}.
1253
1254@var{bus} is either the symbol @code{:system} or the symbol
1255@code{:session}.
1256
1257@var{service} is the service name to be registered on the D-Bus. It
1258must be a known name.
1259
1260@var{flags} is a subset of the following keywords:
1261
1262@itemize
1263@item @code{:allow-replacement}: Allow another service to become the primary
1264owner if requested.
1265
1266@item @code{:replace-existing}: Request to replace the current primary owner.
1267
1268@item @code{:do-not-queue}: If we can not become the primary owner do not
1269place us in the queue.
1270@end itemize
1271
1272One of the following keywords is returned:
1273
1274@itemize
1275
1276@item @code{:primary-owner}: We have become the primary owner of the name
1277@var{service}.
1278
1279@item @code{:in-queue}: We could not become the primary owner and
1280have been placed in the queue.
1281
1282@item @code{:exists}: We already are in the queue.
1283
1284@item @code{:already-owner}: We already are the primary
1285owner.
1286@end itemize
1287@end defun
1288
1289@defun dbus-unregister-service bus service
1290Unregister all objects from D-Bus @var{bus}, registered by Emacs for
1291@var{service}.
1292
1293@var{bus} is either the symbol @code{:system} or the symbol
1294@code{:session}.
1295
1296@var{service} is the D-Bus service name of the D-Bus. It must be a
1297known name. Emacs releases its association to @var{service} from
1298D-Bus.
1299
1300One of the following keywords is returned:
1301
1302@itemize
1303@item @code{:released}: We successfully released the name @var{service}.
1304@item @code{:non-existent}: The name @var{service} does not exist on the bus.
1305@item @code{:not-owner}: We are not an owner of the name @var{service}.
1306@end itemize
1307@end defun
1308
1309When a name has been chosen, Emacs can offer own methods, which can be
1310called by other applications. These methods could be an
1311implementation of an interface of a well known service, like
1312@samp{org.freedesktop.TextEditor}.
addb7f2e
MA
1313
1314It could be also an implementation of an own interface. In this case,
cd71b9ae
MA
1315the service name must be @samp{org.gnu.Emacs}. The object path shall
1316begin with @samp{/org/gnu/Emacs/@strong{Application}/}, and the
addb7f2e 1317interface name shall be @code{org.gnu.Emacs.@strong{Application}}.
cd71b9ae 1318@samp{@strong{Application}} is the name of the application which
addb7f2e
MA
1319provides the interface.
1320
ace706d1
MA
1321@deffn Constant dbus-service-emacs
1322The well known service name of Emacs.
1323@end deffn
1324
1325@deffn Constant dbus-path-emacs
1326The object path head "/org/gnu/Emacs" used by Emacs. All object
1327paths, used by offered methods or signals, shall start with this
1328string.
1329@end deffn
1330
0fadf00e 1331@defun dbus-register-method bus service path interface method handler dont-register-service
addb7f2e
MA
1332With this function, an application registers @var{method} on the D-Bus
1333@var{bus}.
1334
1335@var{bus} is either the symbol @code{:system} or the symbol
1336@code{:session}.
1337
1338@var{service} is the D-Bus service name of the D-Bus object
0fadf00e
MA
1339@var{method} is registered for. It must be a known name (See
1340discussion of @var{dont-register-service} below).
addb7f2e 1341
0fadf00e
MA
1342@var{path} is the D-Bus object path @var{service} is registered (See
1343discussion of @var{dont-register-service} below).
addb7f2e
MA
1344
1345@var{interface} is the interface offered by @var{service}. It must
1346provide @var{method}.
1347
ac134f2f
RS
1348@var{handler} is a Lisp function to be called when a @var{method} call
1349is received. It must accept as arguments the input arguments of
1350@var{method}. @var{handler} should return a list, whose elements are
1351to be used as arguments for the reply message of @var{method}. This
1352list can be composed like the input parameters in @ref{Type
1353Conversion}.
1354
1355If @var{handler} wants to return just one Lisp object and it is not a
1356cons cell, @var{handler} can return this object directly, instead of
1357returning a list containing the object.
addb7f2e 1358
42fb7e61
MA
1359In case @var{handler} shall return a reply message with an empty
1360argument list, @var{handler} must return the symbol @code{:ignore}.
1361
0fadf00e
MA
1362When @var{dont-register-service} is non-@code{nil}, the known name
1363@var{service} is not registered. This means that other D-Bus clients
1364have no way of noticing the newly registered method. When interfaces
1365are constructed incrementally by adding single methods or properties
8c904d82 1366at a time, @var{dont-register-service} can be used to prevent other
0fadf00e
MA
1367clients from discovering the still incomplete interface.
1368
4a7c4c40 1369The default D-Bus timeout when waiting for a message reply is 25
134ce16c
MA
1370seconds. This value could be even smaller, depending on the calling
1371client. Therefore, @var{handler} shall not last longer than
4a7c4c40
MA
1372absolutely necessary.
1373
9b7993b4 1374@code{dbus-register-method} returns a Lisp object, which can be used
addb7f2e
MA
1375as argument in @code{dbus-unregister-object} for removing the
1376registration for @var{method}. Example:
1377
06c0751a 1378@lisp
addb7f2e
MA
1379(defun my-dbus-method-handler (filename)
1380 (let (result)
1381 (if (find-file filename)
1382 (setq result '(:boolean t))
1383 (setq result '(:boolean nil)))
1384 result))
1385
1386@result{} my-dbus-method-handler
1387
1388(dbus-register-method
1389 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1390 "org.freedesktop.TextEditor" "OpenFile"
1391 'my-dbus-method-handler)
1392
eb932e8a 1393@result{} ((:session "org.freedesktop.TextEditor" "OpenFile")
addb7f2e 1394 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
eb932e8a 1395 my-dbus-method-handler))
06c0751a 1396@end lisp
addb7f2e 1397
cd71b9ae 1398If you invoke the method @samp{org.freedesktop.TextEditor.OpenFile}
addb7f2e
MA
1399from another D-Bus application with a filename as parameter, the file
1400is opened in Emacs, and the method returns either @var{true} or
0ecd3c90 1401@var{false}, indicating the success of the method. As test tool one
addb7f2e
MA
1402could use the command line tool @code{dbus-send} in a shell:
1403
1404@example
1405# dbus-send --session --print-reply \
1406 --dest="org.freedesktop.TextEditor" \
1407 "/org/freedesktop/TextEditor" \
1408 "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts"
1409
1410@print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2
eb932e8a
MA
1411 boolean true
1412@end example
1413
1414You can indicate an error by raising the Emacs signal
1415@code{dbus-error}. The handler above could be changed like this:
1416
1417@lisp
1418(defun my-dbus-method-handler (&rest args)
1419 (unless (and (= (length args) 1) (stringp (car args)))
1420 (signal 'dbus-error (list (format "Wrong argument list: %S" args))))
1421 (condition-case err
1422 (find-file (car args))
1423 (error (signal 'dbus-error (cdr err))))
1424 t)
1425
1426@result{} my-dbus-method-handler
1427@end lisp
1428
1429The test runs then
1430
1431@example
1432# dbus-send --session --print-reply \
1433 --dest="org.freedesktop.TextEditor" \
1434 "/org/freedesktop/TextEditor" \
1435 "org.freedesktop.TextEditor.OpenFile" \
1436 string:"/etc/hosts" string:"/etc/passwd"
1437
1438@print{} Error org.freedesktop.DBus.Error.Failed:
1439 Wrong argument list: ("/etc/hosts" "/etc/passwd")
addb7f2e
MA
1440@end example
1441@end defun
1442
0fadf00e 1443@defun dbus-register-property bus service path interface property access value &optional emits-signal dont-register-service
0ecd3c90
MA
1444With this function, an application declares a @var{property} on the D-Bus
1445@var{bus}.
1446
1447@var{bus} is either the symbol @code{:system} or the symbol
1448@code{:session}.
1449
1450@var{service} is the D-Bus service name of the D-Bus. It must be a
1451known name.
1452
0fadf00e
MA
1453@var{path} is the D-Bus object path @var{service} is registered (See
1454discussion of @var{dont-register-service} below).
0ecd3c90
MA
1455
1456@var{interface} is the name of the interface used at @var{path},
1457@var{property} is the name of the property of @var{interface}.
1458
1459@var{access} indicates, whether the property can be changed by other
1460services via D-Bus. It must be either the symbol @code{:read} or
1461@code{:readwrite}. @var{value} is the initial value of the property,
1462it can be of any valid type (see @code{dbus-call-method} for details).
1463
1464If @var{property} already exists on @var{path}, it will be
1465overwritten. For properties with access type @code{:read} this is the
1466only way to change their values. Properties with access type
1467@code{:readwrite} can be changed by @code{dbus-set-property}.
1468
1469The interface @samp{org.freedesktop.DBus.Properties} is added to
1470@var{path}, including a default handler for the @samp{Get},
820ae8fe 1471@samp{GetAll} and @samp{Set} methods of this interface. When
5bd55c3c
MA
1472@var{emits-signal} is non-@code{nil}, the signal
1473@samp{PropertiesChanged} is sent when the property is changed by
1474@code{dbus-set-property}.
820ae8fe 1475
0fadf00e
MA
1476When @var{dont-register-service} is non-@code{nil}, the known name
1477@var{service} is not registered. This means that other D-Bus clients
1478have no way of noticing the newly registered method. When interfaces
1479are constructed incrementally by adding single methods or properties
8c904d82 1480at a time, @var{dont-register-service} can be used to prevent other
0fadf00e
MA
1481clients from discovering the still incomplete interface.
1482
820ae8fe 1483@noindent Example:
0ecd3c90
MA
1484
1485@lisp
1486(dbus-register-property
1487 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1488 "org.freedesktop.TextEditor" "name" :read "GNU Emacs")
1489
1490@result{} ((:session "org.freedesktop.TextEditor" "name")
1491 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"))
1492
1493(dbus-register-property
1494 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
820ae8fe 1495 "org.freedesktop.TextEditor" "version" :readwrite emacs-version t)
0ecd3c90
MA
1496
1497@result{} ((:session "org.freedesktop.TextEditor" "version")
1498 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"))
1499@end lisp
1500
1501Other D-Bus applications can read the property via the default methods
1502@samp{org.freedesktop.DBus.Properties.Get} and
1503@samp{org.freedesktop.DBus.Properties.GetAll}. Testing is also
1504possible via the command line tool @code{dbus-send} in a shell:
1505
1506@example
1507# dbus-send --session --print-reply \
1508 --dest="org.freedesktop.TextEditor" \
1509 "/org/freedesktop/TextEditor" \
1510 "org.freedesktop.DBus.Properties.GetAll" \
1511 string:"org.freedesktop.TextEditor"
1512
1513@print{} method return sender=:1.22 -> dest=:1.23 reply_serial=3
1514 array [
1515 dict entry(
1516 string "name"
1517 variant string "GNU Emacs"
1518 )
1519 dict entry(
1520 string "version"
1521 variant string "23.1.50.5"
1522 )
1523 ]
1524@end example
1525
1526It is also possible, to apply the @code{dbus-get-property},
1527@code{dbus-get-all-properties} and @code{dbus-set-property} functions
1528(@pxref{Properties and Annotations}).
1529
1530@lisp
1531(dbus-set-property
1532 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1533 "org.freedesktop.TextEditor" "version" "23.1.50")
1534
1535@result{} "23.1.50"
1536
1537(dbus-get-property
1538 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
1539 "org.freedesktop.TextEditor" "version")
1540
1541@result{} "23.1.50"
1542@end lisp
1543@end defun
1544
1545@defun dbus-unregister-object object
1546Unregister @var{object} from the D-Bus. @var{object} must be the
1547result of a preceding @code{dbus-register-method},
1548@code{dbus-register-property} or @code{dbus-register-signal} call
1549(@pxref{Signals}). It returns @code{t} if @var{object} has been
1550unregistered, @code{nil} otherwise.
1551
1552When @var{object} identifies the last method or property, which is
1553registered for the respective service, Emacs releases its association
1554to the service from D-Bus.
1555@end defun
977640ed 1556
addb7f2e 1557
22d8ac3a
MA
1558@node Signals
1559@chapter Sending and receiving signals.
1560@cindex signals
1561
1562Signals are broadcast messages. They carry input parameters, which
1563are received by all objects which have registered for such a signal.
1564
0ce574ef 1565@defun dbus-send-signal bus service path interface signal &rest args
22d8ac3a
MA
1566This function is similar to @code{dbus-call-method}. The difference
1567is, that there are no returning output parameters.
1568
1569The function emits @var{signal} on the D-Bus @var{bus}. @var{bus} is
1570either the symbol @code{:system} or the symbol @code{:session}. It
1571doesn't matter whether another object has registered for @var{signal}.
1572
1573@var{service} is the D-Bus service name of the object the signal is
1574emitted from. @var{path} is the corresponding D-Bus object path,
1575@var{service} is registered at. @var{interface} is an interface
1576offered by @var{service}. It must provide @var{signal}.
1577
1578All other arguments args are passed to @var{signal} as arguments.
1579They are converted into D-Bus types as described in @ref{Type
1580Conversion}. Example:
1581
06c0751a 1582@lisp
22d8ac3a 1583(dbus-send-signal
ace706d1
MA
1584 :session dbus-service-emacs dbus-path-emacs
1585 (concat dbus-service-emacs ".FileManager") "FileModified"
1586 "/home/albinus/.emacs")
06c0751a 1587@end lisp
22d8ac3a
MA
1588@end defun
1589
9b7993b4 1590@defun dbus-register-signal bus service path interface signal handler &rest args
22d8ac3a
MA
1591With this function, an application registers for @var{signal} on the
1592D-Bus @var{bus}.
1593
1594@var{bus} is either the symbol @code{:system} or the symbol
1595@code{:session}.
1596
a4397af9
MA
1597@var{service} is the D-Bus service name used by the sending D-Bus
1598object. It can be either a known name or the unique name of the D-Bus
1599object sending the signal. In case of a unique name, signals won't be
1600received any longer once the object owning this unique name has
1601disappeared, and a new queued object has replaced it.
1602
1603When @var{service} is @code{nil}, related signals from all D-Bus
1604objects shall be accepted.
1605
1606@var{path} is the corresponding D-Bus object path, @var{service} is
1607registered at. It can also be @code{nil} if the path name of incoming
1608signals shall not be checked.
1609
1610@var{interface} is an interface offered by @var{service}. It must
1611provide @var{signal}.
22d8ac3a
MA
1612
1613@var{handler} is a Lisp function to be called when the @var{signal} is
1614received. It must accept as arguments the output parameters
9b7993b4
MA
1615@var{signal} is sending.
1616
1617All other arguments @var{args}, if specified, must be strings. They
1618stand for the respective arguments of @var{signal} in their order, and
1619are used for filtering as well. A @code{nil} argument might be used
1620to preserve the order.
1621
1622@code{dbus-register-signal} returns a Lisp object, which can be used
1623as argument in @code{dbus-unregister-object} for removing the
1624registration for @var{signal}. Example:
22d8ac3a 1625
06c0751a 1626@lisp
22d8ac3a
MA
1627(defun my-dbus-signal-handler (device)
1628 (message "Device %s added" device))
1629
0ce574ef
MA
1630@result{} my-dbus-signal-handler
1631
22d8ac3a 1632(dbus-register-signal
0ce574ef
MA
1633 :system "org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
1634 "org.freedesktop.Hal.Manager" "DeviceAdded"
22d8ac3a
MA
1635 'my-dbus-signal-handler)
1636
cd71c3ef
MA
1637@result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
1638 ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
1639 my-signal-handler))
06c0751a 1640@end lisp
22d8ac3a 1641
cd71b9ae
MA
1642As we know from the introspection data of interface
1643@samp{org.freedesktop.Hal.Manager}, the signal @samp{DeviceAdded}
22d8ac3a
MA
1644provides one single parameter, which is mapped into a Lisp string.
1645The callback function @code{my-dbus-signal-handler} must define one
1646single string argument therefore. Plugging an USB device to your
cd71b9ae 1647machine, when registered for signal @samp{DeviceAdded}, will show you
22d8ac3a 1648which objects the GNU/Linux @code{hal} daemon adds.
22d8ac3a
MA
1649@end defun
1650
22d8ac3a 1651
7457f7b6
MA
1652@node Alternative Buses
1653@chapter Alternative buses.
1654@cindex bus names
1655@cindex UNIX domain socket
1656
1657Until now, we have spoken about the system and the session buses,
1658which are the default buses to be connected to. However, it is
1659possible to connect to any bus, from which the address is known. This
1660is a UNIX domain socket. Everywhere, where a @var{bus} is mentioned
1661as argument of a function (the symbol @code{:system} or the symbol
1662@code{:session}), this address can be used instead. The connection to
1663this bus must be initialized first.
1664
1665@defun dbus-init-bus bus
1666Establish the connection to D-Bus @var{bus}.
1667
1668@var{bus} can be either the symbol @code{:system} or the symbol
1669@code{:session}, or it can be a string denoting the address of the
1670corresponding bus. For the system and session busses, this function
1671is called when loading @file{dbus.el}, there is no need to call it
1672again.
1673
1674Example: You open another session bus in a terminal window on your host:
1675
1676@example
1677# eval `dbus-launch --auto-syntax`
1678# echo $DBUS_SESSION_BUS_ADDRESS
1679
1680@print{} unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e
1681@end example
1682
1683In Emacs, you can access to this bus via its address:
1684
1685@lisp
1686(setq my-bus
1687 "unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e")
1688
1689@result{} "unix:abstract=/tmp/dbus-JoFtAVG92w,guid=2f320a1ebe50b7ef58e"
1690
1691(dbus-init-bus my-bus)
1692
1693@result{} nil
1694
1695(dbus-get-unique-name my-bus)
1696
1697@result{} ":1.0"
1698@end lisp
1699@end defun
1700
1701
22d8ac3a
MA
1702@node Errors and Events
1703@chapter Errors and events.
5bd55c3c 1704@cindex debugging
22d8ac3a
MA
1705@cindex errors
1706@cindex events
1707
5bd55c3c
MA
1708The internal actions can be traced by running in a debug mode.
1709
1710@defvar dbus-debug
1711If this variable is non-@code{nil}, D-Bus specific debug messages are raised.
1712@end defvar
1713
21956b56
MA
1714Input parameters of @code{dbus-call-method},
1715@code{dbus-call-method-non-blocking},
1716@code{dbus-call-method-asynchronously}, and
6a31c819
MA
1717@code{dbus-register-signal} are checked for correct D-Bus types. If
1718there is a type mismatch, the Lisp error @code{wrong-type-argument}
1719@code{D-Bus ARG} is raised.
1720
22d8ac3a 1721All errors raised by D-Bus are signaled with the error symbol
d2e4a6c9
MA
1722@code{dbus-error}. If possible, error messages from D-Bus are
1723appended to the @code{dbus-error}.
1724
1725@defspec dbus-ignore-errors forms@dots{}
1726This executes @var{forms} exactly like a @code{progn}, except that
1727@code{dbus-error} errors are ignored during the @var{forms}. These
5bd55c3c 1728errors can be made visible when @code{dbus-debug} is set to @code{t}.
d2e4a6c9 1729@end defspec
22d8ac3a 1730
5794c2a5
MA
1731Incoming D-Bus messages are handled as Emacs events, see @pxref{Misc
1732Events, , , elisp}. They are retrieved only, when Emacs runs in
1733interactive mode. The generated event has this form:
22d8ac3a 1734
06c0751a 1735@lisp
21956b56
MA
1736(dbus-event @var{bus} @var{type} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler}
1737 &rest @var{args})
06c0751a 1738@end lisp
22d8ac3a 1739
21956b56 1740@var{bus} identifies the D-Bus the message is coming from. It is
a4397af9 1741either the symbol @code{:system} or the symbol @code{:session}.
22d8ac3a 1742
21956b56
MA
1743@var{type} is the D-Bus message type which has caused the event. It
1744can be @code{dbus-message-type-invalid},
1745@code{dbus-message-type-method-call},
1746@code{dbus-message-type-method-return},
1747@code{dbus-message-type-error}, or @code{dbus-message-type-signal}.
1748@var{serial} is the serial number of the received D-Bus message.
addb7f2e 1749
22d8ac3a 1750@var{service} and @var{path} are the unique name and the object path
addb7f2e
MA
1751of the D-Bus object emitting the message. @var{interface} and
1752@var{member} denote the message which has been sent.
22d8ac3a 1753
0ce574ef 1754@var{handler} is the callback function which has been registered for
addb7f2e 1755this message (see @pxref{Signals}). When a @code{dbus-event} event
0ce574ef
MA
1756arrives, @var{handler} is called with @var{args} as arguments.
1757
22d8ac3a
MA
1758In order to inspect the @code{dbus-event} data, you could extend the
1759definition of the callback function in @ref{Signals}:
1760
06c0751a 1761@lisp
22d8ac3a
MA
1762(defun my-dbus-signal-handler (&rest args)
1763 (message "my-dbus-signal-handler: %S" last-input-event))
06c0751a 1764@end lisp
22d8ac3a
MA
1765
1766There exist convenience functions which could be called inside a
1767callback function in order to retrieve the information from the event.
1768
1769@defun dbus-event-bus-name event
22d8ac3a
MA
1770Returns the bus name @var{event} is coming from.
1771The result is either the symbol @code{:system} or the symbol @code{:session}.
1772@end defun
1773
21956b56
MA
1774@defun dbus-event-message-type event
1775Returns the message type of the corresponding D-Bus message. The
5bd55c3c 1776result is a natural number.
21956b56
MA
1777@end defun
1778
addb7f2e
MA
1779@defun dbus-event-serial-number event
1780Returns the serial number of the corresponding D-Bus message.
5bd55c3c 1781The result is a natural number.
addb7f2e
MA
1782@end defun
1783
22d8ac3a 1784@defun dbus-event-service-name event
22d8ac3a
MA
1785Returns the unique name of the D-Bus object @var{event} is coming from.
1786@end defun
1787
1788@defun dbus-event-path-name event
22d8ac3a
MA
1789Returns the object path of the D-Bus object @var{event} is coming from.
1790@end defun
1791
1792@defun dbus-event-interface-name event
74fc5047 1793Returns the interface name of the D-Bus object @var{event} is coming from.
22d8ac3a
MA
1794@end defun
1795
1796@defun dbus-event-member-name event
74fc5047 1797Returns the member name of the D-Bus object @var{event} is coming
22d8ac3a
MA
1798from. It is either a signal name or a method name.
1799@end defun
1800
c9ecb5a7
MA
1801D-Bus errors are not propagated during event handling, because it is
1802usually not desired. D-Bus errors in events can be made visible by
e7433508
MA
1803setting the variable @code{dbus-debug} to @code{t}. They can also be
1804handled by a hook function.
1805
1806@defvar dbus-event-error-hooks
1807This hook variable keeps a list of functions, which are called when a
1808D-Bus error happens in the event handler. Every function must accept
74fc5047
MA
1809two arguments, the event and the error variable catched in
1810@code{condition-case} by @code{dbus-error}.
1811
1812Such functions can be used the adapt the error signal to be raised.
1813Example:
e7433508
MA
1814
1815@lisp
74fc5047
MA
1816(defun my-dbus-event-error-handler (event error)
1817 (when (string-equal (concat dbus-service-emacs ".FileManager")
1818 (dbus-event-interface-name event))
1819 (message "my-dbus-event-error-handler: %S %S" event error)
1820 (signal 'file-error (cdr error))))
e7433508
MA
1821
1822(add-hook 'dbus-event-error-hooks 'my-dbus-event-error-handler)
1823@end lisp
1824@end defvar
c9ecb5a7 1825
74fc5047
MA
1826Hook functions shall take into account, that there might be other
1827D-Bus applications running. Therefore, they shall check carefully,
1828whether a given D-Bus error is related to them.
1829
22d8ac3a 1830
5bd55c3c
MA
1831@node Index
1832@unnumbered Index
1833
1834@printindex cp
1835
1836
22d8ac3a
MA
1837@node GNU Free Documentation License
1838@appendix GNU Free Documentation License
1839@include doclicense.texi
1840
22d8ac3a 1841@bye