Back to index

radiance  4R0+20100331
Defines | Functions | Variables
devcomm.c File Reference
#include "copyright.h"
#include <sys/types.h>
#include <sys/wait.h>
#include "platform.h"
#include "standard.h"
#include "driver.h"

Go to the source code of this file.

Defines

#define DEVPATH   getenv("PATH") /* device search path */

Functions

static struct driverfinal_connect (void)
static void mygets (char *s, FILE *fp)
static void myputs (char *s, FILE *fp)
static void reply_error (char *routine)
static void getstate (void)
struct driverslave_init (char *dname, char *id)
struct drivercomm_init (char *dname, char *id)
static void comm_close (void)
static void comm_clear (int xres, int yres)
static void comm_paintr (COLOR col, int xmin, int ymin, int xmax, int ymax)
static void comm_flush (void)
static int comm_getcur (int *xp, int *yp)
static void comm_comout (char *str)
static void comm_comin (char *buf, char *prompt)
static void mygets (register char *s, register FILE *fp)
static void myputs (register char *s, register FILE *fp)

Variables

static const char RCSid [] = "$Id: devcomm.c,v 2.15 2008/08/21 07:05:58 greg Exp $"
FILE * devin
FILE * devout
int devchild
static dr_closef_t comm_close
static dr_clearf_t comm_clear
static dr_paintrf_t comm_paintr
static dr_getcurf_t comm_getcur
static dr_comoutf_t comm_comout
static dr_cominf_t comm_comin
static dr_flushf_t comm_flush

Define Documentation

#define DEVPATH   getenv("PATH") /* device search path */

Definition at line 20 of file devcomm.c.


Function Documentation

static void comm_clear ( int  xres,
int  yres 
) [static]

Definition at line 153 of file devcomm.c.

{
       putc(COM_CLEAR, devout);
       putw(xres, devout);
       putw(yres, devout);
       fflush(devout);
}
static void comm_close ( void  ) [static]

Definition at line 136 of file devcomm.c.

{
       int    pid;

       erract[COMMAND].pf = NULL;         /* reset error vectors */
       if (erract[WARNING].pf != NULL)
              erract[WARNING].pf = wputs;
       fclose(devout);
       fclose(devin);
       if (devchild < 0)
              return;
       while ((pid = wait(0)) != -1 && pid != devchild)
              ;
}

Here is the call graph for this function:

static void comm_comin ( char *  buf,
char *  prompt 
) [static]

Definition at line 226 of file devcomm.c.

{
       putc(COM_COMIN, devout);
       if (prompt == NULL)
              putc(0, devout);
       else {
              putc(1, devout);
              myputs(prompt, devout);
       }
       fflush(devout);
       if (getc(devin) != COM_COMIN)
              reply_error("comin");
       mygets(buf, devin);
       getstate();
}

Here is the call graph for this function:

static void comm_comout ( char *  str) [static]

Definition at line 214 of file devcomm.c.

{
       putc(COM_COMOUT, devout);
       myputs(str, devout);
       if (str[strlen(str)-1] == '\n')
              fflush(devout);
}

Here is the call graph for this function:

static void comm_flush ( void  ) [static]

Definition at line 184 of file devcomm.c.

{
       putc(COM_FLUSH, devout);
       fflush(devout);
       if (getc(devin) != COM_FLUSH)
              reply_error("flush");
       getstate();
}

Here is the call graph for this function:

static int comm_getcur ( int *  xp,
int *  yp 
) [static]

Definition at line 195 of file devcomm.c.

{
       int    c;

       putc(COM_GETCUR, devout);
       fflush(devout);
       if (getc(devin) != COM_GETCUR)
              reply_error("getcur");
       c = getc(devin);
       *xp = getw(devin);
       *yp = getw(devin);
       return(c);
}

Here is the call graph for this function:

struct driver* comm_init ( char *  dname,
char *  id 
) [read]

Definition at line 79 of file devcomm.c.

