changeset 87176:d5feab53f4f8

* net/dbus.el (dbus-hash-table=): Remove function. We cannot apply wildcards in a hash table key; there is no usable hash code then. (dbus-registered-functions-table): Use `equal' as test function. (dbus-name-owner-changed-handler): Rewrite due to new hash table structure.
author Michael Albinus <michael.albinus@gmx.de>
date Sat, 08 Dec 2007 12:56:59 +0000
parents 30175fd3b679
children e0020f0f90e3
files lisp/ChangeLog lisp/net/dbus.el
diffstat 2 files changed, 33 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Dec 08 12:53:37 2007 +0000
+++ b/lisp/ChangeLog	Sat Dec 08 12:56:59 2007 +0000
@@ -1,3 +1,12 @@
+2007-12-08  Michael Albinus  <michael.albinus@gmx.de>
+
+	* net/dbus.el (dbus-hash-table=): Remove function.  We cannot
+	apply wildcards in a hash table key; there is no usable hash code
+	then.
+	(dbus-registered-functions-table): Use `equal' as test function.
+	(dbus-name-owner-changed-handler): Rewrite due to new hash table
+	structure.
+
 2007-12-08  Martin Rudalics  <rudalics@gmx.at>
 
 	* progmodes/cc-cmds.el (c-mask-paragraph): Avoid invalid search
--- a/lisp/net/dbus.el	Sat Dec 08 12:53:37 2007 +0000
+++ b/lisp/net/dbus.el	Sat Dec 08 12:56:59 2007 +0000
@@ -49,36 +49,9 @@
 
 ;;; Hash table of registered functions.
 
-(defun dbus-hash-table= (x y)
-  "Compares keys X and Y in the hash table of registered functions for D-Bus.
-See `dbus-registered-functions-table' for a description of the hash table."
-  (and
-   ;; Bus symbol, either :system or :session.
-   (equal (car x) (car y))
-   ;; Service.
-   (or
-    (null (nth 1 x)) (null (nth 1 y)) ; wildcard
-    (string-equal (nth 1 x) (nth 1 y)))
-   ;; Path.
-   (or
-    (null (nth 2 x)) (null (nth 2 y)) ; wildcard
-    (string-equal (nth 2 x) (nth 2 y)))
-   ;; Member.
-   (or
-    (null (nth 3 x)) (null (nth 3 y)) ; wildcard
-    (string-equal (nth 3 x) (nth 3 y)))
-   ;; Interface.
-   (or
-    (null (nth 4 x)) (null (nth 4 y)) ; wildcard
-    (string-equal (nth 4 x) (nth 4 y)))))
-
-(define-hash-table-test 'dbus-hash-table-test 'dbus-hash-table= 'sxhash)
-
-;; When we assume that service, path, interface and and member are
-;; always strings in the key, we could use `equal' as test function.
-;; But we want to have also `nil' there, being a wildcard.
-(setq dbus-registered-functions-table
-      (make-hash-table :test 'dbus-hash-table-test))
+;; We create it here.  So we have a simple test in dbusbind.c, whether
+;; the Lisp code has been loaded.
+(setq dbus-registered-functions-table (make-hash-table :test 'equal))
 
 (defun dbus-list-hash-table ()
   "Returns all registered signal registrations to D-Bus.
@@ -99,24 +72,29 @@
 empty string if SERVICE was not owned yet.  NEW-OWNER is the new
 owner of SERVICE, or the empty string if SERVICE looses any name owner."
   (save-match-data
-    ;; Check whether SERVICE is a known name, and OLD-OWNER and
-    ;; NEW-OWNER are defined.
+    ;; Check whether SERVICE is a known name.
     (when (and (stringp service) (not (string-match "^:" service))
-	       (not (zerop (length old-owner)))
-	       (not (zerop (length new-owner))))
-      (let ((bus (dbus-event-bus-name last-input-event)))
-	(maphash
-	 '(lambda (key value)
-	    ;; Check for matching bus and service name.
-	    (when (and (equal bus (car key))
-		       (string-equal old-owner (nth 1 key)))
+	       (stringp old-owner) (stringp new-owner))
+      (maphash
+       '(lambda (key value)
+	  (dolist (elt value)
+	    ;; key has the structure (BUS INTERFACE SIGNAL).
+	    ;; elt has the structure (SERVICE UNAME PATH HANDLER).
+	    (when (string-equal old-owner (cadr elt))
 	      ;; Remove old key, and add new entry with changed name.
-	      (when dbus-debug (message "Remove rule for %s" key))
-	      (dbus-unregister-signal key)
-	      (setcar (nthcdr 1 key) new-owner)
-	      (when dbus-debug (message "Add rule for %s" key))
-	      (apply 'dbus-register-signal (append key (list value)))))
-	 (copy-hash-table dbus-registered-functions-table))))))
+	      (when dbus-debug (message "Remove rule for %s %s" key elt))
+	      ;(dbus-unregister-signal key)
+	      (setcar (cdr elt) new-owner)
+	      (when dbus-debug (message "Add rule for %s %s" key elt))
+	      ;; Maybe we could arrange the lists a little bit better
+	      ;; that we don't need to extract every single element?
+	      (when (not (zerop (length new-owner)))
+		(dbus-register-signal
+		 ;; BUS      SERVICE     PATH
+		 (nth 0 key) (nth 0 elt) (nth 2 elt)
+		 ;; INTERFACE SIGNAL     HANDLER
+		 (nth 1 key) (nth 2 key) (nth 3 elt))))))
+       (copy-hash-table dbus-registered-functions-table)))))
 
 ;; Register the handler.
 (condition-case nil