Re: [sigc] Handling signal loops
- From: "Andrew E. Makeev" <andrew solvo ru>
- To: "Timothy M. Shead" <tshead k-3d com>
- Cc: "libsigc-list gnome org" <libsigc-list gnome org>
- Subject: Re: [sigc] Handling signal loops
- Date: Tue, 27 Sep 2005 09:58:38 +0400
Timothy M. Shead wrote:
On Mon, 2005-09-26 at 10:25 +0400, Andrew E. Makeev wrote:
Timothy M. Shead wrote:
I'm wondering if anyone has come across a way to handle signal "loops" -
that is to say, if signal A is connected to signal B, and B to A, is
there any way to prevent emission of either from entering an infinite
loop? I tried creating a custom accumulator, but discovered that a new
instance of the accumulator is created every time emit() is called. I
know it sounds crazy, but I'd like to find a way to see that every
signal in a given loop gets called, then the loop is broken.
Try static member for accumulator class, and increase it in each signal
callback, so, when you hit "odd" number, for example, stop the signal
emission with accumulator return state.
Guess, that's clear.
Seems like I could use this to impose an arbitrary limit on the number
of emissions that take place, and thus prevent infinite loops, but I
would have know way of knowing whether I'd hit every signal
once-and-only-once, or whether I terminated too soon ... unless I'm
missing something?
Using static flags you could do whatever you would to.
One way:
flag = 0 - no signal
flag = 1 - 1st signal
flag = 2 - 2nd signal
When enter 1st slot, check if (flag == 0 || flag == 2) else (duplicate,
stop). if (flag == 2) then (flag = 0, stop) else (flag = 1).
When enter 2nd slot, check if (flag == 0 || flag == 1) else (duplicate,
stop). if (flag == 1) then (flag = 0, stop) else (flag = 2).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]