comparison doc/misc/dbus.texi @ 87585:072778cd2f17

* dbus.texi (Receiving Method Calls): New chapter. (Errors and Events): Add serial number to events. Replace "signal" by "message". Introduce dbus-event-serial-number.
author Michael Albinus <michael.albinus@gmx.de>
date Fri, 04 Jan 2008 21:44:23 +0000
parents 084340c0bd27
children af599a62c634
comparison
equal deleted inserted replaced
87584:af7df042c392 87585:072778cd2f17
48 @menu 48 @menu
49 * Overview:: An overview of D-Bus. 49 * Overview:: An overview of D-Bus.
50 * Inspection:: Inspection of the bus names. 50 * Inspection:: Inspection of the bus names.
51 * Type Conversion:: Mapping Lisp types and D-Bus types. 51 * Type Conversion:: Mapping Lisp types and D-Bus types.
52 * Synchronous Methods:: Calling methods in a blocking way. 52 * Synchronous Methods:: Calling methods in a blocking way.
53 * Receiving Method Calls:: Offering own methods.
53 * Signals:: Sending and receiving signals. 54 * Signals:: Sending and receiving signals.
54 * Errors and Events:: Errors and events. 55 * Errors and Events:: Errors and events.
55 * GNU Free Documentation License:: The license for this documentation. 56 * GNU Free Documentation License:: The license for this documentation.
56 @end menu 57 @end menu
57 58
485 @dots{}" 486 @dots{}"
486 @end example 487 @end example
487 @end defun 488 @end defun
488 489
489 490
491 @node Receiving Method Calls
492 @chapter Offering own methods.
493 @cindex method calls, returning
494 @cindex returning method calls
495
496 Emacs can also offer own methods, which can be called by other
497 applications. These methods could be an implementation of an
498 interface of a well known service, like @code{org.freedesktop.TextEditor}.
499
500 It could be also an implementation of an own interface. In this case,
501 the service name must be @code{org.gnu.Emacs}. The object path shall
502 begin with @code{/org/gnu/Emacs/@strong{Application}/}, and the
503 interface name shall be @code{org.gnu.Emacs.@strong{Application}}.
504 @code{@strong{Application}} is the name of the application which
505 provides the interface.
506
507 @defun dbus-register-method bus service path interface method handler
508 With this function, an application registers @var{method} on the D-Bus
509 @var{bus}.
510
511 @var{bus} is either the symbol @code{:system} or the symbol
512 @code{:session}.
513
514 @var{service} is the D-Bus service name of the D-Bus object
515 @var{method} is registered for. It must be a known name.
516
517 @var{path} is the D-Bus object path @var{service} is
518 registered.
519
520 @var{interface} is the interface offered by @var{service}. It must
521 provide @var{method}.
522
523 @var{handler} is a Lisp function to be called when when a @var{method}
524 call is is received. It must accept as arguments the input arguments
525 of @var{method}. @var{handler} must return a list, which elements are
526 used as arguments for the reply message of @var{method}. This list
527 can be composed like the input parameters in @ref{Type Conversion}.
528
529 @code{dbus-register-method} returns a Lisp symbol, which can be used
530 as argument in @code{dbus-unregister-object} for removing the
531 registration for @var{method}. Example:
532
533 @example
534 (defun my-dbus-method-handler (filename)
535 (let (result)
536 (if (find-file filename)
537 (setq result '(:boolean t))
538 (setq result '(:boolean nil)))
539 result))
540
541 @result{} my-dbus-method-handler
542
543 (dbus-register-method
544 :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
545 "org.freedesktop.TextEditor" "OpenFile"
546 'my-dbus-method-handler)
547
548 @result{} ((:system "org.freedesktop.TextEditor" "OpenFile")
549 ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
550 my-method-handler))
551 @end example
552
553 If you invoke the method @code{org.freedesktop.TextEditor.OpenFile}
554 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
556 @var{false}, indicating the success if the method. As test tool one
557 could use the command line tool @code{dbus-send} in a shell:
558
559 @example
560 # dbus-send --session --print-reply \
561 --dest="org.freedesktop.TextEditor" \
562 "/org/freedesktop/TextEditor" \
563 "org.freedesktop.TextEditor.OpenFile" string:"/etc/hosts"
564
565 @print{} method return sender=:1.22 -> dest=:1.23 reply_serial=2
566 boolean true
567 @end example
568 @end defun
569
570
490 @node Signals 571 @node Signals
491 @chapter Sending and receiving signals. 572 @chapter Sending and receiving signals.
492 @cindex signals 573 @cindex signals
493 574
494 Signals are broadcast messages. They carry input parameters, which 575 Signals are broadcast messages. They carry input parameters, which
599 680
600 Incoming D-Bus messages are handled as Emacs events (see @pxref{Misc 681 Incoming D-Bus messages are handled as Emacs events (see @pxref{Misc
601 Events, , , elisp}). The generated event has this form: 682 Events, , , elisp}). The generated event has this form:
602 683
603 @example 684 @example
604 (dbus-event @var{bus} @var{service} @var{path} @var{interface} @var{member} @var{handler} &rest @var{args}) 685 (dbus-event @var{bus} @var{serial} @var{service} @var{path} @var{interface} @var{member} @var{handler} &rest @var{args})
605 @end example 686 @end example
606 687
607 @var{bus} identifies the D-Bus the signal is coming from. It is 688 @var{bus} identifies the D-Bus the signal is coming from. It is
608 either the symbol @code{:system} or the symbol @code{:session}. 689 either the symbol @code{:system} or the symbol @code{:session}.
609 690
691 @var{serial} is the serial number of the received D-Bus message if it
692 is a method call, or @code{nil}.
693
610 @var{service} and @var{path} are the unique name and the object path 694 @var{service} and @var{path} are the unique name and the object path
611 of the D-Bus object emitting the signal. @var{interface} and 695 of the D-Bus object emitting the message. @var{interface} and
612 @var{member} denote the signal which has been sent. 696 @var{member} denote the message which has been sent.
613 697
614 @var{handler} is the callback function which has been registered for 698 @var{handler} is the callback function which has been registered for
615 this signal (see @pxref{Signals}). When a @code{dbus-event} event 699 this message (see @pxref{Signals}). When a @code{dbus-event} event
616 arrives, @var{handler} is called with @var{args} as arguments. 700 arrives, @var{handler} is called with @var{args} as arguments.
617 701
618 In order to inspect the @code{dbus-event} data, you could extend the 702 In order to inspect the @code{dbus-event} data, you could extend the
619 definition of the callback function in @ref{Signals}: 703 definition of the callback function in @ref{Signals}:
620 704
629 @defun dbus-event-bus-name event 713 @defun dbus-event-bus-name event
630 Returns the bus name @var{event} is coming from. 714 Returns the bus name @var{event} is coming from.
631 The result is either the symbol @code{:system} or the symbol @code{:session}. 715 The result is either the symbol @code{:system} or the symbol @code{:session}.
632 @end defun 716 @end defun
633 717
718 @defun dbus-event-serial-number event
719 Returns the serial number of the corresponding D-Bus message.
720 The result is a number in case the D-Bus message is a method
721 call, or @code{nil} for all other mesage types.
722 @end defun
723
634 @defun dbus-event-service-name event 724 @defun dbus-event-service-name event
635 Returns the unique name of the D-Bus object @var{event} is coming from. 725 Returns the unique name of the D-Bus object @var{event} is coming from.
636 @end defun 726 @end defun
637 727
638 @defun dbus-event-path-name event 728 @defun dbus-event-path-name event