aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/net/dbus.el67
-rw-r--r--test/lisp/net/dbus-tests.el75
2 files changed, 98 insertions, 44 deletions
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el
index fddd6df963b..d4e6cb943df 100644
--- a/lisp/net/dbus.el
+++ b/lisp/net/dbus.el
@@ -178,6 +178,9 @@ See /usr/include/dbus-1.0/dbus/dbus-protocol.h.")
178(defconst dbus-error-invalid-args (concat dbus-error-dbus ".InvalidArgs") 178(defconst dbus-error-invalid-args (concat dbus-error-dbus ".InvalidArgs")
179 "Invalid arguments passed to a method call.") 179 "Invalid arguments passed to a method call.")
180 180
181(defconst dbus-error-no-reply (concat dbus-error-dbus ".NoReply")
182 "No reply to a message expecting one, usually means a timeout occurred.")
183
181(defconst dbus-error-property-read-only 184(defconst dbus-error-property-read-only
182 (concat dbus-error-dbus ".PropertyReadOnly") 185 (concat dbus-error-dbus ".PropertyReadOnly")
183 "Property you tried to set is read-only.") 186 "Property you tried to set is read-only.")
@@ -369,23 +372,24 @@ object is returned instead of a list containing this single Lisp object.
369 372
370 (puthash key result dbus-return-values-table) 373 (puthash key result dbus-return-values-table)
371 (unwind-protect 374 (unwind-protect
372 (progn 375 (progn
373 (with-timeout ((if timeout (/ timeout 1000.0) 25) 376 (with-timeout
374 (signal 'dbus-error (list "call timed out"))) 377 ((if timeout (/ timeout 1000.0) 25)
375 (while (eq (car result) :pending) 378 (signal 'dbus-error `(,dbus-error-no-reply "Call timed out")))
376 (let ((event (let ((inhibit-redisplay t) unread-command-events) 379 (while (eq (car result) :pending)
377 (read-event nil nil check-interval)))) 380 (let ((event (let ((inhibit-redisplay t) unread-command-events)
378 (when event 381 (read-event nil nil check-interval))))
379 (if (ignore-errors (dbus-check-event event)) 382 (when event
380 (setf result (gethash key dbus-return-values-table)) 383 (if (ignore-errors (dbus-check-event event))
381 (setf unread-command-events 384 (setf result (gethash key dbus-return-values-table))
382 (nconc unread-command-events 385 (setf unread-command-events
383 (cons event nil))))) 386 (nconc unread-command-events
384 (when (< check-interval 1) 387 (cons event nil)))))
385 (setf check-interval (* check-interval 1.05)))))) 388 (when (< check-interval 1)
386 (when (eq (car result) :error) 389 (setf check-interval (* check-interval 1.05))))))
387 (signal (cadr result) (cddr result))) 390 (when (eq (car result) :error)
388 (cdr result)) 391 (signal (cadr result) (cddr result)))
392 (cdr result))
389 (remhash key dbus-return-values-table)))) 393 (remhash key dbus-return-values-table))))
390 394
391(defun dbus-call-method-asynchronously 395(defun dbus-call-method-asynchronously
@@ -430,7 +434,7 @@ Example:
430 434
431\(dbus-call-method-asynchronously 435\(dbus-call-method-asynchronously
432 :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/devices/computer\" 436 :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/devices/computer\"
433 \"org.freedesktop.Hal.Device\" \"GetPropertyString\" \\='message 437 \"org.freedesktop.Hal.Device\" \"GetPropertyString\" #\\='message
434 \"system.kernel.machine\") 438 \"system.kernel.machine\")
435 439
436 -| i686 440 -| i686
@@ -710,7 +714,7 @@ Example:
710 714
711\(dbus-register-signal 715\(dbus-register-signal
712 :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\" 716 :system \"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\"
713 \"org.freedesktop.Hal.Manager\" \"DeviceAdded\" \\='my-signal-handler) 717 \"org.freedesktop.Hal.Manager\" \"DeviceAdded\" #\\='my-signal-handler)
714 718
715 => ((:signal :system \"org.freedesktop.Hal.Manager\" \"DeviceAdded\") 719 => ((:signal :system \"org.freedesktop.Hal.Manager\" \"DeviceAdded\")
716 (\"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\" my-signal-handler)) 720 (\"org.freedesktop.Hal\" \"/org/freedesktop/Hal/Manager\" my-signal-handler))
@@ -922,16 +926,19 @@ association to the service from D-Bus."
922 (progn 926 (progn
923 (maphash 927 (maphash
924 (lambda (k v) 928 (lambda (k v)
925 (dolist (e v) 929 (when (consp v)
926 (ignore-errors 930 (dolist (e v)
927 (and 931 (ignore-errors
928 ;; Bus. 932 (and
929 (equal bus (cadr k)) 933 ;; Type.
930 ;; Service. 934 (eq type (car k))
931 (string-equal service (cadr e)) 935 ;; Bus.
932 ;; Non-empty object path. 936 (equal bus (cadr k))
933 (nth 2 e) 937 ;; Service.
934 (throw :found t))))) 938 (string-equal service (cadr e))
939 ;; Non-empty object path.
940 (nth 2 e)
941 (throw :found t))))))
935 dbus-registered-objects-table) 942 dbus-registered-objects-table)
936 nil)))) 943 nil))))
937 (dbus-unregister-service bus service)) 944 (dbus-unregister-service bus service))
@@ -1934,6 +1941,8 @@ this connection to those buses."
1934;; * Implement org.freedesktop.DBus.ObjectManager.InterfacesAdded and 1941;; * Implement org.freedesktop.DBus.ObjectManager.InterfacesAdded and
1935;; org.freedesktop.DBus.ObjectManager.InterfacesRemoved. 1942;; org.freedesktop.DBus.ObjectManager.InterfacesRemoved.
1936;; 1943;;
1944;; * Implement org.freedesktop.DBus.Monitoring.BecomeMonitor.
1945;;
1937;; * Cache introspection data. 1946;; * Cache introspection data.
1938;; 1947;;
1939;; * Run handlers in own threads. 1948;; * Run handlers in own threads.
diff --git a/test/lisp/net/dbus-tests.el b/test/lisp/net/dbus-tests.el
index 73401a8c921..d470bca226a 100644
--- a/test/lisp/net/dbus-tests.el
+++ b/test/lisp/net/dbus-tests.el
@@ -214,28 +214,39 @@ This includes initialization and closing the bus."
214 (dbus-ignore-errors (dbus-unregister-service :session dbus--test-service)) 214 (dbus-ignore-errors (dbus-unregister-service :session dbus--test-service))
215 215
216 (unwind-protect 216 (unwind-protect
217 (let ((method "Method") 217 (let ((method1 "Method1")
218 (handler #'dbus--test-method-handler)) 218 (method2 "Method2")
219 (handler #'dbus--test-method-handler)
220 registered)
219 221
220 (should 222 (should
221 (equal 223 (equal
224 (setq
225 registered
226 (dbus-register-method
227 :session dbus--test-service dbus--test-path
228 dbus--test-interface method1 handler))
229 `((:method :session ,dbus--test-interface ,method1)
230 (,dbus--test-service ,dbus--test-path ,handler))))
231 (should
232 (equal
222 (dbus-register-method 233 (dbus-register-method
223 :session dbus--test-service dbus--test-path 234 :session dbus--test-service dbus--test-path
224 dbus--test-interface method handler) 235 dbus--test-interface method2 handler)
225 `((:method :session ,dbus--test-interface ,method) 236 `((:method :session ,dbus--test-interface ,method2)
226 (,dbus--test-service ,dbus--test-path ,handler)))) 237 (,dbus--test-service ,dbus--test-path ,handler))))
227 238
228 ;; No argument, returns nil. 239 ;; No argument, returns nil.
229 (should-not 240 (should-not
230 (dbus-call-method 241 (dbus-call-method
231 :session dbus--test-service dbus--test-path 242 :session dbus--test-service dbus--test-path
232 dbus--test-interface method)) 243 dbus--test-interface method1))
233 ;; One argument, returns the argument. 244 ;; One argument, returns the argument.
234 (should 245 (should
235 (string-equal 246 (string-equal
236 (dbus-call-method 247 (dbus-call-method
237 :session dbus--test-service dbus--test-path 248 :session dbus--test-service dbus--test-path
238 dbus--test-interface method "foo") 249 dbus--test-interface method1 "foo")
239 "foo")) 250 "foo"))
240 ;; Two arguments, D-Bus error activated as `(:error ...)' list. 251 ;; Two arguments, D-Bus error activated as `(:error ...)' list.
241 (should 252 (should
@@ -243,7 +254,7 @@ This includes initialization and closing the bus."
243 (should-error 254 (should-error
244 (dbus-call-method 255 (dbus-call-method
245 :session dbus--test-service dbus--test-path 256 :session dbus--test-service dbus--test-path
246 dbus--test-interface method "foo" "bar")) 257 dbus--test-interface method1 "foo" "bar"))
247 `(dbus-error ,dbus-error-invalid-args "Wrong arguments (foo bar)"))) 258 `(dbus-error ,dbus-error-invalid-args "Wrong arguments (foo bar)")))
248 ;; Three arguments, D-Bus error activated by `dbus-error' signal. 259 ;; Three arguments, D-Bus error activated by `dbus-error' signal.
249 (should 260 (should
@@ -251,15 +262,28 @@ This includes initialization and closing the bus."
251 (should-error 262 (should-error
252 (dbus-call-method 263 (dbus-call-method
253 :session dbus--test-service dbus--test-path 264 :session dbus--test-service dbus--test-path
254 dbus--test-interface method "foo" "bar" "baz")) 265 dbus--test-interface method1 "foo" "bar" "baz"))
255 `(dbus-error 266 `(dbus-error
256 ,dbus-error-failed 267 ,dbus-error-failed
257 "D-Bus error: \"D-Bus signal\", \"foo\", \"bar\", \"baz\"")))) 268 "D-Bus error: \"D-Bus signal\", \"foo\", \"bar\", \"baz\"")))
269
270 ;; Unregister method.
271 (should (dbus-unregister-object registered))
272 (should-not (dbus-unregister-object registered))
273 (should
274 (equal
275 ;; We don't care the error message text.
276 (butlast
277 (should-error
278 (dbus-call-method
279 :session dbus--test-service dbus--test-path
280 dbus--test-interface method1 :timeout 10 "foo")))
281 `(dbus-error ,dbus-error-no-reply))))
258 282
259 ;; Cleanup. 283 ;; Cleanup.
260 (dbus-unregister-service :session dbus--test-service))) 284 (dbus-unregister-service :session dbus--test-service)))
261 285
262;; TODO: Test emits-signal, unregister. 286;; TODO: Test emits-signal.
263(ert-deftest dbus-test05-register-property () 287(ert-deftest dbus-test05-register-property ()
264 "Check property registration for an own service." 288 "Check property registration for an own service."
265 (skip-unless dbus--test-enabled-session-bus) 289 (skip-unless dbus--test-enabled-session-bus)
@@ -269,14 +293,17 @@ This includes initialization and closing the bus."
269 (let ((property1 "Property1") 293 (let ((property1 "Property1")
270 (property2 "Property2") 294 (property2 "Property2")
271 (property3 "Property3") 295 (property3 "Property3")
272 (property4 "Property4")) 296 (property4 "Property4")
297 registered)
273 298
274 ;; `:read' property. 299 ;; `:read' property.
275 (should 300 (should
276 (equal 301 (equal
277 (dbus-register-property 302 (setq
278 :session dbus--test-service dbus--test-path 303 registered
279 dbus--test-interface property1 :read "foo") 304 (dbus-register-property
305 :session dbus--test-service dbus--test-path
306 dbus--test-interface property1 :read "foo"))
280 `((:property :session ,dbus--test-interface ,property1) 307 `((:property :session ,dbus--test-interface ,property1)
281 (,dbus--test-service ,dbus--test-path)))) 308 (,dbus--test-service ,dbus--test-path))))
282 (should 309 (should
@@ -419,7 +446,25 @@ This includes initialization and closing the bus."
419 (should (setq result (cadr (assoc dbus--test-interface result)))) 446 (should (setq result (cadr (assoc dbus--test-interface result))))
420 (should (string-equal (cdr (assoc property1 result)) "foo")) 447 (should (string-equal (cdr (assoc property1 result)) "foo"))
421 (should (string-equal (cdr (assoc property3 result)) "/baz/baz")) 448 (should (string-equal (cdr (assoc property3 result)) "/baz/baz"))
422 (should-not (assoc property2 result)))) 449 (should-not (assoc property2 result)))
450
451 ;; Unregister property.
452 (should (dbus-unregister-object registered))
453 (should-not (dbus-unregister-object registered))
454 (should-not
455 (dbus-get-property
456 :session dbus--test-service dbus--test-path
457 dbus--test-interface property1))
458 (let ((dbus-show-dbus-errors t))
459 (should
460 (equal
461 ;; We don't care the error message text.
462 (butlast
463 (should-error
464 (dbus-get-property
465 :session dbus--test-service dbus--test-path
466 dbus--test-interface property1)))
467 `(dbus-error ,dbus-error-unknown-property)))))
423 468
424 ;; Cleanup. 469 ;; Cleanup.
425 (dbus-unregister-service :session dbus--test-service))) 470 (dbus-unregister-service :session dbus--test-service)))