Boost logo

Boost :

From: Stjepan Rajko (stipe_at_[hidden])
Date: 2007-02-19 19:55:31


Is there any interest in a library which facilitates the
implementation and interconnection of objects using Boost.Signals?
For example, in a video processing scenario, one might be using the
following objects:

 * frame_rate - generates a void() signal at a consistent frame rate
 * video_generator - upon receiving a void() signal, produces a signal
containing an image (e.g., a frame grabbed from a camera or read from
a file)
 * differencer - upon receiving an image signal, outputs the
pixel-difference between the image and the previous image received
 * flipper - upon receiving an image signal, outputs the horizontally
flipped image
 * analysis - upon receiving an image signal, performs some sort of
analysis and outputs a feature vector signal
 * database - upon receiving a feature vector signal, outputs an image
from the database based on some relationship
 * display1, display2 - upon receiving an image, displays it in a window

It would be nice to be able to easily connect these objects via
intuitive signal flow "diagrams":

// perform the whole video analysis and display the results
frame_rate >>= video_generator >>= differencer >>= flipper >>=
 analysis >>= database >>= display1;

// also display the video input
video_generator >>= display2;

... or, to specify the entire signal flow in one shot using something like this:
frame_rate
>>= video_generator
>= (differencer >>= flipper >>= analysis >>= database >>= display1)
>= display2;

Boost.Signals allows us to interconnect the components, and
also change the connections as needed(for example, one could
skip the flipper if necessary). However, in the absence of an easy
connection mechanism such as the one above, one
has to use signal::connect(...) for each connection, which can be
tedious with a lot of connections, and not as readable.

As a starting point, I implemented a little library that provides the
above connection syntax (and a little more) - you can find most of it
documented as the signal_link class at http://tinyurl.com/2npfcr.
The code is attached - I've tested it under both VS.NET2005 and GCC
4.0.1 on OSX/Xcode. It has a little test app with test cases (an
included script called g++_it should build it using g++ if you
have boost includes and libs on your path).

If you find this concept interesting please take a look at the
documentation and the code, I'd be most interested to hear your
feedback. There are quite a few things still missing (for example,
the slot_selector mechanism is not fully integrated with the
operators, and it's not possible to disconnect signals in all ways one
would want to), so suggestions are more than welcome. In particular:
  * The current signal_link class provides a default output object.
Would it be better to let the descendant class provide its own and
supply a reference to signal_link?
  * I am having problems using signal::disconnect to disconnect
equivalent slots (even trying to compile examples from the web
documentation). I'm using 1_33_1. Any ideas?
  * I'm wondering whether the choice of operators (operator(), >>=.,
>=) used is appropriate or whether there are better alternatives.
  * Is there a better alternative to the current slot_selector mechanism?

Also, please let me know whether you think this would be an
interesting addition to Boost. I think the concept might be useful in
any situation where the problem can be visualized as a flow of
data/signals (e.g., any signal processing application).

Regards,

Stjepan




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk