next up previous contents
Next: A Monitor Process Up: Example Programs Previous: A DD Producer

A DD Consumer Process

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. In order to minimize the number of unsuccessful tries to get an event, a call to ddu_req_fev(n_events) is made. This call makes sure that always at least n_events are reserved for this process (unless data taking stopped for one reason or another).

#include <dd_user.h>

 
main(int argc,char **argv)

{

int *p;

char fname[100];

int mode, reqcnt, prescale, wait,ctl[4];

struct fifo_entry fev;

int go_on;

if (argc < 2) {

printf("syntax: argument fifo name needed \n");

exit(0);

}

strcpy(fname,argv[1]);

mode = FMODE_COND;

wait = DD_WAIT_ASYNC;

/* mode = FMODE_ONREQ; */

/* wait = DD_WAIT_SLEEP; */

prescale = 1;

ctl[0] = -1;

ctl[1] = 4;

ctl[2] = -1;

ctl[3] = -1;

if ( (status = ddu_init(fname,mode,prescale,wait,ctl)) != 0 ) {

printf("ddu_init: status returned %d\n",status);

exit(1);

}

/* if you want to have always at least 5 events */

/* waiting to be picked up by this process */

/* n_events = 5; */

/* ddu_set_reqcnt(n_events); */

ddu_start();

go_on = 1;

while (go_on & & ddu_attached() ) {

status = ddu_get_fev(&fev);

if (status == 0){

printf(``got an event of length %d at address %x \n'',

fev.len,fev.p2da);

if ( (status = ddu_put_fev(fev)) != 0 ) {

printf("ddu_put_fev: status returned %d\n",status);

go_on = 0;

}

} else if ( status < 0 ) {

printf("ddu_get_fev: status returned %d\n",status);

go_on = 0;

} else

printf(``tried to get an event, but none was available\n'');

}

ddu_stop();

ddu_close();

exit(0);

}



Online software development
Thu Mar 14 10:35:53 EST 1996