csp::common::NotifySender< DATA_TYPE > Class Template Reference

Inheritance diagram for csp::common::NotifySender< DATA_TYPE >:

csp::CSProcess csp::ThreadCSProcess boost::noncopyable List of all members.

Detailed Description

template<typename DATA_TYPE>
class csp::common::NotifySender< DATA_TYPE >

A process that behaves like Id -- continually reading values and then sending them on -- but with acknowledgements when the message has been sent on.

The code of the process is straightforward:

            while (true)
            {
                in >> t;
                out << t;
                sentAck << true;
            }
When poison is encountered, all channels are poisoned. A "false" value is NOT sent; instead, the sendAck channel will be poisoned.

One main use of this process -- if the buffering (of one) it inherently adds is acceptable -- is to transform an output into an input, for use with an alt. Consider a case where you have a process that wants to wait for either input on its "in" channel or output being taken on its "out" channel. You could do the following (using int as the data type for illustration):

        One2OneChannel<int> c;
        One2OneChannel<bool> acks;
        AltChanin<bool> ackIn = acks.reader();
        ScopedForking forking;
        forking.forkInThisThread(new NotifySender<int>(c.reader(),out,acks.writer()));
        
        Alternative alt( boost::assign::list_of<Guard*>(in.inputGuard())(ackIn.inputGuard()) );
        while (true)
        {
            switch (alt.fairSelect())
            {
                case 0:
                    {
                        //input on in channel:
                        int n;
                        in >> n;
                        // ... do something ...
                        break;
                    }
                case 1:
                    {
                        //output was taken:
                        bool b;
                        ackIn >> b;
                        // ... do something ...
                        break;
                    }
            }
        }

DATA_TYPE Requirements

DATA_TYPE must have a default constructor, and must meet the requirements of the channels it is being used with.


Public Member Functions

 NotifySender (const Chanin< DATA_TYPE > &_in, const Chanout< DATA_TYPE > &_out, const Chanout< bool > &_sentAck)
 Constructs the process.

Protected Member Functions

void run ()
 You must implement this function to provide the code for your process.


Constructor & Destructor Documentation

template<typename DATA_TYPE>
csp::common::NotifySender< DATA_TYPE >::NotifySender ( const Chanin< DATA_TYPE > &  _in,
const Chanout< DATA_TYPE > &  _out,
const Chanout< bool > &  _sentAck 
) [inline]

Constructs the process.

Parameters:
_in The channel to read the data from
_out The channel to send the data out on
_sentAck The channel to send the send-notifications on.


Member Function Documentation

template<typename DATA_TYPE>
void csp::common::NotifySender< DATA_TYPE >::run (  )  [inline, protected, virtual]

You must implement this function to provide the code for your process.

When the run method finishes, the process will terminate.

You should not let an uncaught exception cause the end of this function. If it derives from std::exception, it will be caught (although this behaviour should not be relied upon) but otherwise undefined behaviour will result.

Implements csp::ThreadCSProcess.


Generated on Mon Aug 20 12:24:29 2007 for C++CSP2 by  doxygen 1.4.7