| 1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Holodeck display process communication |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#include "rholo.h" |
| 9 |
|
#include "rhdisp.h" |
| 10 |
+ |
#include "rtprocess.h" |
| 11 |
|
#include <sys/uio.h> |
| 12 |
+ |
#include <string.h> |
| 13 |
|
|
| 14 |
|
#ifndef HDSUF |
| 15 |
< |
#define HDSUF ".hdisp" |
| 15 |
> |
#define HDSUF ".hdi" |
| 16 |
|
#endif |
| 17 |
+ |
#ifndef SLAVENAME |
| 18 |
+ |
#define SLAVENAME "slave" |
| 19 |
+ |
#endif |
| 20 |
|
|
| 21 |
+ |
#ifndef FNONBLK |
| 22 |
+ |
#define FNONBLK O_NONBLOCK |
| 23 |
+ |
#endif |
| 24 |
+ |
|
| 25 |
|
static int inp_flags; |
| 26 |
< |
static int dpd[3]; |
| 26 |
> |
static SUBPROC dpd; |
| 27 |
|
static FILE *dpout; |
| 28 |
|
|
| 29 |
+ |
static void disp_flush(void); |
| 30 |
+ |
static void disp_result(int type, int nbytes, char *p); |
| 31 |
|
|
| 32 |
< |
disp_open(dname) /* open the named display driver */ |
| 33 |
< |
char *dname; |
| 32 |
> |
|
| 33 |
> |
extern void |
| 34 |
> |
disp_open( /* open the named display driver */ |
| 35 |
> |
char *dname |
| 36 |
> |
) |
| 37 |
|
{ |
| 38 |
< |
char dpath[128], fd0[8], fd1[8], *cmd[5]; |
| 39 |
< |
int i; |
| 40 |
< |
/* get full display program name */ |
| 38 |
> |
char buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn; |
| 39 |
> |
int i, n, len; |
| 40 |
> |
|
| 41 |
> |
if (!strcmp(dname, SLAVENAME)) { |
| 42 |
> |
dpd.r = 0; /* read from stdin */ |
| 43 |
> |
dpout = stdout; /* write to stdout */ |
| 44 |
> |
dpd.running = 0; /* we're the slave procees */ |
| 45 |
> |
} else { |
| 46 |
> |
/* get full display program name */ |
| 47 |
|
#ifdef DEVPATH |
| 48 |
< |
sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF); |
| 48 |
> |
sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF); |
| 49 |
|
#else |
| 50 |
< |
sprintf(dpath, "dev/%s%s", dname, HDSUF); |
| 50 |
> |
sprintf(buf, "dev/%s%s", dname, HDSUF); |
| 51 |
|
#endif |
| 52 |
< |
/* dup stdin and stdout */ |
| 53 |
< |
if (readinp) |
| 54 |
< |
sprintf(fd0, "%d", dup(0)); |
| 55 |
< |
else |
| 56 |
< |
strcpy(fd0, "-1"); |
| 57 |
< |
sprintf(fd1, "%d", dup(1)); |
| 58 |
< |
/* start the display process */ |
| 59 |
< |
cmd[0] = dpath; |
| 60 |
< |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
| 61 |
< |
cmd[4] = NULL; |
| 62 |
< |
i = open_process(dpd, cmd); |
| 63 |
< |
if (i <= 0) |
| 64 |
< |
error(USER, "cannot start display process"); |
| 65 |
< |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
| 66 |
< |
error(SYSTEM, "cannot associate FILE with display pipe"); |
| 67 |
< |
dpd[1] = -1; /* causes ignored error in close_process() */ |
| 52 |
> |
/* dup stdin and stdout */ |
| 53 |
> |
if (readinp) |
| 54 |
> |
sprintf(fd0, "%d", dup(0)); |
| 55 |
> |
else |
| 56 |
> |
strcpy(fd0, "-1"); |
| 57 |
> |
sprintf(fd1, "%d", dup(1)); |
| 58 |
> |
/* start the display process */ |
| 59 |
> |
cmd[0] = buf; |
| 60 |
> |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
| 61 |
> |
cmd[4] = NULL; |
| 62 |
> |
i = open_process(&dpd, cmd); |
| 63 |
> |
if (i <= 0) |
| 64 |
> |
error(USER, "cannot start display process"); |
| 65 |
> |
if ((dpout = fdopen(dpd.w, "w")) == NULL) |
| 66 |
> |
error(SYSTEM, "problem opening display pipe"); |
| 67 |
> |
/* close dup'ed stdin and stdout */ |
| 68 |
> |
if (readinp) |
| 69 |
> |
close(atoi(fd0)); |
| 70 |
> |
close(atoi(fd1)); |
| 71 |
> |
} |
| 72 |
> |
dpd.w = -1; /* causes ignored error in close_process() */ |
| 73 |
|
inp_flags = 0; |
| 74 |
< |
/* close dup'ed stdin and stdout */ |
| 75 |
< |
if (readinp) |
| 76 |
< |
close(atoi(fd0)); |
| 77 |
< |
close(atoi(fd1)); |
| 78 |
< |
/* write out hologram grids */ |
| 79 |
< |
for (i = 0; hdlist[i] != NULL; i++) |
| 80 |
< |
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
| 74 |
> |
/* check if outside */ |
| 75 |
> |
if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) |
| 76 |
> |
disp_result(DS_OUTSECT, 0, NULL); |
| 77 |
> |
/* send eye separation if specified */ |
| 78 |
> |
if (vdef(EYESEP)) { |
| 79 |
> |
sprintf(buf, "%.9e", vflt(EYESEP)); |
| 80 |
> |
disp_result(DS_EYESEP, strlen(buf)+1, buf); |
| 81 |
> |
} |
| 82 |
> |
/* write out hologram grids & octrees */ |
| 83 |
> |
for (i = 0; hdlist[i] != NULL; i++) { |
| 84 |
> |
memcpy(buf, (void *)hdlist[i], sizeof(HDGRID)); |
| 85 |
> |
len = sizeof(HDGRID); |
| 86 |
> |
n = vdef(GEOMETRY); |
| 87 |
> |
sfn = i<n ? nvalue(GEOMETRY,i) : |
| 88 |
> |
n ? nvalue(GEOMETRY,n-1) : vval(OCTREE); |
| 89 |
> |
strcpy(buf+len, sfn); |
| 90 |
> |
len += strlen(sfn) + 1; |
| 91 |
> |
n = vdef(PORTS); |
| 92 |
> |
sfn = i<n ? nvalue(PORTS,i) : n ? nvalue(PORTS,n-1) : ""; |
| 93 |
> |
strcpy(buf+len, sfn); |
| 94 |
> |
len += strlen(sfn) + 1; |
| 95 |
> |
disp_result(DS_ADDHOLO, len, buf); |
| 96 |
> |
} |
| 97 |
|
disp_flush(); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
< |
disp_packet(p) /* display a packet */ |
| 102 |
< |
register PACKHEAD *p; |
| 101 |
> |
extern void |
| 102 |
> |
disp_packet( /* display a packet */ |
| 103 |
> |
register PACKHEAD *p |
| 104 |
> |
) |
| 105 |
|
{ |
| 106 |
|
disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
< |
disp_check(block) /* check display process */ |
| 111 |
< |
int block; |
| 110 |
> |
extern int |
| 111 |
> |
disp_check( /* check display process */ |
| 112 |
> |
int block |
| 113 |
> |
) |
| 114 |
|
{ |
| 115 |
|
MSGHEAD msg; |
| 116 |
|
int n; |
| 123 |
|
/* check read blocking */ |
| 124 |
|
if (block != (inp_flags == 0)) { |
| 125 |
|
inp_flags = block ? 0 : FNONBLK; |
| 126 |
< |
if (fcntl(dpd[0], F_SETFL, inp_flags) < 0) |
| 126 |
> |
if (fcntl(dpd.r, F_SETFL, inp_flags) < 0) |
| 127 |
|
goto fcntlerr; |
| 128 |
|
} |
| 129 |
|
/* read message header */ |
| 130 |
< |
n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD)); |
| 130 |
> |
n = read(dpd.r, (char *)&msg, sizeof(MSGHEAD)); |
| 131 |
|
if (n != sizeof(MSGHEAD)) { |
| 132 |
|
if (n >= 0) { |
| 133 |
|
dpout = NULL; |
| 134 |
|
error(USER, "display process died"); |
| 135 |
|
} |
| 136 |
< |
if (errno != EAGAIN & errno != EINTR) |
| 136 |
> |
if ((errno != EAGAIN) & (errno != EINTR)) |
| 137 |
|
goto readerr; |
| 138 |
|
return(2); /* acceptable failure */ |
| 139 |
|
} |
| 140 |
|
if (msg.nbytes) { /* get the message body */ |
| 141 |
+ |
if (msg.nbytes < 0) |
| 142 |
+ |
error(INTERNAL, "anti-message from display process"); |
| 143 |
|
buf = (char *)malloc(msg.nbytes); |
| 144 |
|
if (buf == NULL) |
| 145 |
|
error(SYSTEM, "out of memory in disp_check"); |
| 146 |
< |
if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
| 146 |
> |
if (inp_flags != 0 && fcntl(dpd.r, F_SETFL, inp_flags=0) < 0) |
| 147 |
|
goto fcntlerr; |
| 148 |
< |
if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) |
| 148 |
> |
if (readbuf(dpd.r, buf, msg.nbytes) != msg.nbytes) |
| 149 |
|
goto readerr; |
| 150 |
|
} |
| 151 |
|
switch (msg.type) { /* take appropriate action */ |
| 157 |
|
case DR_NEWSET: /* new calculation set */ |
| 158 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
| 159 |
|
error(INTERNAL, "bad DR_NEWSET from display process"); |
| 160 |
< |
disp_result(DS_STARTIMM, 0, NULL); |
| 160 |
> |
if (msg.nbytes) |
| 161 |
> |
disp_result(DS_STARTIMM, 0, NULL); |
| 162 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
| 163 |
< |
disp_result(DS_ENDIMM, 0, NULL); |
| 164 |
< |
disp_flush(); |
| 163 |
> |
if (msg.nbytes) { |
| 164 |
> |
disp_result(DS_ENDIMM, 0, NULL); |
| 165 |
> |
disp_flush(); |
| 166 |
> |
} |
| 167 |
|
break; |
| 168 |
|
case DR_ADDSET: /* add to calculation set */ |
| 169 |
+ |
if (!msg.nbytes) |
| 170 |
+ |
break; |
| 171 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
| 172 |
|
error(INTERNAL, "bad DR_ADDSET from display process"); |
| 173 |
|
disp_result(DS_STARTIMM, 0, NULL); |
| 176 |
|
disp_flush(); |
| 177 |
|
break; |
| 178 |
|
case DR_ADJSET: /* adjust calculation set members */ |
| 179 |
+ |
if (!msg.nbytes) |
| 180 |
+ |
break; |
| 181 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
| 182 |
|
error(INTERNAL, "bad DR_ADJSET from display process"); |
| 183 |
|
disp_result(DS_STARTIMM, 0, NULL); |
| 186 |
|
disp_flush(); |
| 187 |
|
break; |
| 188 |
|
case DR_DELSET: /* delete from calculation set */ |
| 189 |
+ |
if (!msg.nbytes) |
| 190 |
+ |
break; |
| 191 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
| 192 |
|
error(INTERNAL, "bad DR_DELSET from display process"); |
| 193 |
|
bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
| 194 |
|
break; |
| 195 |
+ |
case DR_VIEWPOINT: /* set target eye position */ |
| 196 |
+ |
if (msg.nbytes != sizeof(VIEWPOINT)) |
| 197 |
+ |
error(INTERNAL, "bad DR_VIEWPOINT from display process"); |
| 198 |
+ |
myeye = *((VIEWPOINT *)buf); |
| 199 |
+ |
break; |
| 200 |
|
case DR_ATTEN: /* block for priority request */ |
| 201 |
|
if (msg.nbytes) |
| 202 |
|
error(INTERNAL, "bad DR_ATTEN from display process"); |
| 224 |
|
case DR_CLOBBER: /* clobber holodeck */ |
| 225 |
|
if (msg.nbytes) |
| 226 |
|
error(INTERNAL, "bad DR_CLOBBER from display process"); |
| 227 |
< |
if (!force || !ncprocs) |
| 227 |
> |
if ((force <= 0) | (ncprocs <= 0)) |
| 228 |
|
error(WARNING, "request to clobber holodeck denied"); |
| 229 |
|
else { |
| 230 |
|
error(WARNING, "clobbering holodeck contents"); |
| 247 |
|
error(SYSTEM, "cannot change display blocking mode"); |
| 248 |
|
readerr: |
| 249 |
|
error(SYSTEM, "error reading from display process"); |
| 250 |
+ |
return -1; /* pro forma return */ |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
|
| 254 |
< |
int |
| 255 |
< |
disp_close() /* close our display process */ |
| 254 |
> |
extern int |
| 255 |
> |
disp_close(void) /* close our display process */ |
| 256 |
|
{ |
| 198 |
– |
int rval; |
| 199 |
– |
|
| 257 |
|
if (dpout == NULL) |
| 258 |
|
return(-1); |
| 259 |
+ |
myeye.rng = 0; |
| 260 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
| 261 |
|
fclose(dpout); |
| 262 |
|
dpout = NULL; |
| 263 |
< |
return(close_process(dpd)); |
| 263 |
> |
return(dpd.running ? close_process(&dpd) : 0); |
| 264 |
> |
|
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
|
| 268 |
< |
disp_result(type, nbytes, p) /* queue result message to display process */ |
| 269 |
< |
int type, nbytes; |
| 270 |
< |
char *p; |
| 268 |
> |
static void |
| 269 |
> |
disp_result( /* queue result message to display process */ |
| 270 |
> |
int type, |
| 271 |
> |
int nbytes, |
| 272 |
> |
char *p |
| 273 |
> |
) |
| 274 |
|
{ |
| 275 |
|
MSGHEAD msg; |
| 276 |
< |
|
| 276 |
> |
/* consistency checks */ |
| 277 |
> |
#ifdef DEBUG |
| 278 |
> |
if (nbytes < 0 || nbytes > 0 & p == NULL) |
| 279 |
> |
error(CONSISTENCY, "bad buffer handed to disp_result"); |
| 280 |
> |
#endif |
| 281 |
|
if (dpout == NULL) |
| 282 |
|
return; |
| 283 |
|
msg.type = type; |
| 288 |
|
} |
| 289 |
|
|
| 290 |
|
|
| 291 |
< |
disp_flush() /* flush output to display */ |
| 291 |
> |
static void |
| 292 |
> |
disp_flush(void) /* flush output to display */ |
| 293 |
|
{ |
| 294 |
|
if (fflush(dpout) < 0) |
| 295 |
|
error(SYSTEM, "error writing to the display process"); |