unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Mario Lang <mlang@delysid.org>
To: emacs-devel@gnu.org
Cc: Michael Albinus <michael.albinus@gmx.de>
Subject: dbus.el: defvar dbus-event for signal handlers?
Date: Sun, 09 Aug 2009 15:46:42 +0200	[thread overview]
Message-ID: <87tz0hp0al.fsf@x2.delysid.org> (raw)

[-- 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 --]

             reply	other threads:[~2009-08-09 13:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-09 13:46 Mario Lang [this message]
2009-08-09 14:36 ` dbus.el: defvar dbus-event for signal handlers? Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tz0hp0al.fsf@x2.delysid.org \
    --to=mlang@delysid.org \
    --cc=emacs-devel@gnu.org \
    --cc=michael.albinus@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).