all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* dbus.el: defvar dbus-event for signal handlers?
@ 2009-08-09 13:46 Mario Lang
  2009-08-09 14:36 ` Michael Albinus
  0 siblings, 1 reply; 2+ messages in thread
From: Mario Lang @ 2009-08-09 13:46 UTC (permalink / raw)
  To: emacs-devel; +Cc: Michael Albinus

[-- Attachment #1: Type: text/plain, Size: 2697 bytes --]

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 #2: Type: application/pgp-signature, Size: 188 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-08-09 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-09 13:46 dbus.el: defvar dbus-event for signal handlers? Mario Lang
2009-08-09 14:36 ` Michael Albinus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.