[vtk-developers] Callbacks

Ken Martin ken.martin at kitware.com
Sun Jul 2 10:23:36 EDT 2000


At 09:56 PM 7/1/2000 +0100, John Biddiscombe wrote:
>Hi all,
>
>I'm in the process of implementing a vtkCallBackHandler class.
>So far all is well and its possible to define a Message ID and
>register a callback.
>CallBackHandler.RegisterCallBack(funcptr, args..., ID, etc);
>and
>CallBackHandlerPerformCallBack(this,ID);
>
>Problem is backwards compatibility, several types of callback
>exist
>void (*f)(void*)

I thought all of them were the above type. I can see how maybe one or two 
others have creeped in but I'm not sure I'd agree with them. Also, only the 
above type gets wrapped into Tcl, Python, Java. Not the ones below. Unless 
there is a good reason to keep the ones below I'd say to not support them. 
At the same time, I think the default callback mechanism should have the 
this pointer as a default argument. So instead of

callback(clientArg) use callback(clientArg, this)

I think that will simplify some callbacks if it works.

>void (*f)(void*, void*)
>void (*f)(void*...
>
>these are fine and handled by the class, but the ones I'm not
>happy about are
>StartMethodArgDelete
>EndMethodArgDelete
>etc etc
>the ArgDelete ones need the correct arg which is not available the
>way I've done it.
>
>Here is the arg supplied (OK)
>void SetLeftButtonPressMethod(void (*f)(void *), void *arg);
>
>Here the arg isn't available and I don't wat to scan the callbacks
>looking for the cortrect arg
>void SetLeftButtonPressMethodArgDelete(void (*f)(void *));
>
>
>I did a grep for various ArgDelete methods and can't find any
>references to them apart from their definitions...
>
>Does anyone use them?
>
>Can I get rid of the arg delete callbacks?
>SetLeftButtonPressArgDelete etc etc

You cannot get rid of the arg delete methods. They are there to provide a 
method for freeing the arg memory when the object deletes.  They are used 
heavily in the wrapper code and some in C++ applications.  You should be 
able to look up the method from the "this" pointer (which I would assume 
you pass to the callback handler) and the method ID StartMethod or 
EndMethod, shouldn't that be unique? If the issue is one of scanning the 
callbacks perhaps there is a different way to organize the delete methods ?

- Ken





More information about the vtk-developers mailing list