|
Boost : |
From: Jody Hagins (jody-boost-011304_at_[hidden])
Date: 2004-11-24 09:31:02
I have a class that needs to react to a particular signal. However, the
manner in which it handles the signal is state dependent. I would,
therefore, like to change the connected slot when necessary. In
general, this is not a problem. However, changing the connection inside
another slot is problematic. For example, assume that Foo::bar() is
already connected to signal_, and signal_() is called...
void
Foo::
bar()
{
std::cout << "Foo::bar()\n";
current_connection_.disconnect();
current_connection_ = signal_.connect(
boost::bind(&Foo::bar1, this));
}
void
Foo::
bar1()
{
std::cout << "Foo::bar1()\n";
}
What I want to happen is that bar() will be called, then it will be
disconnected, and bar1 will then be connected in its place. For
example, given this calling sequence...
signal_();
signal_();
I expect to see...
Foo::bar()
Foo::bar1()
However, sometimes I may see...
Foo::bar()
Foo::bar1()
Foo::bar1()
because bar1() MAY get connected AFTER the place where bar() used to be
connected, resulting in it also being called for the same signal
invocation.
What I think I want is a way to "replace" a connected slot, without
disturbing anything else...
void
Foo::
bar()
{
std::cout << "Foo::bar()\n";
current_connection_.replace_slot(&Foo::bar1, this);
}
This is especially important if the slot is originally connected with...
signal_.connect(
invocation_level,
boost::bind(&Foo::bar1, this));
because I see no way to retrieve the ordering information from the
connection.
In any event, how do you suggest I "replace" a conected slot, while
still guaranteeing that the "connection" is invoked exactly once?
Thanks!!!
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk