//*** //*** File : fifo.bip -- BIP description of producer/consumer //*** connected through a fifo channel //*** //*** Details: http://www-verimag.imag.fr/~async/BIP/examples.html //*** //*** Author : Ananda Basu (basu@imag.fr), Verimag, 07/2006 //*** {# typedef char* pChar ; #} component fifo port write_event, read_event data {# enum e { max = 5 }; char store[max]; #} data char c data int i, first extern data int max // make max visible from Bip world behavior initial do i=0; first=0; to S state S on write_event provided (i != max) do {# store[(first + i) % max] = c; ++i; c = store[first]; #} to S on read_event provided (i != 0) do {# -- i; first = (first + 1) % max; c = store[first]; #} to S end end component producer port out data pChar str data char c init {# str = "Hello BIP!\n"; c = *str++; #} behavior initial to WORK state WORK on out provided (*str) do {# c = *str++; #} to WORK end end component consumer port in data char c behavior initial to WORK state WORK on in do {# printf("\n Received character : %c\n", c); #} to WORK end end component Team contains fifo fifo_inst contains producer prod_inst contains consumer cons_inst connector C1 = prod_inst.out, fifo_inst.write_event behavior do fifo_inst.c = prod_inst.c; end connector C2 = cons_inst.in, fifo_inst.read_event behavior do cons_inst.c = fifo_inst.c; end end