;;; 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
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))
(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)
(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.
;; 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
\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)
(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)
"")))
;; 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