aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2007-12-04 21:21:09 +0000
committerMichael Albinus2007-12-04 21:21:09 +0000
commit5363d8eaa64bf0e7a8dc0dc960fd3cf9436dc5a9 (patch)
treea90a81a6b683007763eebec397f645069429e14c
parenta4397af9ae03da8dbb3efe23fd9e5c146ec5b98b (diff)
downloademacs-5363d8eaa64bf0e7a8dc0dc960fd3cf9436dc5a9.tar.gz
emacs-5363d8eaa64bf0e7a8dc0dc960fd3cf9436dc5a9.zip
* net/dbus.el (dbus-hash-table=): New defun.
(dbus-hash-table-test) New hash table test function, used in `dbus-registered-functions-table'. (dbus-*-event, dbus-event-*): Rewritten, due to new structure of `dbus-event'.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/net/dbus.el85
2 files changed, 70 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b7b82020aef..47cd9fed94c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12007-12-04 Michael Albinus <michael.albinus@gmx.de>
2
3 * net/dbus.el (dbus-hash-table=): New defun.
4 (dbus-hash-table-test) New hash table test function, used in
5 `dbus-registered-functions-table'.
6 (dbus-*-event, dbus-event-*): Rewritten, due to new structure of
7 `dbus-event'.
8
12007-12-04 Juanma Barranquero <lekktu@gmail.com> 92007-12-04 Juanma Barranquero <lekktu@gmail.com>
2 10
3 * ido.el (ido-save-history): Set the `coding' local 11 * ido.el (ido-save-history): Set the `coding' local
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el
index 91c10e786b3..9deddbc3e0f 100644
--- a/lisp/net/dbus.el
+++ b/lisp/net/dbus.el
@@ -46,36 +46,76 @@
46(defconst dbus-interface-introspectable "org.freedesktop.DBus.Introspectable" 46(defconst dbus-interface-introspectable "org.freedesktop.DBus.Introspectable"
47 "The interface supported by introspectable objects.") 47 "The interface supported by introspectable objects.")
48 48
49
50;;; Hash table of registered functions.
51
52(defun dbus-hash-table= (x y)
53 "Compares keys X and Y in the hash table of registered functions for D-Bus.
54See `dbus-registered-functions-table' for a description of the hash table."
55 (and
56 (listp x) (listp y)
57 ;; Bus symbol, either :system or :session.
58 (symbolp (car x)) (symbolp (car y)) (equal (car x) (car y))
59 ;; Interface.
60 (stringp (cadr x)) (stringp (cadr y)) (string-equal (cadr x) (cadr y))
61 ;; Member.
62 (stringp (caddr x)) (stringp (caddr y)) (string-equal (caddr x) (caddr y))))
63
64(define-hash-table-test 'dbus-hash-table-test
65 'dbus-hash-table= 'sxhash)
66
67(setq dbus-registered-functions-table
68 (make-hash-table :test 'dbus-hash-table-test))
69
70
71;;; D-Bus events.
72
49(defun dbus-check-event (event) 73(defun dbus-check-event (event)
50 "Checks whether EVENT is a well formed D-Bus event. 74 "Checks whether EVENT is a well formed D-Bus event.
51EVENT is a list which starts with symbol `dbus-event': 75EVENT is a list which starts with symbol `dbus-event':
52 76
53 (dbus-event SYMBOL SERVICE PATH &rest ARGS) 77 (dbus-event HANDLER BUS SERVICE PATH INTERFACE MEMBER &rest ARGS)
54 78
55SYMBOL is the interned Lisp symbol which has been generated 79HANDLER is the function which has been registered for this
56during signal registration. SERVICE and PATH are the unique name 80signal. BUS identifies the D-Bus the signal is coming from. It
57and the object path of the D-Bus object emitting the signal. 81is either the symbol `:system' or the symbol `:session'. SERVICE
58ARGS are the arguments passed to the corresponding handler. 82and PATH are the name and the object path of the D-Bus object
83emitting the signal. INTERFACE and MEMBER denote the signal
84which has been sent. ARGS are the arguments passed to HANDLER,
85when it is called during event handling in `dbus-handle-event'.
59 86
60This function raises a `dbus-error' signal in case the event is 87This function raises a `dbus-error' signal in case the event is
61not well formed." 88not well formed."
62 (when dbus-debug (message "DBus-Event %s" event)) 89 (when dbus-debug (message "DBus-Event %s" event))
63 (unless (and (listp event) 90 (unless (and (listp event)
64 (eq (car event) 'dbus-event) 91 (eq (car event) 'dbus-event)
65 (symbolp (cadr event)) 92 ;; Handler.
66 (stringp (car (cddr event))) 93 (functionp (nth 1 event))
67 (stringp (cadr (cddr event)))) 94 ;; Bus symbol.
95 (symbolp (nth 2 event))
96 ;; Service.
97 (stringp (nth 3 event))
98 ;; Object path.
99 (stringp (nth 4 event))
100 ;; Interface.
101 (stringp (nth 5 event))
102 ;; Member.
103 (stringp (nth 6 event)))
68 (signal 'dbus-error (list "Not a valid D-Bus event" event)))) 104 (signal 'dbus-error (list "Not a valid D-Bus event" event))))
69 105
70;;;###autoload 106;;;###autoload
71(defun dbus-handle-event (event) 107(defun dbus-handle-event (event)
72 "Handle events from the D-Bus. 108 "Handle events from the D-Bus.
73EVENT is a D-Bus event, see `dbus-check-event'. This function 109EVENT is a D-Bus event, see `dbus-check-event'. HANDLER, being
74raises a `dbus-error' signal in case the event is not well 110part of the event, is called with arguments ARGS."
75formed."
76 (interactive "e") 111 (interactive "e")
77 (dbus-check-event event) 112 ;; We don't want to raise an error, because this function is called
78 (when (functionp (cadr event)) (apply (cadr event) (cddr (cddr event))))) 113 ;; in the event handling loop.
114 (condition-case nil
115 (progn
116 (dbus-check-event event)
117 (apply (cadr event) (nthcdr 7 event)))
118 (dbus-error)))
79 119
80(defun dbus-event-bus-name (event) 120(defun dbus-event-bus-name (event)
81 "Return the bus name the event is coming from. 121 "Return the bus name the event is coming from.
@@ -84,16 +124,15 @@ EVENT is a D-Bus event, see `dbus-check-event'. This function
84raises a `dbus-error' signal in case the event is not well 124raises a `dbus-error' signal in case the event is not well
85formed." 125formed."
86 (dbus-check-event event) 126 (dbus-check-event event)
87 (save-match-data 127 (nth 2 event))
88 (intern (car (split-string (symbol-name (cadr event)) "\\.")))))
89 128
90(defun dbus-event-service-name (event) 129(defun dbus-event-service-name (event)
91 "Return the unique name of the D-Bus object the event is coming from. 130 "Return the name of the D-Bus object the event is coming from.
92The result is a string. EVENT is a D-Bus event, see `dbus-check-event'. 131The result is a string. EVENT is a D-Bus event, see `dbus-check-event'.
93This function raises a `dbus-error' signal in case the event is 132This function raises a `dbus-error' signal in case the event is
94not well formed." 133not well formed."
95 (dbus-check-event event) 134 (dbus-check-event event)
96 (car (cddr event))) 135 (nth 3 event))
97 136
98(defun dbus-event-path-name (event) 137(defun dbus-event-path-name (event)
99 "Return the object path of the D-Bus object the event is coming from. 138 "Return the object path of the D-Bus object the event is coming from.
@@ -101,7 +140,7 @@ The result is a string. EVENT is a D-Bus event, see `dbus-check-event'.
101This function raises a `dbus-error' signal in case the event is 140This function raises a `dbus-error' signal in case the event is
102not well formed." 141not well formed."
103 (dbus-check-event event) 142 (dbus-check-event event)
104 (cadr (cddr event))) 143 (nth 4 event))
105 144
106(defun dbus-event-interface-name (event) 145(defun dbus-event-interface-name (event)
107 "Return the interface name of the D-Bus object the event is coming from. 146 "Return the interface name of the D-Bus object the event is coming from.
@@ -109,9 +148,7 @@ The result is a string. EVENT is a D-Bus event, see `dbus-check-event'.
109This function raises a `dbus-error' signal in case the event is 148This function raises a `dbus-error' signal in case the event is
110not well formed." 149not well formed."
111 (dbus-check-event event) 150 (dbus-check-event event)
112 (save-match-data 151 (nth 5 event))
113 (string-match "^[^.]+\\.\\(.+\\)\\.[^.]+$" (symbol-name (cadr event)))
114 (match-string 1 (symbol-name (cadr event)))))
115 152
116(defun dbus-event-member-name (event) 153(defun dbus-event-member-name (event)
117 "Return the member name the event is coming from. 154 "Return the member name the event is coming from.
@@ -120,8 +157,10 @@ string. EVENT is a D-Bus event, see `dbus-check-event'. This
120function raises a `dbus-error' signal in case the event is not 157function raises a `dbus-error' signal in case the event is not
121well formed." 158well formed."
122 (dbus-check-event event) 159 (dbus-check-event event)
123 (save-match-data 160 (nth 6 event))
124 (car (nreverse (split-string (symbol-name (cadr event)) "\\."))))) 161
162
163;;; D-Bus registered names.
125 164
126(defun dbus-list-activatable-names () 165(defun dbus-list-activatable-names ()
127 "Return the D-Bus service names which can be activated as list. 166 "Return the D-Bus service names which can be activated as list.