--- ray/src/hd/rholo4.c 1998/05/22 08:30:41 3.18 +++ ray/src/hd/rholo4.c 2003/07/27 22:12:02 3.35 @@ -1,70 +1,94 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rholo4.c,v 3.35 2003/07/27 22:12:02 schorsch Exp $"; #endif - /* * Holodeck display process communication */ #include "rholo.h" #include "rhdisp.h" +#include "rtprocess.h" #include +#include #ifndef HDSUF -#define HDSUF ".hdi" +#define HDSUF ".hdi" #endif +#ifndef SLAVENAME +#define SLAVENAME "slave" +#endif +#ifndef FNONBLK +#define FNONBLK O_NONBLOCK +#endif + static int inp_flags; -static int dpd[3]; +static SUBPROC dpd; static FILE *dpout; disp_open(dname) /* open the named display driver */ char *dname; { - char dpath[128], fd0[8], fd1[8], *cmd[5]; - int i; - /* get full display program name */ + char buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn; + int i, n, len; + + if (!strcmp(dname, SLAVENAME)) { + dpd.r = 0; /* read from stdin */ + dpout = stdout; /* write to stdout */ + dpd.running = 0; /* we're the slave procees */ + } else { + /* get full display program name */ #ifdef DEVPATH - sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF); + sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF); #else - sprintf(dpath, "dev/%s%s", dname, HDSUF); + sprintf(buf, "dev/%s%s", dname, HDSUF); #endif - /* dup stdin and stdout */ - if (readinp) - sprintf(fd0, "%d", dup(0)); - else - strcpy(fd0, "-1"); - sprintf(fd1, "%d", dup(1)); - /* start the display process */ - cmd[0] = dpath; - cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; - cmd[4] = NULL; - i = open_process(dpd, cmd); - if (i <= 0) - error(USER, "cannot start display process"); - if ((dpout = fdopen(dpd[1], "w")) == NULL) - error(SYSTEM, "cannot associate FILE with display pipe"); - dpd[1] = -1; /* causes ignored error in close_process() */ + /* dup stdin and stdout */ + if (readinp) + sprintf(fd0, "%d", dup(0)); + else + strcpy(fd0, "-1"); + sprintf(fd1, "%d", dup(1)); + /* start the display process */ + cmd[0] = buf; + cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; + cmd[4] = NULL; + i = open_process(&dpd, cmd); + if (i <= 0) + error(USER, "cannot start display process"); + if ((dpout = fdopen(dpd.w, "w")) == NULL) + error(SYSTEM, "problem opening display pipe"); + /* close dup'ed stdin and stdout */ + if (readinp) + close(atoi(fd0)); + close(atoi(fd1)); + } + dpd.w = -1; /* causes ignored error in close_process() */ inp_flags = 0; - /* close dup'ed stdin and stdout */ - if (readinp) - close(atoi(fd0)); - close(atoi(fd1)); /* check if outside */ if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) disp_result(DS_OUTSECT, 0, NULL); /* send eye separation if specified */ if (vdef(EYESEP)) { - char fbuf[32]; - sprintf(fbuf, "%.9e", vflt(EYESEP)); - disp_result(DS_EYESEP, strlen(fbuf)+1, fbuf); + sprintf(buf, "%.9e", vflt(EYESEP)); + disp_result(DS_EYESEP, strlen(buf)+1, buf); } - /* write out hologram grids */ - for (i = 0; hdlist[i] != NULL; i++) - disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); + /* write out hologram grids & octrees */ + for (i = 0; hdlist[i] != NULL; i++) { + memcpy(buf, (void *)hdlist[i], sizeof(HDGRID)); + len = sizeof(HDGRID); + n = vdef(GEOMETRY); + sfn = i= 0) { dpout = NULL; error(USER, "display process died"); } - if (errno != EAGAIN & errno != EINTR) + if ((errno != EAGAIN) & (errno != EINTR)) goto readerr; return(2); /* acceptable failure */ } if (msg.nbytes) { /* get the message body */ + if (msg.nbytes < 0) + error(INTERNAL, "anti-message from display process"); buf = (char *)malloc(msg.nbytes); if (buf == NULL) error(SYSTEM, "out of memory in disp_check"); - if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) + if (inp_flags != 0 && fcntl(dpd.r, F_SETFL, inp_flags=0) < 0) goto fcntlerr; - if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) + if (readbuf(dpd.r, buf, msg.nbytes) != msg.nbytes) goto readerr; } switch (msg.type) { /* take appropriate action */ @@ -122,12 +148,17 @@ int block; case DR_NEWSET: /* new calculation set */ if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_NEWSET from display process"); - disp_result(DS_STARTIMM, 0, NULL); + if (msg.nbytes) + disp_result(DS_STARTIMM, 0, NULL); bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); - disp_result(DS_ENDIMM, 0, NULL); - disp_flush(); + if (msg.nbytes) { + disp_result(DS_ENDIMM, 0, NULL); + disp_flush(); + } break; case DR_ADDSET: /* add to calculation set */ + if (!msg.nbytes) + break; if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_ADDSET from display process"); disp_result(DS_STARTIMM, 0, NULL); @@ -136,6 +167,8 @@ int block; disp_flush(); break; case DR_ADJSET: /* adjust calculation set members */ + if (!msg.nbytes) + break; if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_ADJSET from display process"); disp_result(DS_STARTIMM, 0, NULL); @@ -144,10 +177,17 @@ int block; disp_flush(); break; case DR_DELSET: /* delete from calculation set */ + if (!msg.nbytes) + break; if (msg.nbytes % sizeof(PACKHEAD)) error(INTERNAL, "bad DR_DELSET from display process"); bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); break; + case DR_VIEWPOINT: /* set target eye position */ + if (msg.nbytes != sizeof(VIEWPOINT)) + error(INTERNAL, "bad DR_VIEWPOINT from display process"); + myeye = *((VIEWPOINT *)buf); + break; case DR_ATTEN: /* block for priority request */ if (msg.nbytes) error(INTERNAL, "bad DR_ATTEN from display process"); @@ -175,7 +215,7 @@ int block; case DR_CLOBBER: /* clobber holodeck */ if (msg.nbytes) error(INTERNAL, "bad DR_CLOBBER from display process"); - if (!force || !ncprocs) + if ((force <= 0) | (ncprocs <= 0)) error(WARNING, "request to clobber holodeck denied"); else { error(WARNING, "clobbering holodeck contents"); @@ -208,10 +248,12 @@ disp_close() /* close our display process */ if (dpout == NULL) return(-1); + myeye.rng = 0; disp_result(DS_SHUTDOWN, 0, NULL); fclose(dpout); dpout = NULL; - return(close_process(dpd)); + return(dpd.running ? close_process(&dpd) : 0); + } @@ -220,7 +262,11 @@ int type, nbytes; char *p; { MSGHEAD msg; - + /* consistency checks */ +#ifdef DEBUG + if (nbytes < 0 || nbytes > 0 & p == NULL) + error(CONSISTENCY, "bad buffer handed to disp_result"); +#endif if (dpout == NULL) return; msg.type = type;