
UniCon StreamIn and StreamOut players allow system designers to view streams of data as entities in a design, and to apply data typing semantics to these entities. System designers can, therefore, describe and reason about properties of streams in ways that are not possible by simply focusing on the source code implementations of the filters.
NOTE: UniCon generates a program that performs the initialization of a pipe and filter system at run-time. This program creates all of the pipes, and hooks each end of each pipe to the appropriate port in one of the filters in the system. Therefore, a filter should never open or close a port; it should assume that the open is done automatically prior to execution of the first line of code in the filter, and that the close is done automatically after the last line of code in the filter is executed. Therefore, when using the write system call to implement the output stream, no calls to open and close are necessary. When any of the formatted
I/O routines are used, such as fputc and fprintf, no calls to fopen and fclose are necessary - however in this case one call to fdopen is required to wrap the output port up as a file pointer, the data structure expected by the formatted I/O routines.
The following are examples of StreamOut players in the implementation of a filter:
#include <stdio.h>
#define PORT_3 3
#define PORT_5 5
#define MAX_BUF_LEN 256
#define FOR_OUTPUT "w"
#define ONE_CHARACTER 1
/* external data definitions required to support the code fragments below */
char output_buffer[MAX_BUF_LEN + 1];
FILE *fp;
int i;
/* in each example below the code writes from output_buffer until
the end of the buffer is reached, or the value `\0' is encountered */
/* the following lines of code perform stream output to port 3, one character at
a time, using the write system call (inside the implementation of a filter) */
for (i = 0;
output_buffer[i] != `\0' && i < MAX_BUF_LEN;
i++)
write (PORT_3, &output_buffer[i], ONE_CHARACTER);
/* the following lines of code perform stream output to port 5 using
the fprintf formatted I/O routine (inside the implementation of a filter) */
fp = fdopen (PORT_5, FOR_OUTPUT); /* this call happens only once */
output_buffer[MAX_BUF_LEN] = `\0';
fprintf (fp, "%s", output_buffer);

Author:
Last Modified: May 12, 1996