Passing reference to boost::bind object

So, we are implementing boost::signals/slots, and in several cases, we have a connect() function to allow us to hook up an arbitrary slot to the signal, without exposing the details of the signal for cleanliness issues. We would like to implement the signals::trackable interface, and have the objects which are passing in the bound slot manage their connections in this manner. However, we are passing them as boost::function objects, which (as documented) does not work properly with boost::function objects, only boost::bind objects. In all of the documentation that I've found, about assigning the results of a boost::bind call were to function objects. Is there an alternative available to not destroy the trackable functionality that we're trying to use? Thanks --dw

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday 08 April 2009, david.weber@l-3com.com wrote:
So, we are implementing boost::signals/slots, and in several cases, we have a connect() function to allow us to hook up an arbitrary slot to the signal, without exposing the details of the signal for cleanliness issues.
We would like to implement the signals::trackable interface, and have the objects which are passing in the bound slot manage their connections in this manner. However, we are passing them as boost::function objects
Pass slots through your interface as signal::slot_type objects. trackable objects are discovered in the slot_type constructor. See the "passing slots" portion of the tutorial. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkncp3oACgkQ5vihyNWuA4VrfwCghvy5gwKvWupGISZbpGkPyo7f FCcAoIw9yMO2vcOdl95UqfSSwKELAMbq =ouA9 -----END PGP SIGNATURE-----

Ok, found it. Now, the rub.
We have plugins, which register interest in things. When they call a
base-class register() function to register interest, they pass in the
slot that they want the thing's signal to be connected to.
So, the plugin base class (who we want to inherit from
boost:;signals::trackable) keeps a map of interested thing to (formerly
a boost::function) object. When changed to a signal_t::slot_type,
compilation dies.
Looking at slot.hpp, it looks like a slot does not have a copy
constructor, nor an assignment operator. This means we can't store the
slot in an STL container, nor can we pass a boost::function through the
register() function without breaking trackable. Note: The functions are
bound to class instance member functions, so we're using boost::bind.
We were hitting an issue, where the connections weren't being torn down
when the plugin unloads, causing a segfault when the signal was emitted.
Trackable seemed like the easiest mechanism to add this functionality.
So, can we delay turning the bind into a slot somehow? What does bind
actually return? It would seem that if I can store that *bound* object,
and just wait until we need to call connect, we should be fine.
------------------------------------
Just re-read the above, I'll write some pseudo-code to illustrate our
problem
-------------------------------------
Class plugin_base : boost::signals::trackable
{
Public:
Plugin_base(){};
// We need to make sure that we tear down our connections...
~plugin_base(){};
Register(int id, boost::function slot)
{
registerMap[id] = slot;
}
Connect(object obj) // connect obj's signal to plugin_concrete's
slot
{
// Prefer not to keep list of connections here.
// Automate via trackable is preferred.
Obj.sig.connect(registerMap[obj.id]);
}
Private:
Std::map
participants (3)
-
david.weber@l-3com.com
-
Frank Mori Hess
-
Nat Goodspeed