Inheritance diagram for csp::common::NotifySender< DATA_TYPE >:
The code of the process is straightforward:
while (true) { in >> t; out << t; sentAck << true; }
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; } } }
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. |
csp::common::NotifySender< DATA_TYPE >::NotifySender | ( | const Chanin< DATA_TYPE > & | _in, | |
const Chanout< DATA_TYPE > & | _out, | |||
const Chanout< bool > & | _sentAck | |||
) | [inline] |
Constructs the process.
_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. |
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.