Lisp HUG Maillist Archive

Unplanned need to find the interface that called a callback

I have a large interactive application and I've started adding
some progress bars when time-consuming operations are performed.
The progress bars are displayed in fresh interfaces containing
nothing but the progress bar and some text saying what is happening.
I want the progress bars to have as their owner the interface
from which the user initiated the current action.

My issue is how to find the interface that initiated the
current action. I could re-visit all the callbacks and modify
them to take an interface as argument, but that would be a lot
of fiddly work. 

Instead, I've looked at stack backtraces in the debugger to
see what happens before a callback is called and I've come up
with the following solution of adding advice in a couple of
places:

___________________________________________________________

(defvar *callback-interface* nil) ; NIL in case I haven't
                                  ; caught all places
                                  ; where callbacks are called

;; menu-item and button callbacks are called within a call
;; of CAPI:EXECUTE-WITH-INTERFACE
(lw:defadvice (capi:execute-with-interface
               bind-*callback-interface*
               :around)
    (interface &rest other-args)
  (let* ((*callback-interface* interface))
    (apply #'lw:call-next-advice interface other-args)))

;; confirm-destroy-callbacks are called within a call
;; of CAPI::EXECUTE-WITH-INTERFACE-INTERNAL
(lw:defadvice (capi::execute-with-interface-internal
               bind-*callback-interface*
               :around)
    (interface &rest other-args)
  (let* ((*callback-interface* interface))
    (apply #'lw:call-next-advice interface other-args)))
___________________________________________________________


This seems to work fine.

My questions are:

Is there a better way to approach this?
Would it be a useful addition for the CAPI to provide such a
variable?

Simon



Re: Unplanned need to find the interface that called a callback

Simon Katz wrote:

> 
> This seems to work fine.
> 
> My questions are:
> 
> Is there a better way to approach this?
> Would it be a useful addition for the CAPI to provide such a
> variable?
> 

Even though it might be fiddly I would suggest you add an interface
arg to the progress bar callbacks.  I think that it is the _right_
thing to do.  Using CAPI implementation internals is not a good idea.

Wade



Updated at: 2020-12-10 08:54 UTC