The following sample program is a consumer that requests
all events, which have bit 3 of fev.ctlb1 set.
If no event is available, the consumers returns immediately.
Another consumer option is commented out: It receives only
events on request, falls asleep when there are no events.
int main(int argc, char *argv[])
{
char *dd_name = "dd.brook.drive";
char *pcFifoName = "test";
DD_factory *pDDFactory = new DD_factory();
DD *my_dd = DD::create_dd( dd_name, "r" );
if ( my_dd->get_status() != DD_STATUS_OK ) {
cout << "test_consumer: error in creating DD system " <<
dd_name << endl;
exit(EXIT_FAILURE);
}
//
// create the fifo in the desired mode
//
sFifo_mode sMode;
sMode.eFill_mode = fill_all;
sMode.eFilter = filter_off;
sMode.eWait = sleep_mode;
sMode.fctl.iCtlw1 = sMode.fctl.iCtlb1 = sMode.fctl.iCtlw2 = sMode.fctl.iCtlb2 = -1;
const char *pcFifoType = "DYN";
Fifo *pMyFifo = my_dd->create_fifo( pcFifoName, pcFifoType, sMode );
if ( pMyFifo == NULL ) {
cout << "test_consumer: error in creating my fifo " << pcFifoName << endl;
exit( EXIT_FAILURE );
}
int nEvents = 3;
int iEvent;
// now our fifo is enabled to receive events until
// we call disable_events
my_dd->enable_events();
for ( iEvent = 0; iEvent < nEvents; iEvent++ ) {
Fifo_entry fev;
int iStatus;
iStatus = my_dd->get_fev( fev );
if ( iStatus != ddcSuccess ) {
cout << "req_fev returns status " << iStatus << endl;
break;
}
else {
iStatus = my_dd->put_fev( fev );
if ( iStatus != ddcSuccess ) {
cout << "put_fev returns status " << iStatus << endl;
break;
}
}
}
my_dd->disable_events();
cout << "I consumed " << iEvent << " from the DD system" << endl;
delete my_dd;
return 0;
}
Alphabetic index Hierarchy of classes