Don't say "buying copies from the FSF" for manuals they do not publish
[bpt/emacs.git] / doc / misc / dbus.texi
index b58fbcb..610321f 100644 (file)
@@ -5,8 +5,11 @@
 @c @setchapternewpage odd
 @c %**end of header
 
+@syncodeindex vr cp
+@syncodeindex fn cp
+
 @copying
-Copyright @copyright{} 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+Copyright @copyright{} 2007-2012 Free Software Foundation, Inc.
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -17,8 +20,7 @@ and with the Back-Cover Texts as in (a) below.  A copy of the license
 is included in the section entitled ``GNU Free Documentation License''.
 
 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
-modify this GNU manual.  Buying copies from the FSF supports it in
-developing GNU and promoting software freedom.''
+modify this GNU manual.''
 @end quotation
 @end copying
 
@@ -50,7 +52,10 @@ another.  An overview of D-Bus can be found at
 * Asynchronous Methods::        Calling methods non-blocking.
 * Receiving Method Calls::      Offering own methods.
 * Signals::                     Sending and receiving signals.
+* Alternative Buses::           Alternative buses and environments.
 * Errors and Events::           Errors and events.
+* Index::                       Index including concepts, functions, variables.
+
 * GNU Free Documentation License:: The license for this documentation.
 @end menu
 
@@ -110,6 +115,7 @@ name could be @samp{org.gnu.Emacs.TextEditor} or
 @cindex inspection
 
 @menu
+* Version::                     Determining the D-Bus version.
 * Bus names::                   Discovering D-Bus names.
 * Introspection::               Knowing the details of D-Bus services.
 * Nodes and Interfaces::        Detecting object paths and interfaces.
@@ -119,6 +125,25 @@ name could be @samp{org.gnu.Emacs.TextEditor} or
 @end menu
 
 
+@node Version
+@section D-Bus version.
+
+D-Bus has evolved over the years.  New features have been added with
+new D-Bus versions.  There are two variables, which allow to determine
+the used D-Bus version.
+
+@defvar dbus-compiled-version
+This variable, a string, determines the version of D-Bus Emacs is
+compiled against.  If it cannot be determined the value is @code{nil}.
+@end defvar
+
+@defvar dbus-runtime-version
+The other D-Bus version to be checked is the version of D-Bus Emacs
+runs with.  This string can be different from @code{dbus-compiled-version}.
+It is also @code{nil}, if it cannot be determined at runtime.
+@end defvar
+
+
 @node Bus names
 @section Bus names.
 
@@ -126,14 +151,23 @@ There are several basic functions which inspect the buses for
 registered names.  Internally they use the basic interface
 @samp{org.freedesktop.DBus}, which is supported by all objects of a bus.
 
-@defun dbus-list-activatable-names
-This function returns the D-Bus service names, which can be activated.
-An activatable service is described in a service registration file.
-Under GNU/Linux, such files are located at
-@file{/usr/share/dbus-1/services/}.
+@defun dbus-list-activatable-names &optional bus
+This function returns the D-Bus service names, which can be activated
+for @var{bus}.  It must be either the symbol @code{:system} (the
+default) or the symbol @code{:session}.  An activatable service is
+described in a service registration file.  Under GNU/Linux, such files
+are located at @file{/usr/share/dbus-1/system-services/} (for the
+@code{:system} bus) or @file{/usr/share/dbus-1/services/}.  An
+activatable service is not necessarily registered at @var{bus} at already.
 
 The result is a list of strings, which is @code{nil} when there are no
-activatable service names at all.
+activatable service names at all.  Example:
+
+@lisp
+;; Check, whether the document viewer can be accessed via D-Bus.
+(member "org.gnome.evince.Daemon"
+        (dbus-list-activatable-names :session))
+@end lisp
 @end defun
 
 @defun dbus-list-names bus
@@ -148,7 +182,7 @@ strings like @samp{org.freedesktop.DBus}.  Names starting with
 @end defun
 
 @defun dbus-list-known-names bus
-Retrieves all services which correspond to a known name in @var{bus}.
+Retrieves all registered services which correspond to a known name in @var{bus}.
 A service has a known name if it doesn't start with @samp{:}.  The
 result is a list of strings, which is @code{nil} when there are no
 known names at all.
@@ -316,7 +350,7 @@ Example:
 @code{method}, @code{signal}, and @code{property} elements.  Unlike
 properties, which can change their values during lifetime of a D-Bus
 object, annotations are static.  Often they are used for code
-generators of D-Bus langugae bindings.  Example:
+generators of D-Bus language bindings.  Example:
 
 @example
 <annotation name="de.berlios.Pinot.GetStatistics" value="pinotDBus"/>
@@ -418,7 +452,8 @@ Example:
 @result{} "/org/freedesktop/SystemToolsBackends/UsersConfig"
 @end lisp
 
-If @var{object} has no @var{attribute}, the function returns nil.
+If @var{object} has no @var{attribute}, the function returns
+@code{nil}.
 @end defun
 
 