{
       char   *dvcname;
       int    p1[2], p2[2];
       char   pin[16], pout[16];
                                          /* find driver program */
       if ((dvcname = getpath(dname, DEVPATH, X_OK)) == NULL) {
              eputs(dname);
              eputs(": not found\n");
              return(NULL);
       }
#ifdef RHAS_FORK_EXEC
                                          /* open communication pipes */
       if (pipe(p1) == -1 || pipe(p2) == -1)
              goto syserr;
       if ((devchild = fork()) == 0) {    /* fork driver process */
              close(p1[1]);
              close(p2[0]);
              sprintf(pin, "%d", p1[0]);
              sprintf(pout, "%d", p2[1]);
              execl(dvcname, dname, pin, pout, id, NULL);
              perror(dvcname);
              _exit(127);
       }
       if (devchild == -1)
              goto syserr;
       close(p1[0]);
       close(p2[1]);
       /*
        * Close write stream on exec to avoid multiprocessing deadlock.
        * No use in read stream without it, so set flag there as well.
        */
       fcntl(p1[1], F_SETFD, FD_CLOEXEC);
       fcntl(p2[0], F_SETFD, FD_CLOEXEC);
       if ((devout = fdopen(p1[1], "w")) == NULL)
              goto syserr;
       if ((devin = fdopen(p2[0], "r")) == NULL)
              goto syserr;
       return(final_connect());           /* verify initialization */
syserr:
       perror(dname);
       return(NULL);

#else  /* ! RHAS_FORK_EXEC */

       eputs(dname);
       eputs(": no fork/exec\n");
       return(NULL);

#endif /* ! RHAS_FORK_EXEC */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void comm_paintr ( COLOR  col,
int  xmin,
int  ymin,
int  xmax,
int  ymax 
) [static]

Definition at line 166 of file devcomm.c.

{
       putc(COM_PAINTR, devout);
       fwrite((char *)col, sizeof(COLOR), 1, devout);
       putw(xmin, devout);
       putw(ymin, devout);
       putw(xmax, devout);
       putw(ymax, devout);
}
static struct driver * final_connect ( void  ) [static, read]

Definition at line 47 of file devcomm.c.

{
       putw(COM_SENDM, devout);
       fflush(devout);
       if (getw(devin) != COM_RECVM)
              return(NULL);
                                          /* get driver parameters */
       getstate();
                                          /* set error vectors */
       erract[COMMAND].pf = comm_comout;
       /*                                 doesn't work with raypcalls.c
       if (erract[WARNING].pf != NULL)
              erract[WARNING].pf = comm_comout;
       */
       return(&comm_driver);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void getstate ( void  ) [static]

Definition at line 285 of file devcomm.c.

{
       fread((char *)&comm_driver.pixaspect,
                     sizeof(comm_driver.pixaspect), 1, devin);
       comm_driver.xsiz = getw(devin);
       comm_driver.ysiz = getw(devin);
       comm_driver.inpready = getw(devin);
}

Here is the caller graph for this function:

static void mygets ( char *  s,
FILE *  fp 
) [static]

Definition at line 158 of file devmain.c.

{
       register int  c;

       while ((c = getc(fp)) != EOF)
              if ((*s++ = c) == '\0')
                     return;
       *s = '\0';
}

Here is the caller graph for this function:

static void mygets ( register char *  s,
register FILE *  fp 
) [static]

Definition at line 247 of file devcomm.c.

{
       register int  c;

       while ((c = getc(fp)) != EOF)
              if ((*s++ = c) == '\0')
                     return;
       *s = '\0';
}
static void myputs ( char *  s,
FILE *  fp 
) [static]

Definition at line 171 of file devmain.c.

{
       do
              putc(*s, fp);
       while (*s++);
}

Here is the caller graph for this function:

static void myputs ( register char *  s,
register FILE *  fp 
) [static]

Definition at line 262 of file devcomm.c.

{
       do
              putc(*s, fp);
       while (*s++);
}
static void reply_error ( char *  routine) [static]

Definition at line 274 of file devcomm.c.

{
       eputs(routine);
       eputs(": driver reply error\n");
       quit(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct driver* slave_init ( char *  dname,
char *  id 
) [read]

Definition at line 66 of file devcomm.c.

{
       devchild = -1;                            /* we're the slave here */
       devout = stdout;                   /* use standard input */
       devin = stdin;                            /* and standard output */
       return(final_connect());           /* verify initialization */
}

Here is the call graph for this function:


Variable Documentation

Definition at line 33 of file devcomm.c.

Definition at line 32 of file devcomm.c.

Definition at line 37 of file devcomm.c.

Definition at line 36 of file devcomm.c.

Definition at line 38 of file devcomm.c.

Definition at line 35 of file devcomm.c.

Definition at line 34 of file devcomm.c.

int devchild

Definition at line 24 of file devcomm.c.

FILE* devin

Definition at line 23 of file devcomm.c.

FILE * devout

Definition at line 23 of file devcomm.c.

const char RCSid[] = "$Id: devcomm.c,v 2.15 2008/08/21 07:05:58 greg Exp $" [static]

Definition at line 2 of file devcomm.c.