Merge from emacs-23; up to 2010-06-12T08:59:37Z!albinus@detlef.
[bpt/emacs.git] / lisp / net / dbus.el
index 9f6cbda..87af3d1 100644 (file)
@@ -1,6 +1,6 @@
 ;;; dbus.el --- Elisp bindings for D-Bus.
 
-;; Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 2007-2011 Free Software Foundation, Inc.
 
 ;; Author: Michael Albinus <michael.albinus@gmx.de>
 ;; Keywords: comm, hardware
@@ -121,7 +121,7 @@ See `dbus-registered-objects-table' for a description of the
 hash table."
   (let (result)
     (maphash
-     '(lambda (key value) (add-to-list 'result (cons key value) 'append))
+     (lambda (key value) (add-to-list 'result (cons key value) 'append))
      dbus-registered-objects-table)
     result))
 
@@ -183,7 +183,18 @@ association to the service from D-Bus."
 (defun dbus-unregister-service (bus service)
   "Unregister all objects related to SERVICE from D-Bus BUS.
 BUS is either a Lisp symbol, `:system' or `:session', or a string
-denoting the bus address.  SERVICE must be a known service name."
+denoting the bus address.  SERVICE must be a known service name.
+
+The function returns a keyword, indicating the result of the
+operation.  One of the following keywords is returned:
+
+`:released': Service has become the primary owner of the name.
+
+`:non-existent': Service name does not exist on this bus.
+
+`:not-owner': We are neither the primary owner nor waiting in the
+queue of this service."
+
   (maphash
    (lambda (key value)
      (dolist (elt value)
@@ -200,7 +211,7 @@ denoting the bus address.  SERVICE must be a known service name."
       (1 :released)
       (2 :non-existent)
       (3 :not-owner)
-      (t (signal 'dbus-error "Could not unregister service")))))
+      (t (signal 'dbus-error (list "Could not unregister service" service))))))
 
 (defun dbus-call-method-non-blocking-handler (&rest args)
   "Handler for reply messages of asynchronous D-Bus message calls.
@@ -260,20 +271,20 @@ usage: (dbus-name-owner-changed-handler service old-owner new-owner)"
          ;; Check whether SERVICE is a known name.
          (when (not (string-match "^:" service))
            (maphash
-            '(lambda (key value)
-               (dolist (elt value)
-                 ;; key has the structure (BUS INTERFACE MEMBER).
-                 ;; elt has the structure (UNAME SERVICE PATH HANDLER).
-                 (when (string-equal old-owner (car elt))
-                   ;; Remove old key, and add new entry with changed name.
-                   (dbus-unregister-object (list key (cdr elt)))
-                   ;; Maybe we could arrange the lists a little bit better
-                   ;; that we don't need to extract every single element?
-                   (dbus-register-signal
-                    ;; BUS      SERVICE     PATH
-                    (nth 0 key) (nth 1 elt) (nth 2 elt)
-                    ;; INTERFACE MEMBER     HANDLER
-                    (nth 1 key) (nth 2 key) (nth 3 elt)))))
+            (lambda (key value)
+               (dolist (elt value)
+                 ;; key has the structure (BUS INTERFACE MEMBER).
+                 ;; elt has the structure (UNAME SERVICE PATH HANDLER).
+                 (when (string-equal old-owner (car elt))
+                   ;; Remove old key, and add new entry with changed name.
+                   (dbus-unregister-object (list key (cdr elt)))
+                   ;; Maybe we could arrange the lists a little bit better
+                   ;; that we don't need to extract every single element?
+                   (dbus-register-signal
+                    ;; BUS      SERVICE     PATH
+                    (nth 0 key) (nth 1 elt) (nth 2 elt)
+                    ;; INTERFACE MEMBER     HANDLER
+                    (nth 1 key) (nth 2 key) (nth 3 elt)))))
             (copy-hash-table dbus-registered-objects-table))))
       ;; The error is reported only in debug mode.
       (when  dbus-debug
@@ -495,13 +506,14 @@ well formed."
 \f
 ;;; D-Bus registered names.
 
-(defun dbus-list-activatable-names ()
+(defun dbus-list-activatable-names (&optional bus)
   "Return the D-Bus service names which can be activated as list.
-The result is a list of strings, which is `nil' when there are no
-activatable service names at all."
+If BUS is left nil, `:system' is assumed.  The result is a list
+of strings, which is `nil' when there are no activatable service
+names at all."
   (dbus-ignore-errors
     (dbus-call-method
-     :system dbus-service-dbus
+     (or bus :system) dbus-service-dbus
      dbus-path-dbus dbus-interface-dbus "ListActivatableNames")))
 
 (defun dbus-list-names (bus)
@@ -813,15 +825,15 @@ be \"out\"."
       (setq direction nil))
     ;; Collect the signatures.
     (mapconcat
-     '(lambda (x)
-       (let ((arg (dbus-introspect-get-argument
-                   bus service path interface name x)))
-         (if (or (not (stringp direction))
-                 (string-equal
-                  direction
-                  (dbus-introspect-get-attribute arg "direction")))
-             (dbus-introspect-get-attribute arg "type")
-           "")))
+     (lambda (x)
+       (let ((arg (dbus-introspect-get-argument
+                   bus service path interface name x)))
+         (if (or (not (stringp direction))
+                 (string-equal
+                  direction
+                  (dbus-introspect-get-attribute arg "direction")))
+             (dbus-introspect-get-attribute arg "type")
+           "")))
      (dbus-introspect-get-argument-names bus service path interface name)
      "")))
 
@@ -922,13 +934,13 @@ clients from discovering the still incomplete interface."
   ;; Add handlers for the three property-related methods.
   (dbus-register-method
    bus service path dbus-interface-properties "Get"
-   'dbus-property-handler t)
+   'dbus-property-handler 'dont-register)
   (dbus-register-method
-   bus service path dbus-interface-properties "GetAll" 
-   'dbus-property-handler t)
+   bus service path dbus-interface-properties "GetAll"
+   'dbus-property-handler 'dont-register)
   (dbus-register-method
-   bus service path dbus-interface-properties "Set" 
-   'dbus-property-handler t)
+   bus service path dbus-interface-properties "Set"
+   'dbus-property-handler 'dont-register)
 
   ;; Register the name SERVICE with BUS.
   (unless dont-register-service