comparison doc/misc/dbus.texi @ 91590:6834ec860aff

* dbus.texi (all): Wrap Lisp code examples with @lisp ... @end lisp. (Inspection): New function dbus-ping.
author Michael Albinus <michael.albinus@gmx.de>
date Wed, 06 Feb 2008 21:27:27 +0000
parents af599a62c634
children 83be756929f1
comparison
equal deleted inserted replaced
91589:12b2f1526656 91590:6834ec860aff
156 string. 156 string.
157 @end defun 157 @end defun
158 158
159 @defun dbus-get-name-owner bus service 159 @defun dbus-get-name-owner bus service
160 For a given service, registered at D-Bus @var{bus} under the name 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 result is a 161 @var{service}, the unique name of the name owner is returned. The
162 string, or @code{nil} when there exist no name owner of @var{service}. 162 result is a string, or @code{nil} when there exist no name owner of
163 @var{service}.
163 164
164 @var{bus} must be either the symbol @code{:system} or the symbol 165 @var{bus} must be either the symbol @code{:system} or the symbol
165 @code{:session}. @var{service} must be a known service name as 166 @code{:session}. @var{service} must be a known service name as
166 string. 167 string.
168 @end defun
169
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}.
174
175 @var{bus} must be either the symbol @code{:system} or the symbol
176 @code{:session}. @var{service} must be a string. Example:
177
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
167 @end defun 186 @end defun
168 187
169 @defun dbus-get-unique-name bus 188 @defun dbus-get-unique-name bus
170 The unique name, under which Emacs is registered at D-Bus @var{bus}, 189 The unique name, under which Emacs is registered at D-Bus @var{bus},
171 is returned as string. 190 is returned as string.
183 @code{:session}. @var{service} must be a known service name, and 202 @code{:session}. @var{service} must be a known service name, and
184 @var{path} must be a valid object path. The last two parameters are 203 @var{path} must be a valid object path. The last two parameters are
185 strings. The result, the introspection data, is a string in XML 204 strings. The result, the introspection data, is a string in XML
186 format. Example: 205 format. Example:
187 206
188 @example 207 @lisp
189 (dbus-introspect 208 (dbus-introspect
190 :system "org.freedesktop.Hal" 209 :system "org.freedesktop.Hal"
191 "/org/freedesktop/Hal/devices/computer") 210 "/org/freedesktop/Hal/devices/computer")
192 211
193 @result{} "<!DOCTYPE node PUBLIC 212 @result{} "<!DOCTYPE node PUBLIC
204 <arg name=\"updates\" type=\"a(sbb)\"/> 223 <arg name=\"updates\" type=\"a(sbb)\"/>
205 </signal> 224 </signal>
206 </interface> 225 </interface>
207 @dots{} 226 @dots{}
208 </node>" 227 </node>"
209 @end example 228 @end lisp
210 229
211 This example informs us, that the service @code{org.freedesktop.Hal} 230 This example informs us, that the service @code{org.freedesktop.Hal}
212 at object path @code{/org/freedesktop/Hal/devices/computer} offers the 231 at object path @code{/org/freedesktop/Hal/devices/computer} offers the
213 interface @code{org.freedesktop.Hal.Device} (and 2 other interfaces 232 interface @code{org.freedesktop.Hal.Device} (and 2 other interfaces
214 not documented here). This interface contains the method 233 not documented here). This interface contains the method
420 439
421 The function returns the resulting values of @var{method} as a list of 440 The function returns the resulting values of @var{method} as a list of
422 Lisp objects, according to the type conversion rules described in 441 Lisp objects, according to the type conversion rules described in
423 @ref{Type Conversion}. Example: 442 @ref{Type Conversion}. Example:
424 443
425 @example 444 @lisp
426 (dbus-call-method 445 (dbus-call-method
427 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp" 446 :session "org.gnome.seahorse" "/org/gnome/seahorse/keys/openpgp"
428 "org.gnome.seahorse.Keys" "GetKeyField" 447 "org.gnome.seahorse.Keys" "GetKeyField"
429 "openpgp:657984B8C7A966DD" "simple-name") 448 "openpgp:657984B8C7A966DD" "simple-name")
430 449
431 @result{} (t ("Philip R. Zimmermann")) 450 @result{} (t ("Philip R. Zimmermann"))
432 @end example 451 @end lisp
433 452
434 If the result of the method call is just one value, the converted Lisp 453 If the result of the method call is just one value, the converted Lisp
435 object is returned instead of a list containing this single Lisp 454 object is returned instead of a list containing this single Lisp
436 object. Example: 455 object. Example:
437 456
438 @example 457 @lisp
439 (dbus-call-method 458 (dbus-call-method
440 :system "org.freedesktop.Hal" 459 :system "org.freedesktop.Hal"
441 "/org/freedesktop/Hal/devices/computer" 460 "/org/freedesktop/Hal/devices/computer"
442 "org.freedesktop.Hal.Device" "GetPropertyString" 461 "org.freedesktop.Hal.Device" "GetPropertyString"
443 "system.kernel.machine") 462 "system.kernel.machine")
444 463
445 @result{} "i686" 464 @result{} "i686"
446 @end example 465 @end lisp
447 466
448 With the @code{dbus-introspect} function it is possible to explore the 467 With the @code{dbus-introspect} function it is possible to explore the
449 interfaces of @samp{org.freedesktop.Hal} service. It offers the 468 interfaces of @samp{org.freedesktop.Hal} service. It offers the
450 interfaces @samp{org.freedesktop.Hal.Manager} for the object at the 469 interfaces @samp{org.freedesktop.Hal.Manager} for the object at the
451 path @samp{/org/freedesktop/Hal/Manager} as well as the interface 470 path @samp{/org/freedesktop/Hal/Manager} as well as the interface
452 @samp{org.freedesktop.Hal.Device} for all objects prefixed with the 471 @samp{org.freedesktop.Hal.Device} for all objects prefixed with the
453 path @samp{/org/freedesktop/Hal/devices}. With the methods 472 path @samp{/org/freedesktop/Hal/devices}. With the methods
454 @samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to 473 @samp{GetAllDevices} and @samp{GetAllProperties}, it is simple to
455 emulate the @code{lshal} command on GNU/Linux systems: 474 emulate the @code{lshal} command on GNU/Linux systems:
456 475
457 @example 476 @lisp
458 (dolist (device 477 (dolist (device
459 (dbus-call-method 478 (dbus-call-method
460 :system "org.freedesktop.Hal" 479 :system "org.freedesktop.Hal"
461 "/org/freedesktop/Hal/Manager" 480 "/org/freedesktop/Hal/Manager"
462 "org.freedesktop.Hal.Manager" "GetAllDevices")) 481 "org.freedesktop.Hal.Manager" "GetAllDevices"))
482 smbios.bios.release_date = \"11/07/2001\" 501 smbios.bios.release_date = \"11/07/2001\"
483 system.chassis.manufacturer = \"COMPAL\" 502 system.chassis.manufacturer = \"COMPAL\"
484 system.chassis.type = \"Notebook\" 503 system.chassis.type = \"Notebook\"
485 system.firmware.release_date = \"03/19/2005\" 504 system.firmware.release_date = \"03/19/2005\"
486 @dots{}" 505 @dots{}"
487 @end example 506 @end lisp
488 @end defun 507 @end defun
489 508
490 509
491 @node Receiving Method Calls 510 @node Receiving Method Calls
492 @chapter Offering own methods. 511 @chapter Offering own methods.
528 547
529 @code{dbus-register-method} returns a Lisp symbol, which can be used 548 @code{dbus-register-method} returns a Lisp symbol, which can be used
530 as argument in @code{dbus-unregister-object} for removing the 549 as argument in @code{dbus-unregister-object} for removing the
531 registration for @var{method}. Example: 550 registration for @var{method}. Example:
532 551
533 @example 552 @lisp
534 (defun my-dbus-method-handler (filename) 553 (defun my-dbus-method-handler (filename)
535 (let (result) 554 (let (result)
536 (if (find-file filename) 555 (if (find-file filename)
537 (setq result '(:boolean t)) 556 (setq result '(:boolean t))
538 (setq result '(:boolean nil))) 557 (setq result '(:boolean nil)))
546 'my-dbus-method-handler) 565 'my-dbus-method-handler)
547 566
548 @result{} ((:system "org.freedesktop.TextEditor" "OpenFile") 567 @result{} ((:system "org.freedesktop.TextEditor" "OpenFile")
549 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor" 568 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
550 my-method-handler)) 569 my-method-handler))
551 @end example 570 @end lisp
552 571
553 If you invoke the method @code{org.freedesktop.TextEditor.OpenFile} 572 If you invoke the method @code{org.freedesktop.TextEditor.OpenFile}
554 from another D-Bus application with a filename as parameter, the file 573 from another D-Bus application with a filename as parameter, the file
555 is opened in Emacs, and the method returns either @var{true} or 574 is opened in Emacs, and the method returns either @var{true} or
556 @var{false}, indicating the success if the method. As test tool one 575 @var{false}, indicating the success if the method. As test tool one
590 609
591 All other arguments args are passed to @var{signal} as arguments. 610 All other arguments args are passed to @var{signal} as arguments.
592 They are converted into D-Bus types as described in @ref{Type 611 They are converted into D-Bus types as described in @ref{Type
593 Conversion}. Example: 612 Conversion}. Example:
594 613
595 @example 614 @lisp
596 (dbus-send-signal 615 (dbus-send-signal
597 :session "org.gnu.Emacs" "/org/gnu/Emacs" 616 :session "org.gnu.Emacs" "/org/gnu/Emacs"
598 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs") 617 "org.gnu.Emacs.FileManager" "FileModified" "/home/albinus/.emacs")
599 @end example 618 @end lisp
600 @end defun 619 @end defun
601 620
602 @defun dbus-register-signal bus service path interface signal handler 621 @defun dbus-register-signal bus service path interface signal handler
603 With this function, an application registers for @var{signal} on the 622 With this function, an application registers for @var{signal} on the
604 D-Bus @var{bus}. 623 D-Bus @var{bus}.
624 643
625 @var{handler} is a Lisp function to be called when the @var{signal} is 644 @var{handler} is a Lisp function to be called when the @var{signal} is
626 received. It must accept as arguments the output parameters 645 received. It must accept as arguments the output parameters
627 @var{signal} is sending. Example: 646 @var{signal} is sending. Example:
628 647
629 @example 648 @lisp
630 (defun my-dbus-signal-handler (device) 649 (defun my-dbus-signal-handler (device)
631 (message "Device %s added" device)) 650 (message "Device %s added" device))
632 651
633 @result{} my-dbus-signal-handler 652 @result{} my-dbus-signal-handler
634 653
638 'my-dbus-signal-handler) 657 'my-dbus-signal-handler)
639 658
640 @result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded") 659 @result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
641 ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager" 660 ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
642 my-signal-handler)) 661 my-signal-handler))
643 @end example 662 @end lisp
644 663
645 As we know from the inspection data of interface 664 As we know from the inspection data of interface
646 @code{org.freedesktop.Hal.Manager}, the signal @code{DeviceAdded} 665 @code{org.freedesktop.Hal.Manager}, the signal @code{DeviceAdded}
647 provides one single parameter, which is mapped into a Lisp string. 666 provides one single parameter, which is mapped into a Lisp string.
648 The callback function @code{my-dbus-signal-handler} must define one 667 The callback function @code{my-dbus-signal-handler} must define one
685 @end defspec 704 @end defspec
686 705
687 Incoming D-Bus messages are handled as Emacs events (see @pxref{Misc 706 Incoming D-Bus messages are handled as Emacs events (see @pxref{Misc
688 Events, , , elisp}). The generated event has this form: 707 Events, , , elisp}). The generated event has this form:
689 708
690 @example 709 @lisp
691 (dbus-event @var{bus} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler} &rest @var{args}) 710 (dbus-event @var{bus} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler} &rest @var{args})
692 @end example 711 @end lisp
693 712
694 @var{bus} identifies the D-Bus the signal is coming from. It is 713 @var{bus} identifies the D-Bus the signal is coming from. It is
695 either the symbol @code{:system} or the symbol @code{:session}. 714 either the symbol @code{:system} or the symbol @code{:session}.
696 715
697 @var{serial} is the serial number of the received D-Bus message if it 716 @var{serial} is the serial number of the received D-Bus message if it
706 arrives, @var{handler} is called with @var{args} as arguments. 725 arrives, @var{handler} is called with @var{args} as arguments.
707 726
708 In order to inspect the @code{dbus-event} data, you could extend the 727 In order to inspect the @code{dbus-event} data, you could extend the
709 definition of the callback function in @ref{Signals}: 728 definition of the callback function in @ref{Signals}:
710 729
711 @example 730 @lisp
712 (defun my-dbus-signal-handler (&rest args) 731 (defun my-dbus-signal-handler (&rest args)
713 (message "my-dbus-signal-handler: %S" last-input-event)) 732 (message "my-dbus-signal-handler: %S" last-input-event))
714 @end example 733 @end lisp
715 734
716 There exist convenience functions which could be called inside a 735 There exist convenience functions which could be called inside a
717 callback function in order to retrieve the information from the event. 736 callback function in order to retrieve the information from the event.
718 737
719 @defun dbus-event-bus-name event 738 @defun dbus-event-bus-name event