@@ -536,7 +571,7 @@ data from a running system:
 @node Methods and Signal
 @section Applying the functionality.
 
-Methods and signals are the communicatione means to D-Bus.  The
+Methods and signals are the communication means to D-Bus.  The
 following functions return their specifications.
 
 @defun dbus-introspect-get-method-names bus service path interface
@@ -620,6 +655,12 @@ Interfaces can have properties.  These can be exposed via the
 That is, properties can be retrieved and changed during lifetime of an
 element.
 
+A generalized interface is
+@samp{org.freedesktop.DBus.Objectmanager}@footnote{See
+@uref{http://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager}},
+which returns objects, their interfaces and properties for a given
+service in just one call.
+
 Annotations, on the other hand, are static values for an element.
 Often, they are used to instruct generators, how to generate code from
 the interface for a given language binding.
@@ -669,7 +710,7 @@ A @var{property} value can be retrieved by the function
 @defun dbus-get-property bus service path interface property
 This function returns the value of @var{property} of @var{interface}.
 It will be checked at @var{bus}, @var{service}, @var{path}.  The
-result can be any valid D-Bus value, or nil if there is no
+result can be any valid D-Bus value, or @code{nil} if there is no
 @var{property}.  Example:
 
 @lisp
@@ -715,6 +756,61 @@ If there are no properties, @code{nil} is returned.  Example:
 @end lisp
 @end defun
 
+@defun dbus-get-all-managed-objects bus service path
+This functions returns all objects at @var{bus}, @var{service},
+@var{path}, and the children of @var{path}.  The result is a list of
+objects.  Every object is a cons of an existing path name, and the
+list of available interface objects.  An interface object is another
+cons, which car is the interface name, and the cdr is the list of
+properties as returned by @code{dbus-get-all-properties} for that path
+and interface. Example:
+
+@lisp
+(dbus-get-all-managed-objects
+  :session "org.gnome.SettingsDaemon" "/")
+
+@result{} (("/org/gnome/SettingsDaemon/MediaKeys"
+     ("org.gnome.SettingsDaemon.MediaKeys")
+     ("org.freedesktop.DBus.Peer")
+     ("org.freedesktop.DBus.Introspectable")
+     ("org.freedesktop.DBus.Properties")
+     ("org.freedesktop.DBus.ObjectManager"))
+    ("/org/gnome/SettingsDaemon/Power"
+     ("org.gnome.SettingsDaemon.Power.Keyboard")
+     ("org.gnome.SettingsDaemon.Power.Screen")
+     ("org.gnome.SettingsDaemon.Power"
+      ("Icon" . ". GThemedIcon battery-full-charged-symbolic ")
+      ("Tooltip" . "Laptop battery is charged"))
+     ("org.freedesktop.DBus.Peer")
+     ("org.freedesktop.DBus.Introspectable")
+     ("org.freedesktop.DBus.Properties")
+     ("org.freedesktop.DBus.ObjectManager"))
+    @dots{})
+@end lisp
+
+If possible, @samp{org.freedesktop.DBus.ObjectManager.GetManagedObjects}
+is used for retrieving the information.  Otherwise, the information
+is collected via @samp{org.freedesktop.DBus.Introspectable.Introspect}
+and @samp{org.freedesktop.DBus.Properties.GetAll}, which is slow.
+
+An overview of all existing object paths, their interfaces and
+properties could be retrieved by the following code:
+
+@lisp
+(with-current-buffer (switch-to-buffer "*objectmanager*")
+  (erase-buffer)
+  (let (result)
+    (dolist (service (dbus-list-known-names :session) result)
+      (message "%s" service)
+      (add-to-list
+       'result
+       (cons service
+             (dbus-get-all-managed-objects :session service "/"))))
+    (insert (message "%s" (pp result)))
+    (redisplay t)))
+@end lisp
+@end defun
+
 @defun dbus-introspect-get-annotation-names bus service path interface &optional name
 Return a list of all annotation names as list of strings.  If
 @var{name} is @code{nil}, the annotations are children of
@@ -863,12 +959,12 @@ Lisp function call.  The following mapping to D-Bus types is
 applied, when the corresponding D-Bus message is created:
 
 @example
-@multitable {@code{t} and @code{nil}} {@expansion{}} {DBUS_TYPE_BOOLEAN}
+@multitable {negative integer} {@expansion{}} {DBUS_TYPE_BOOLEAN}
 @item Lisp type               @tab              @tab D-Bus type
 @item
 @item @code{t} and @code{nil} @tab @expansion{} @tab DBUS_TYPE_BOOLEAN
-@item number                  @tab @expansion{} @tab DBUS_TYPE_UINT32
-@item integer                 @tab @expansion{} @tab DBUS_TYPE_INT32
+@item natural number          @tab @expansion{} @tab DBUS_TYPE_UINT32
+@item negative integer        @tab @expansion{} @tab DBUS_TYPE_INT32
 @item float                   @tab @expansion{} @tab DBUS_TYPE_DOUBLE
 @item string                  @tab @expansion{} @tab DBUS_TYPE_STRING
 @item list                    @tab @expansion{} @tab DBUS_TYPE_ARRAY
@@ -876,32 +972,33 @@ applied, when the corresponding D-Bus message is created:
 @end example
 
 Other Lisp objects, like symbols or hash tables, are not accepted as
-input parameter.
+input parameters.
 
 If it is necessary to use another D-Bus type, a corresponding type
-symbol can be preceeded to the corresponding Lisp object. Basic D-Bus
+symbol can be prepended to the corresponding Lisp object.  Basic D-Bus
 types are represented by the type symbols @code{:byte},
 @code{:boolean}, @code{:int16}, @code{:uint16}, @code{:int32},
 @code{:uint32}, @code{:int64}, @code{:uint64}, @code{:double},
-@code{:string}, @code{:object-path} and @code{:signature}.
+@code{:string}, @code{:object-path}, @code{:signature} and
+@code{:unix-fd}.
 
 @noindent
 Example:
 
 @lisp
-(dbus-call-method @dots{} @var{NUMBER} @var{STRING})
+(dbus-call-method @dots{} @var{NAT-NUMBER} @var{STRING})
 @end lisp
 
 is equivalent to
 
 @lisp
-(dbus-call-method @dots{} :uint32 @var{NUMBER} :string @var{STRING})
+(dbus-call-method @dots{} :uint32 @var{NAT-NUMBER} :string @var{STRING})
 @end lisp
 
 but different to
 
 @lisp
-(dbus-call-method @dots{} :int32 @var{NUMBER} :signature @var{STRING})
+(dbus-call-method @dots{} :int32 @var{NAT-NUMBER} :signature @var{STRING})
 @end lisp
 
 The value for a byte D-Bus type can be any integer in the range 0
@@ -910,6 +1007,10 @@ represented outside this range are stripped of.  For example,
 @code{:byte ?x} is equal to @code{:byte ?\M-x}, but it is not equal to
 @code{:byte ?\C-x} or @code{:byte ?\M-\C-x}.
 
+Signed and unsigned integer D-Bus types expect a corresponding integer
+value.  If the value does not fit Emacs's integer range, it is also
+possible to use an equivalent floating point number.
+
 A D-Bus compound type is always represented as a list.  The @sc{car}
 of this list can be the type symbol @code{:array}, @code{:variant},
 @code{:struct} or @code{:dict-entry}, which would result in a
@@ -994,17 +1095,18 @@ Output parameters of D-Bus methods and signals are mapped to Lisp
 objects.
 
 @example
-@multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {@code{t} or @code{nil}}
+@multitable {DBUS_TYPE_OBJECT_PATH} {@expansion{}} {natural number or float}
 @item D-Bus type            @tab              @tab Lisp type
 @item
 @item DBUS_TYPE_BOOLEAN     @tab @expansion{} @tab @code{t} or @code{nil}
-@item DBUS_TYPE_BYTE        @tab @expansion{} @tab number
-@item DBUS_TYPE_UINT16      @tab @expansion{} @tab number
-@item DBUS_TYPE_INT16       @tab @expansion{} @tab number
-@item DBUS_TYPE_UINT32      @tab @expansion{} @tab number or float
-@item DBUS_TYPE_INT32       @tab @expansion{} @tab number or float
-@item DBUS_TYPE_UINT64      @tab @expansion{} @tab number or float
-@item DBUS_TYPE_INT64       @tab @expansion{} @tab number or float
+@item DBUS_TYPE_BYTE        @tab @expansion{} @tab natural number
+@item DBUS_TYPE_UINT16      @tab @expansion{} @tab natural number
+@item DBUS_TYPE_INT16       @tab @expansion{} @tab integer
+@item DBUS_TYPE_UINT32      @tab @expansion{} @tab natural number or float
+@item DBUS_TYPE_UNIX_FD     @tab @expansion{} @tab natural number or float
+@item DBUS_TYPE_INT32       @tab @expansion{} @tab integer or float
+@item DBUS_TYPE_UINT64      @tab @expansion{} @tab natural number or float
+@item DBUS_TYPE_INT64       @tab @expansion{} @tab integer or float
 @item DBUS_TYPE_DOUBLE      @tab @expansion{} @tab float
 @item DBUS_TYPE_STRING      @tab @expansion{} @tab string
 @item DBUS_TYPE_OBJECT_PATH @tab @expansion{} @tab string
@@ -1017,9 +1119,9 @@ objects.
 @end example
 
 A float object in case of @code{DBUS_TYPE_UINT32},
-@code{DBUS_TYPE_INT32}, @code{DBUS_TYPE_UINT64} and
-@code{DBUS_TYPE_INT6432} is returned, when the C value exceeds the
-Emacs number size range.
+@code{DBUS_TYPE_INT32}, @code{DBUS_TYPE_UINT64},
+@code{DBUS_TYPE_INT64} and @code{DBUS_TYPE_UNIX_FD} is returned, when
+the C value exceeds the Emacs number size range.
 
 The resulting list of the last 4 D-Bus compound types contains as
 elements the elements of the D-Bus container, mapped according to the
@@ -1030,7 +1132,7 @@ The signal @code{PropertyModified}, discussed as example in
 (@var{BOOL} stands here for either @code{nil} or @code{t}):
 
 @lisp
-(@var{NUMBER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
+(@var{INTEGER} ((@var{STRING} @var{BOOL} @var{BOOL}) (@var{STRING} @var{BOOL} @var{BOOL}) @dots{}))
 @end lisp
 
 @defun dbus-byte-array-to-string byte-array
@@ -1163,24 +1265,6 @@ emulate the @code{lshal} command on GNU/Linux systems:
 @end lisp
 @end defun
 
-@defun dbus-call-method-non-blocking bus service path interface method &optional :timeout timeout &rest args
-Call @var{method} on the D-Bus @var{bus}, but don't block the event queue.
-This is necessary for communicating to registered D-Bus methods,
-which are running in the same Emacs process.
-
-The arguments are the same as in @code{dbus-call-method}.  Example:
-
-@lisp
-(dbus-call-method-non-blocking
-  :system "org.freedesktop.Hal"
-  "/org/freedesktop/Hal/devices/computer"
-  "org.freedesktop.Hal.Device" "GetPropertyString"
-  "system.kernel.machine")
-
-@result{} "i686"
-@end lisp
-@end defun
-
 
 @node Asynchronous Methods
 @chapter Calling methods non-blocking.
@@ -1210,7 +1294,7 @@ All other arguments args are passed to @var{method} as arguments.
 They are converted into D-Bus types as described in @ref{Type
 Conversion}.
 
-Unless @var{handler} is @code{nil}, the function returns a key into
+If @var{handler} is a Lisp function, the function returns a key into
 the hash table @code{dbus-registered-objects-table}.  The
 corresponding entry in the hash table is removed, when the return
 message has been arrived, and @var{handler} is called.  Example:
@@ -1222,7 +1306,7 @@ message has been arrived, and @var{handler} is called.  Example:
   "org.freedesktop.Hal.Device" "GetPropertyString" 'message
   "system.kernel.machine")
 
-@result{} (:system 2)
+@result{} (:serial :system 2)
 
 @print{} i686
 @end lisp
@@ -1234,28 +1318,94 @@ message has been arrived, and @var{handler} is called.  Example:
 @cindex method calls, returning
 @cindex returning method calls
 
-Emacs can also offer own methods, which can be called by other
-applications.  These methods could be an implementation of an
-interface of a well known service, like @samp{org.freedesktop.TextEditor}.
+In order to register methods on the D-Bus, Emacs has to request a well
+known name on the D-Bus under which it will be available for other
+clients.  Names on the D-Bus can be registered and unregistered using
+the following functions:
+
+@defun dbus-register-service bus service &rest flags
+Register the known name @var{service} on D-Bus @var{bus}.
+
+@var{bus} is either the symbol @code{:system} or the symbol
+@code{:session}.
+
+@var{service} is the service name to be registered on the D-Bus.  It
+must be a known name.
+
+@var{flags} is a subset of the following keywords:
+
+@itemize
+@item @code{:allow-replacement}: Allow another service to become the primary
+owner if requested.
+
+@item @code{:replace-existing}: Request to replace the current primary owner.
+
+@item @code{:do-not-queue}: If we can not become the primary owner do not
+place us in the queue.
+@end itemize
+
+One of the following keywords is returned:
+
+@itemize
+
+@item @code{:primary-owner}: We have become the primary owner of the name
+@var{service}.
+
+@item @code{:in-queue}: We could not become the primary owner and
+have been placed in the queue.
+
+@item @code{:exists}: We already are in the queue.
+
+@item @code{:already-owner}: We already are the primary
+owner.
+@end itemize
+@end defun
+
+@defun dbus-unregister-service bus service
+Unregister all objects from D-Bus @var{bus}, registered by Emacs for
+@var{service}.
+
+@var{bus} is either the symbol @code{:system} or the symbol
+@code{:session}.
+
+@var{service} is the D-Bus service name of the D-Bus.  It must be a
+known name.  Emacs releases its association to @var{service} from
+D-Bus.
+
+One of the following keywords is returned:
+
+@itemize
+@item @code{:released}: We successfully released the name @var{service}.
+@item @code{:non-existent}: The name @var{service} does not exist on the bus.
+@item @code{:not-owner}: We are not an owner of the name @var{service}.
+@end itemize
+@end defun
+
+When a name has been chosen, Emacs can offer own methods, which can be
+called by other applications.  These methods could be an
+implementation of an interface of a well known service, like
+@samp{org.freedesktop.TextEditor}.
 
 It could be also an implementation of an own interface.  In this case,
 the service name must be @samp{org.gnu.Emacs}.  The object path shall
-begin with @samp{/org/gnu/Emacs/@strong{Application}/}, and the
+begin with @samp{/org/gnu/Emacs/@strong{Application}}, and the
 interface name shall be @code{org.gnu.Emacs.@strong{Application}}.
 @samp{@strong{Application}} is the name of the application which
 provides the interface.
 
 @deffn Constant dbus-service-emacs
-The well known service name of Emacs.
+The well known service name @samp{org.gnu.Emacs} of Emacs.
 @end deffn
 
 @deffn Constant dbus-path-emacs
-The object path head "/org/gnu/Emacs" used by Emacs.  All object
-paths, used by offered methods or signals, shall start with this
-string.
+The object path namespace @samp{/org/gnu/Emacs} used by Emacs.
+@end deffn
+
+@deffn Constant dbus-interface-emacs
+The interface namespace @code{org.gnu.Emacs} used by Emacs.
 @end deffn
 
-@defun dbus-register-method bus service path interface method handler
+@defun dbus-register-method bus service path interface method handler dont-register-service
 With this function, an application registers @var{method} on the D-Bus
 @var{bus}.
 
@@ -1263,10 +1413,11 @@ With this function, an application registers @var{method} on the D-Bus
 @code{:session}.
 
 @var{service} is the D-Bus service name of the D-Bus object
-@var{method} is registered for.  It must be a known name.
+@var{method} is registered for.  It must be a known name (See
+discussion of @var{dont-register-service} below).
 
-@var{path} is the D-Bus object path @var{service} is
-registered.
+@var{path} is the D-Bus object path @var{service} is registered (See
+discussion of @var{dont-register-service} below).
 
 @var{interface} is the interface offered by @var{service}.  It must
 provide @var{method}.
@@ -1285,6 +1436,13 @@ returning a list containing the object.
 In case @var{handler} shall return a reply message with an empty
 argument list, @var{handler} must return the symbol @code{:ignore}.
 
+When @var{dont-register-service} is non-@code{nil}, the known name
+@var{service} is not registered.  This means that other D-Bus clients
+have no way of noticing the newly registered method.  When interfaces
+are constructed incrementally by adding single methods or properties
+at a time, @var{dont-register-service} can be used to prevent other
+clients from discovering the still incomplete interface.
+
 The default D-Bus timeout when waiting for a message reply is 25
 seconds.  This value could be even smaller, depending on the calling
 client.  Therefore, @var{handler} shall not last longer than
@@ -1309,7 +1467,7 @@ registration for @var{method}.  Example:
   "org.freedesktop.TextEditor" "OpenFile"
   'my-dbus-method-handler)
 
-@result{} ((:session "org.freedesktop.TextEditor" "OpenFile")
+@result{} ((:method :session "org.freedesktop.TextEditor" "OpenFile")
     ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
      my-dbus-method-handler))
 @end lisp
@@ -1359,7 +1517,7 @@ The test runs then
 @end example
 @end defun
 
-@defun dbus-register-property bus service path interface property access value
+@defun dbus-register-property bus service path interface property access value &optional emits-signal dont-register-service
 With this function, an application declares a @var{property} on the D-Bus
 @var{bus}.
 
@@ -1369,8 +1527,8 @@ With this function, an application declares a @var{property} on the D-Bus
 @var{service} is the D-Bus service name of the D-Bus.  It must be a
 known name.
 
-@var{path} is the D-Bus object path @var{service} is
-registered.
+@var{path} is the D-Bus object path @var{service} is registered (See
+discussion of @var{dont-register-service} below).
 
 @var{interface} is the name of the interface used at @var{path},
 @var{property} is the name of the property of @var{interface}.
@@ -1387,21 +1545,33 @@ only way to change their values.  Properties with access type
 
 The interface @samp{org.freedesktop.DBus.Properties} is added to
 @var{path}, including a default handler for the @samp{Get},
-@samp{GetAll} and @samp{Set} methods of this interface.  Example:
+@samp{GetAll} and @samp{Set} methods of this interface.  When
+@var{emits-signal} is non-@code{nil}, the signal
+@samp{PropertiesChanged} is sent when the property is changed by
+@code{dbus-set-property}.
+
+When @var{dont-register-service} is non-@code{nil}, the known name
+@var{service} is not registered.  This means that other D-Bus clients
+have no way of noticing the newly registered method.  When interfaces
+are constructed incrementally by adding single methods or properties
+at a time, @var{dont-register-service} can be used to prevent other
+clients from discovering the still incomplete interface.
+
+@noindent Example:
 
 @lisp
 (dbus-register-property
   :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
   "org.freedesktop.TextEditor" "name" :read "GNU Emacs")
 
-@result{} ((:session "org.freedesktop.TextEditor" "name")
+@result{} ((:property :session "org.freedesktop.TextEditor" "name")
     ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"))
 
 (dbus-register-property
   :session "org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"
-  "org.freedesktop.TextEditor" "version" :readwrite emacs-version)
+  "org.freedesktop.TextEditor" "version" :readwrite emacs-version t)
 
-@result{} ((:session "org.freedesktop.TextEditor" "version")
+@result{} ((:property :session "org.freedesktop.TextEditor" "version")
     ("org.freedesktop.TextEditor" "/org/freedesktop/TextEditor"))
 @end lisp
 
@@ -1461,25 +1631,13 @@ registered for the respective service, Emacs releases its association
 to the service from D-Bus.
 @end defun
 
-@defun dbus-unregister-service bus service
-Unregister all objects from D-Bus @var{bus}, registered by Emacs for
-@var{service}.
-
-@var{bus} is either the symbol @code{:system} or the symbol
-@code{:session}.
-
-@var{service} is the D-Bus service name of the D-Bus.  It must be a
-known name.  Emacs releases its association to @var{service} from
-D-Bus.
-@end defun
-
 
 @node Signals
 @chapter Sending and receiving signals.
 @cindex signals
 
-Signals are broadcast messages.  They carry input parameters, which
-are received by all objects which have registered for such a signal.
+Signals are one way messages.  They carry input parameters, which are
+received by all objects which have registered for such a signal.
 
 @defun dbus-send-signal bus service path interface signal &rest args
 This function is similar to @code{dbus-call-method}.  The difference
@@ -1489,10 +1647,14 @@ The function emits @var{signal} on the D-Bus @var{bus}.  @var{bus} is
 either the symbol @code{:system} or the symbol @code{:session}.  It
 doesn't matter whether another object has registered for @var{signal}.
 
-@var{service} is the D-Bus service name of the object the signal is
-emitted from.  @var{path} is the corresponding D-Bus object path,
-@var{service} is registered at.  @var{interface} is an interface
-offered by @var{service}.  It must provide @var{signal}.
+Signals can be unicast or broadcast messages.  For broadcast messages,
+@var{service} must be @code{nil}.  Otherwise, @var{service} is the
+D-Bus service name the signal is sent to as unicast
+message.@footnote{For backward compatibility, a broadcast message is
+also emitted if @var{service} is the known or unique name Emacs is
+registered at D-Bus @var{bus}.}  @var{path} is the D-Bus object path
+@var{signal} is sent from.  @var{interface} is an interface available
+at @var{path}.  It must provide @var{signal}.
 
 All other arguments args are passed to @var{signal} as arguments.
 They are converted into D-Bus types as described in @ref{Type
@@ -1500,43 +1662,66 @@ Conversion}.  Example:
 
 @lisp
 (dbus-send-signal
-  :session dbus-service-emacs dbus-path-emacs
-  (concat dbus-service-emacs ".FileManager") "FileModified"
+  :session nil dbus-path-emacs
+  (concat dbus-interface-emacs ".FileManager") "FileModified"
   "/home/albinus/.emacs")
 @end lisp
 @end defun
 
 @defun dbus-register-signal bus service path interface signal handler &rest args
-With this function, an application registers for @var{signal} on the
-D-Bus @var{bus}.
+With this function, an application registers for a signal on the D-Bus
+@var{bus}.
 
 @var{bus} is either the symbol @code{:system} or the symbol
 @code{:session}.
 
 @var{service} is the D-Bus service name used by the sending D-Bus
 object.  It can be either a known name or the unique name of the D-Bus
-object sending the signal.  In case of a unique name, signals won't be
-received any longer once the object owning this unique name has
-disappeared, and a new queued object has replaced it.
-
-When @var{service} is @code{nil}, related signals from all D-Bus
-objects shall be accepted.
+object sending the signal.  A known name will be mapped onto the
+unique name of the object, owning @var{service} at registration time.
+When the corresponding D-Bus object disappears, signals won't be
+received any longer.
 
 @var{path} is the corresponding D-Bus object path, @var{service} is
-registered at.  It can also be @code{nil} if the path name of incoming
-signals shall not be checked.
+registered at.  @var{interface} is an interface offered by
+@var{service}.  It must provide @var{signal}.
 
-@var{interface} is an interface offered by @var{service}.  It must
-provide @var{signal}.
+@var{service}, @var{path}, @var{interface} and @var{signal} can be
+@code{nil}.  This is interpreted as a wildcard for the respective
+argument.
 
 @var{handler} is a Lisp function to be called when the @var{signal} is
 received.  It must accept as arguments the output parameters
 @var{signal} is sending.
 
-All other arguments @var{args}, if specified, must be strings.  They
-stand for the respective arguments of @var{signal} in their order, and
-are used for filtering as well.  A @code{nil} argument might be used
-to preserve the order.
+The remaining arguments @var{args} can be keywords or keyword string
+pairs.@footnote{For backward compatibility, the arguments @var{args}
+can also be just strings.  They stand for the respective arguments of
+@var{signal} in their order, and are used for filtering as well.  A
+@code{nil} argument might be used to preserve the order.}  The meaning
+is as follows:
+
+@itemize
+@item @code{:argN} @var{string}:@*
+@code{:pathN} @var{string}:@*
+This stands for the Nth argument of the signal.  @code{:pathN}
+arguments can be used for object path wildcard matches as specified by
+D-Bus, while an @code{:argN} argument requires an exact match.
+
+@item @code{:arg-namespace} @var{string}:@*
+Register for the signals, which first argument defines the service or
+interface namespace @var{string}.
+
+@item @code{:path-namespace} @var{string}:@*
+Register for the object path namespace @var{string}.  All signals sent
+from an object path, which has @var{string} as the preceding string,
+are matched.  This requires @var{path} to be @code{nil}.
+
+@item @code{:eavesdrop}:@*
+Register for unicast signals which are not directed to the D-Bus
+object Emacs is registered at D-Bus BUS, if the security policy of BUS
+allows this.  Otherwise, this argument is ignored.
+@end itemize
 
 @code{dbus-register-signal} returns a Lisp object, which can be used
 as argument in @code{dbus-unregister-object} for removing the
@@ -1553,7 +1738,7 @@ registration for @var{signal}.  Example:
   "org.freedesktop.Hal.Manager" "DeviceAdded"
   'my-dbus-signal-handler)
 
-@result{} ((:system "org.freedesktop.Hal.Manager" "DeviceAdded")
+@result{} ((:signal :system "org.freedesktop.Hal.Manager" "DeviceAdded")
     ("org.freedesktop.Hal" "/org/freedesktop/Hal/Manager"
      my-signal-handler))
 @end lisp
@@ -1565,17 +1750,147 @@ The callback function @code{my-dbus-signal-handler} must define one
 single string argument therefore.  Plugging an USB device to your
 machine, when registered for signal @samp{DeviceAdded}, will show you
 which objects the GNU/Linux @code{hal} daemon adds.
+
+Some of the match rules have been added to a later version of D-Bus.
+In order to test the availability of such features, you could register
+for a dummy signal, and check the result:
+
+@lisp
+(dbus-ignore-errors
+  (dbus-register-signal
+    :system nil nil nil nil 'ignore :path-namespace "/invalid/path"))
+
+@result{} nil
+@end lisp
+@end defun
+
+
+@node Alternative Buses
+@chapter Alternative buses and environments.
+@cindex bus names
+@cindex UNIX domain socket
+@cindex TCP/IP socket
+
+Until now, we have spoken about the system and the session buses,
+which are the default buses to be connected to.  However, it is
+possible to connect to any bus, from which the address is known.  This
+is a UNIX domain or TCP/IP socket.  Everywhere, where a @var{bus} is
+mentioned as argument of a function (the symbol @code{:system} or the
+symbol @code{:session}), this address can be used instead.  The
+connection to this bus must be initialized first.
+
+@defun dbus-init-bus bus &optional private
+Establish the connection to D-Bus @var{bus}.
+
+@var{bus} can be either the symbol @code{:system} or the symbol
+@code{:session}, or it can be a string denoting the address of the
+corresponding bus.  For the system and session buses, this function
+is called when loading @file{dbus.el}, there is no need to call it
+again.
+
+The function returns a number, which counts the connections this Emacs
+session has established to the @var{bus} under the same unique name
+(see @code{dbus-get-unique-name}).  It depends on the libraries Emacs
+is linked with, and on the environment Emacs is running.  For example,
+if Emacs is linked with the gtk toolkit, and it runs in a GTK-aware
+environment like Gnome, another connection might already be
+established.
+
+When @var{private} is non-@code{nil}, a new connection is established
+instead of reusing an existing one.  It results in a new unique name
+at the bus.  This can be used, if it is necessary to distinguish from
+another connection used in the same Emacs process, like the one
+established by GTK+.  It should be used with care for at least the
+@code{:system} and @code{:session} buses, because other Emacs Lisp
+packages might already use this connection to those buses.
+
+Example: You initialize a connection to the AT-SPI bus on your host:
+
+@lisp
+(setq my-bus
+  (dbus-call-method
+   :session "org.a11y.Bus" "/org/a11y/bus"
+   "org.a11y.Bus" "GetAddress"))
+
+@result{} "unix:abstract=/tmp/dbus-2yzWHOCdSD,guid=a490dd26625870ca1298b6e10000fd7f"
+
+;; If Emacs is built with gtk support, and you run in a GTK enabled
+;; environment (like a GNOME session), the initialization reuses the
+;; connection established by GTK's atk bindings.
+(dbus-init-bus my-bus)
+
+@result{} 2
+
+(dbus-get-unique-name my-bus)
+
+@result{} ":1.19"
+
+;; Open a new connection to the same bus.  This obsoletes the
+;; previous one.
+(dbus-init-bus my-bus 'private)
+
+@result{} 1
+
+(dbus-get-unique-name my-bus)
+
+@result{} ":1.20"
+@end lisp
+
+D-Bus addresses can specify different transport.  A possible address
+could be based on TCP/IP sockets, see next example.  However, it
+depends on the bus daemon configuration, which transport is supported.
+@end defun
+
+@defun dbus-setenv bus variable value
+Set the value of the @var{bus} environment variable @var{variable} to
+@var{value}.
+
+@var{bus} is either a Lisp symbol, @code{:system} or @code{:session},
+or a string denoting the bus address.  Both @var{variable} and
+@var{value} should be strings.
+
+Normally, services inherit the environment of the bus daemon.  This
+function adds to or modifies that environment when activating services.
+
+Some bus instances, such as @code{:system}, may disable setting the
+environment.  In such cases, or if this feature is not available in
+older D-Bus versions, a @code{dbus-error} error is raised.
+
+As an example, it might be desirable to start X11 enabled services on
+a remote host's bus on the same X11 server the local Emacs is
+running.  This could be achieved by
+
+@lisp
+(setq my-bus "unix:host=example.gnu.org,port=4711")
+
+@result{} "unix:host=example.gnu.org,port=4711"
+
+(dbus-init-bus my-bus)
+
+@result{} 1
+
+(dbus-setenv my-bus "DISPLAY" (getenv "DISPLAY"))
+
+@result{} nil
+@end lisp
 @end defun
 
 
 @node Errors and Events
 @chapter Errors and events.
+@cindex debugging
 @cindex errors
 @cindex events
 
+The internal actions can be traced by running in a debug mode.
+
+@defvar dbus-debug
+If this variable is non-@code{nil}, D-Bus specific debug messages are raised.
+@end defvar
+
 Input parameters of @code{dbus-call-method},
-@code{dbus-call-method-non-blocking},
-@code{dbus-call-method-asynchronously}, and
+@code{dbus-call-method-asynchronously}, @code{dbus-send-signal},
+@code{dbus-register-method}, @code{dbus-register-property} and
 @code{dbus-register-signal} are checked for correct D-Bus types. If
 there is a type mismatch, the Lisp error @code{wrong-type-argument}
 @code{D-Bus ARG} is raised.
@@ -1587,8 +1902,7 @@ appended to the @code{dbus-error}.
 @defspec dbus-ignore-errors forms@dots{}
 This executes @var{forms} exactly like a @code{progn}, except that
 @code{dbus-error} errors are ignored during the @var{forms}.  These
-errors can be made visible when variable @code{dbus-debug} is set to
-@code{t}.
+errors can be made visible when @code{dbus-debug} is set to @code{t}.
 @end defspec
 
 Incoming D-Bus messages are handled as Emacs events, see @pxref{Misc
@@ -1636,12 +1950,12 @@ The result is either the symbol @code{:system} or the symbol @code{:session}.
 
 @defun dbus-event-message-type event
 Returns the message type of the corresponding D-Bus message.  The
-result is a number.
+result is a natural number.
 @end defun
 
 @defun dbus-event-serial-number event
 Returns the serial number of the corresponding D-Bus message.
-The result is a number.
+The result is a natural number.
 @end defun
 
 @defun dbus-event-service-name event
@@ -1666,10 +1980,10 @@ usually not desired.  D-Bus errors in events can be made visible by
 setting the variable @code{dbus-debug} to @code{t}.  They can also be
 handled by a hook function.
 
-@defvar dbus-event-error-hooks
+@defvar dbus-event-error-functions
 This hook variable keeps a list of functions, which are called when a
 D-Bus error happens in the event handler.  Every function must accept
-two arguments, the event and the error variable catched in
+two arguments, the event and the error variable caught in
 @code{condition-case} by @code{dbus-error}.
 
 Such functions can be used the adapt the error signal to be raised.
@@ -1677,12 +1991,12 @@ Example:
 
 @lisp
 (defun my-dbus-event-error-handler (event error)
-  (when (string-equal (concat dbus-service-emacs ".FileManager")
+  (when (string-equal (concat dbus-interface-emacs ".FileManager")
                       (dbus-event-interface-name event))
     (message "my-dbus-event-error-handler: %S %S" event error)
     (signal 'file-error (cdr error))))
 
-(add-hook 'dbus-event-error-hooks 'my-dbus-event-error-handler)
+(add-hook 'dbus-event-error-functions 'my-dbus-event-error-handler)
 @end lisp
 @end defvar
 
@@ -1691,12 +2005,14 @@ D-Bus applications running.  Therefore, they shall check carefully,
 whether a given D-Bus error is related to them.
 
 
+@node Index
+@unnumbered Index
+
+@printindex cp
+
+
 @node GNU Free Documentation License
 @appendix GNU Free Documentation License
 @include doclicense.texi
 
 @bye
-
-@ignore
-   arch-tag: 2eeec19d-0caf-44e0-a193-329d7f9951d8
-@end ignore