1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1999 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
13 |
|
#include <sys/uio.h> |
14 |
|
|
15 |
|
#ifndef HDSUF |
16 |
< |
#define HDSUF ".hdi" |
16 |
> |
#define HDSUF ".hdi" |
17 |
|
#endif |
18 |
+ |
#ifndef SLAVENAME |
19 |
+ |
#define SLAVENAME "slave" |
20 |
+ |
#endif |
21 |
|
|
22 |
+ |
#ifndef FNONBLK |
23 |
+ |
#define FNONBLK O_NONBLOCK |
24 |
+ |
#endif |
25 |
+ |
|
26 |
|
static int inp_flags; |
27 |
|
static int dpd[3]; |
28 |
|
static FILE *dpout; |
31 |
|
disp_open(dname) /* open the named display driver */ |
32 |
|
char *dname; |
33 |
|
{ |
34 |
< |
char dpath[128], fd0[8], fd1[8], *cmd[5]; |
35 |
< |
int i; |
36 |
< |
/* get full display program name */ |
34 |
> |
char buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn; |
35 |
> |
int i, n, len; |
36 |
> |
|
37 |
> |
if (!strcmp(dname, SLAVENAME)) { |
38 |
> |
dpd[0] = 0; /* read from stdin */ |
39 |
> |
dpout = stdout; /* write to stdout */ |
40 |
> |
dpd[2] = -1; /* we're the slave process */ |
41 |
> |
} else { |
42 |
> |
/* get full display program name */ |
43 |
|
#ifdef DEVPATH |
44 |
< |
sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF); |
44 |
> |
sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF); |
45 |
|
#else |
46 |
< |
sprintf(dpath, "dev/%s%s", dname, HDSUF); |
46 |
> |
sprintf(buf, "dev/%s%s", dname, HDSUF); |
47 |
|
#endif |
48 |
< |
/* dup stdin and stdout */ |
49 |
< |
if (readinp) |
50 |
< |
sprintf(fd0, "%d", dup(0)); |
51 |
< |
else |
52 |
< |
strcpy(fd0, "-1"); |
53 |
< |
sprintf(fd1, "%d", dup(1)); |
54 |
< |
/* start the display process */ |
55 |
< |
cmd[0] = dpath; |
56 |
< |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
57 |
< |
cmd[4] = NULL; |
58 |
< |
i = open_process(dpd, cmd); |
59 |
< |
if (i <= 0) |
60 |
< |
error(USER, "cannot start display process"); |
61 |
< |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
62 |
< |
error(SYSTEM, "cannot associate FILE with display pipe"); |
48 |
> |
/* dup stdin and stdout */ |
49 |
> |
if (readinp) |
50 |
> |
sprintf(fd0, "%d", dup(0)); |
51 |
> |
else |
52 |
> |
strcpy(fd0, "-1"); |
53 |
> |
sprintf(fd1, "%d", dup(1)); |
54 |
> |
/* start the display process */ |
55 |
> |
cmd[0] = buf; |
56 |
> |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
57 |
> |
cmd[4] = NULL; |
58 |
> |
i = open_process(dpd, cmd); |
59 |
> |
if (i <= 0) |
60 |
> |
error(USER, "cannot start display process"); |
61 |
> |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
62 |
> |
error(SYSTEM, "problem opening display pipe"); |
63 |
> |
/* close dup'ed stdin and stdout */ |
64 |
> |
if (readinp) |
65 |
> |
close(atoi(fd0)); |
66 |
> |
close(atoi(fd1)); |
67 |
> |
} |
68 |
|
dpd[1] = -1; /* causes ignored error in close_process() */ |
69 |
|
inp_flags = 0; |
70 |
< |
/* close dup'ed stdin and stdout */ |
71 |
< |
if (readinp) |
72 |
< |
close(atoi(fd0)); |
73 |
< |
close(atoi(fd1)); |
74 |
< |
/* write out hologram grids */ |
75 |
< |
for (i = 0; hdlist[i] != NULL; i++) |
76 |
< |
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
70 |
> |
/* check if outside */ |
71 |
> |
if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) |
72 |
> |
disp_result(DS_OUTSECT, 0, NULL); |
73 |
> |
/* send eye separation if specified */ |
74 |
> |
if (vdef(EYESEP)) { |
75 |
> |
sprintf(buf, "%.9e", vflt(EYESEP)); |
76 |
> |
disp_result(DS_EYESEP, strlen(buf)+1, buf); |
77 |
> |
} |
78 |
> |
/* write out hologram grids & octrees */ |
79 |
> |
for (i = 0; hdlist[i] != NULL; i++) { |
80 |
> |
bcopy((char *)hdlist[i], buf, sizeof(HDGRID)); |
81 |
> |
len = sizeof(HDGRID); |
82 |
> |
n = vdef(GEOMETRY); |
83 |
> |
sfn = i<n ? nvalue(GEOMETRY,i) : |
84 |
> |
n ? nvalue(GEOMETRY,n-1) : vval(OCTREE); |
85 |
> |
strcpy(buf+len, sfn); |
86 |
> |
len += strlen(sfn) + 1; |
87 |
> |
n = vdef(PORTS); |
88 |
> |
sfn = i<n ? nvalue(PORTS,i) : n ? nvalue(PORTS,n-1) : ""; |
89 |
> |
strcpy(buf+len, sfn); |
90 |
> |
len += strlen(sfn) + 1; |
91 |
> |
disp_result(DS_ADDHOLO, len, buf); |
92 |
> |
} |
93 |
|
disp_flush(); |
94 |
|
} |
95 |
|
|
130 |
|
return(2); /* acceptable failure */ |
131 |
|
} |
132 |
|
if (msg.nbytes) { /* get the message body */ |
133 |
+ |
if (msg.nbytes < 0) |
134 |
+ |
error(INTERNAL, "anti-message from display process"); |
135 |
|
buf = (char *)malloc(msg.nbytes); |
136 |
|
if (buf == NULL) |
137 |
|
error(SYSTEM, "out of memory in disp_check"); |
138 |
< |
if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
138 |
> |
if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
139 |
|
goto fcntlerr; |
140 |
|
if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) |
141 |
|
goto readerr; |
149 |
|
case DR_NEWSET: /* new calculation set */ |
150 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
151 |
|
error(INTERNAL, "bad DR_NEWSET from display process"); |
152 |
< |
disp_result(DS_STARTIMM, 0, NULL); |
152 |
> |
if (msg.nbytes) |
153 |
> |
disp_result(DS_STARTIMM, 0, NULL); |
154 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
155 |
< |
disp_result(DS_ENDIMM, 0, NULL); |
156 |
< |
disp_flush(); |
155 |
> |
if (msg.nbytes) { |
156 |
> |
disp_result(DS_ENDIMM, 0, NULL); |
157 |
> |
disp_flush(); |
158 |
> |
} |
159 |
|
break; |
160 |
|
case DR_ADDSET: /* add to calculation set */ |
161 |
+ |
if (!msg.nbytes) |
162 |
+ |
break; |
163 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
164 |
|
error(INTERNAL, "bad DR_ADDSET from display process"); |
165 |
|
disp_result(DS_STARTIMM, 0, NULL); |
168 |
|
disp_flush(); |
169 |
|
break; |
170 |
|
case DR_ADJSET: /* adjust calculation set members */ |
171 |
+ |
if (!msg.nbytes) |
172 |
+ |
break; |
173 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
174 |
|
error(INTERNAL, "bad DR_ADJSET from display process"); |
175 |
|
disp_result(DS_STARTIMM, 0, NULL); |
178 |
|
disp_flush(); |
179 |
|
break; |
180 |
|
case DR_DELSET: /* delete from calculation set */ |
181 |
+ |
if (!msg.nbytes) |
182 |
+ |
break; |
183 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
184 |
|
error(INTERNAL, "bad DR_DELSET from display process"); |
185 |
|
bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
186 |
|
break; |
187 |
+ |
case DR_VIEWPOINT: /* set target eye position */ |
188 |
+ |
if (msg.nbytes != sizeof(VIEWPOINT)) |
189 |
+ |
error(INTERNAL, "bad DR_VIEWPOINT from display process"); |
190 |
+ |
copystruct(&myeye, (VIEWPOINT *)buf); |
191 |
+ |
break; |
192 |
|
case DR_ATTEN: /* block for priority request */ |
193 |
|
if (msg.nbytes) |
194 |
|
error(INTERNAL, "bad DR_ATTEN from display process"); |
216 |
|
case DR_CLOBBER: /* clobber holodeck */ |
217 |
|
if (msg.nbytes) |
218 |
|
error(INTERNAL, "bad DR_CLOBBER from display process"); |
219 |
< |
if (!force || !ncprocs) |
219 |
> |
if (force <= 0 | ncprocs <= 0) |
220 |
|
error(WARNING, "request to clobber holodeck denied"); |
221 |
|
else { |
222 |
|
error(WARNING, "clobbering holodeck contents"); |
249 |
|
|
250 |
|
if (dpout == NULL) |
251 |
|
return(-1); |
252 |
+ |
myeye.rng = 0; |
253 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
254 |
|
fclose(dpout); |
255 |
|
dpout = NULL; |
256 |
< |
return(close_process(dpd)); |
256 |
> |
return(dpd[2]<0 ? 0 : close_process(dpd)); |
257 |
|
} |
258 |
|
|
259 |
|
|
262 |
|
char *p; |
263 |
|
{ |
264 |
|
MSGHEAD msg; |
265 |
< |
|
265 |
> |
/* consistency checks */ |
266 |
> |
#ifdef DEBUG |
267 |
> |
if (nbytes < 0 || nbytes > 0 & p == NULL) |
268 |
> |
error(CONSISTENCY, "bad buffer handed to disp_result"); |
269 |
> |
#endif |
270 |
|
if (dpout == NULL) |
271 |
|
return; |
272 |
|
msg.type = type; |