On Sun, 6 Aug 2000, Baruch Even wrote:
> In the decoupling process of the image loading from the figure inset I
> needed to use a signal on the image loader to notify when the image has
> loaded. For this my InsetGraphics now inherits also from SigC::Object.
Firstly, ask yourself if you really require a callback here. Will a
semaphore suffice? A semaphore can be checked on a redraw so there is
little overhead from polling. The only problem would be that a picture
on screen wouldn't be updated unless a user triggered a redraw by
scrolling for example.
> As I have no idea what is going on in the signals, I wanted to know what
> adverse effects (if any) can be on the inset? Is there anything I should
> pay attention to due to this change?
Okay, supposing you still want a callback (can't you do a join() or
something between the threads/forks?) and use a signal for this. The
biggest problem with Signals is that they can't be copied (or at least
there copy semantics are different to what you might desire). So you need
to make sure that Clone() does what you want it too. For example,
suppose I create a InsetGraphics with a picture. It's being rendered in
the background and I copy the inset. We want both insets to get the same
image when the rendering is complete. So we want both to be connected to
the same signal.
The trick to notice here is that the callback (a function pointer to a
function in the given inset) is different for each inset. So there has to
be two connections to the Signal in the renderer -- one from the original
Inset and one from the copied one. That will require you to know the
renderer to which the original is connected (so you connect to its
Signal).
Something like:
INsetGraphics & InsetGraphics::Clone(...) {
InsetGraphics tmp();
...
if (renderer) {
renderer->finished.connect(slot(tmp,&InstallGraphics::callback);
tmp.renderer = renderer;
} else {
tmp.renderer = 0;
}
return tmp;
}
then in callback() you need to have a:
renderer = 0;
line. Not the prettiest but it's the first thing that came to mind.
Probably better ways of doing this and there's probably a flaw in this
somewhere (almost certainly related to the race between copying an inset
and clearing renderer in the callback).
Allan. (ARRae)