[vtk-developers] Callbacks
John Biddiscombe
j.biddiscombe at rl.ac.uk
Sun Jul 2 17:52:40 EDT 2000
> You cannot get rid of the arg delete methods. They are there to
provide a
Ok.
> 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?
^^^^^^^^^^^^^^^^^^^^^^^^^
Yes (well, sort of anyway see *** below)
>If the issue is one of scanning the
> callbacks perhaps there is a different way to organize the
delete methods ?
I'll explain what I'm trying to do in order to illustrate...
I've added the ability to insert
this->CallBackHandler.PerformCallback(this,
VTK_MSG_ASYNCHRONOUS_UPDATE, 0, 0);
this->CallBackHandler.PerformCallback(this, VTK_MSG_SETOUTPUT, 0,
0);
this->CallBackHandler.PerformCallback(this,
VTK_MSG_PROGRESS_START, 0, 0);
this->CallBackHandler.PerformCallback(this,
VTK_MSG_PROGRESS_UPDATE, 0, 0.63);
messages anywhere you like. And you can define a new message
identifier in
vtkCallBackMessageIds.h
So people like me who want to hook into the update mechanism (for
whatever reason), can insert messages at suitable places.
If you
object->RegisterCallBackHandler(functionaddress, UserArg,
MessageID)
then one of several things will happen
1) If the MessageID==VTK_MSG_ALL, then all messages will be sent
to the callback function and you can put a handler which does
switch (message)
case VTK_MSG_PROGRESS_START
case VTK_MSG_LEFT_BUTTON_PRESS
etc etc.
The callback is of type
void (*f)(vtkObject *this, void *userarg, int iParam, float
fParam)
which allows for future expansion should one want to send more
information
2) If the messageId is VTK_MSG_LEFTBUTTONPRESS (or something other
than ALL), then the callback is only called if the message is of
the correct type.
Here's an example
The function
void vtkProcessObject::SetStartMethod( void (*f)(void *), void
*UserArg)
will do this
callbackhandler->RegisterCallBackHandler(f, UserArg,
VTK_MSG_PROGRESS_START)
and the old code
if (this->StartMethod) {
this->StartMethod(this->StartMethodArg)
}
is replaced by
this->CallBackHandler.PerformCallback(this,
VTK_MSG_PROGRESS_START, 0, 0);
The callbackhandler loops over all the registered callbacks and
calls them if they are VTK_MSG_ALL, or if they are
VTK_MSG_PROGRESS_START (and likewise for other messages) and calls
the correct function type depending upon how they were registered.
---
Note that the callback handler has several overloaded register
functions to allow different types of callback function to be
accomodated and it stores a flag with each to know what type of
call to make when dispatching. (this is done for compatibility)
---
The idea is to add in all the new callbacks we want, without
disturbing any existing code. After its all in place, it is
relatively easy to replace a callback in the 'old' style with a
newer or better version in the new style.
ie
void vtkProcessObject::SetStartMethod( void (*f)(void *), void
*UserArg)
can be replaced with a function taking a this pointer, float etc
etc. If desired.
For example - if you do this
myFilter->SetStartMethod(myfunc, myarg);
myFilter->RegisterCallBackHandler(myotherfunc, myarg,
VTK_MSG_PROGRESS_START)
you're actually doing the same thing, but the second version
allows you to send a function which will receive the full
parameter list and not just the arg.
(see *** above) Note that several callbacks can be defined for the
same message if one wants! -
The only problem is the arg delete ones, because the arg isn't
present when the callback is set, so one must scan previously set
args to see what's what.
I think I'm going on a bit so I'll stop. I shall find a nice way
of doing the arg delete ones without changing any (users) code. I
welcome comments etc etc
I think the obvious way is
callbackhandler->RegisterArgDeleteHandler(something meaningful
here);
then it can be merged in with the rest and no changes will be
required - I'll see if this works and report back when done.
John B
More information about the vtk-developers
mailing list