emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dbus.el: defvar dbus-event for signal handlers?


From: Mario Lang
Subject: dbus.el: defvar dbus-event for signal handlers?
Date: Sun, 09 Aug 2009 15:46:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Hi.

First of all, thanks for dbus.el.  I am writing atspi.el which
is heavily based on dbus.el.  I noticed a rough bit in the API which I'd
like to discuss to see what your opinions are.

`dbus-register-signal' allows for SERVICE and PATH to be nil, which is
something I need for a group of signals I need to handle.  However, to be
able to run `dbus-event-service-name' and `dbus-event-path-name' to
figure out what SERVICE and PATH actually are during handler execution I
somehow need to get to the actual event object when my signal handler is run.
Given how elisp works, there is a way to access the event object by just
using EVENT, for example:

(defun handler ()
  (message "Event on service %s path %s" (dbus-event-service-name event)
                                         (dbus-event-path-name event)))

which of course looks odd and at least upsets elint:

** function atspi-tree-remove-accessible-handler **
Reference to unbound symbol: event

Now I guess one solution is something like the following patch:

--- a/lisp/net/dbus.el
+++ b/lisp/net/dbus.el
@@ -349,11 +349,15 @@ not well formed."
               (functionp (nth 8 event)))
     (signal 'dbus-error (list "Not a valid D-Bus event" event))))
 
+(defvar dbus-event nil
+  "Set by `dbus-handle-event' during handler execution.")
+
 ;;;###autoload
 (defun dbus-handle-event (event)
   "Handle events from the D-Bus.
 EVENT is a D-Bus event, see `dbus-check-event'.  HANDLER, being
 part of the event, is called with arguments ARGS.
+During executing of HANDLER, EVENT is bound to `dbus-event'.
 If the HANDLER returns an `dbus-error', it is propagated as return message."
   (interactive "e")
   (condition-case err
@@ -364,7 +368,8 @@ If the HANDLER returns an `dbus-error', it is propagated as 
return message."
        (when (= dbus-message-type-error (nth 2 event))
          (signal 'dbus-error (nthcdr 9 event)))
        ;; Apply the handler.
-       (setq result (apply (nth 8 event) (nthcdr 9 event)))
+       (let ((dbus-event event))
+         (setq result (apply (nth 8 event) (nthcdr 9 event))))
        ;; Return a message when it is a message call.
        (when (= dbus-message-type-method-call (nth 2 event))
          (dbus-ignore-errors


Which would mean the above example shoudl be rewritten as:

(defun handler ()
  (message "Event on service %s path %s" (dbus-event-service-name dbus-event)
                                         (dbus-event-path-name dbus-event)))


Another solution would be to pass EVENT as the first argument to HANDLER,
but this would need changing of all existing handler functions, which is
probably no good idea at all.

Any thoughts?
-- 
Thanks,
  ⡍⠁⠗⠊⠕

Attachment: pgpU7SjcnVGJ4.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]