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 ".hdisp" |
16 |
> |
#define HDSUF ".hdi" |
17 |
|
#endif |
18 |
|
|
19 |
+ |
#ifndef FNONBLK |
20 |
+ |
#define FNONBLK O_NONBLOCK |
21 |
+ |
#endif |
22 |
+ |
|
23 |
|
static int inp_flags; |
24 |
|
static int dpd[3]; |
25 |
|
static FILE *dpout; |
28 |
|
disp_open(dname) /* open the named display driver */ |
29 |
|
char *dname; |
30 |
|
{ |
31 |
< |
char dpath[128], *com[3]; |
32 |
< |
int i; |
33 |
< |
|
31 |
> |
char buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn; |
32 |
> |
int i, n, len; |
33 |
> |
/* get full display program name */ |
34 |
|
#ifdef DEVPATH |
35 |
< |
sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF); |
35 |
> |
sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF); |
36 |
|
#else |
37 |
< |
sprintf(dpath, "dev/%s%s", dname, HDSUF); |
37 |
> |
sprintf(buf, "dev/%s%s", dname, HDSUF); |
38 |
|
#endif |
39 |
< |
com[0] = dpath; com[1] = froot; com[2] = NULL; |
40 |
< |
i = open_process(dpd, com); |
39 |
> |
/* dup stdin and stdout */ |
40 |
> |
if (readinp) |
41 |
> |
sprintf(fd0, "%d", dup(0)); |
42 |
> |
else |
43 |
> |
strcpy(fd0, "-1"); |
44 |
> |
sprintf(fd1, "%d", dup(1)); |
45 |
> |
/* start the display process */ |
46 |
> |
cmd[0] = buf; |
47 |
> |
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
48 |
> |
cmd[4] = NULL; |
49 |
> |
i = open_process(dpd, cmd); |
50 |
|
if (i <= 0) |
51 |
|
error(USER, "cannot start display process"); |
52 |
< |
if ((dpout = fdopen(dup(dpd[1]), "w")) == NULL) |
52 |
> |
if ((dpout = fdopen(dpd[1], "w")) == NULL) |
53 |
|
error(SYSTEM, "cannot associate FILE with display pipe"); |
54 |
+ |
dpd[1] = -1; /* causes ignored error in close_process() */ |
55 |
|
inp_flags = 0; |
56 |
< |
/* write out hologram grids */ |
57 |
< |
for (i = 0; hdlist[i] != NULL; i++) |
58 |
< |
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
56 |
> |
/* close dup'ed stdin and stdout */ |
57 |
> |
if (readinp) |
58 |
> |
close(atoi(fd0)); |
59 |
> |
close(atoi(fd1)); |
60 |
> |
/* check if outside */ |
61 |
> |
if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS)) |
62 |
> |
disp_result(DS_OUTSECT, 0, NULL); |
63 |
> |
/* send eye separation if specified */ |
64 |
> |
if (vdef(EYESEP)) { |
65 |
> |
sprintf(buf, "%.9e", vflt(EYESEP)); |
66 |
> |
disp_result(DS_EYESEP, strlen(buf)+1, buf); |
67 |
> |
} |
68 |
> |
/* write out hologram grids & octrees */ |
69 |
> |
for (i = 0; hdlist[i] != NULL; i++) { |
70 |
> |
bcopy((char *)hdlist[i], buf, sizeof(HDGRID)); |
71 |
> |
len = sizeof(HDGRID); |
72 |
> |
n = vdef(GEOMETRY); |
73 |
> |
sfn = i<n ? nvalue(GEOMETRY,i) : |
74 |
> |
n ? nvalue(GEOMETRY,n-1) : vval(OCTREE); |
75 |
> |
strcpy(buf+len, sfn); |
76 |
> |
len += strlen(sfn) + 1; |
77 |
> |
n = vdef(PORTS); |
78 |
> |
sfn = i<n ? nvalue(PORTS,i) : n ? nvalue(PORTS,n-1) : ""; |
79 |
> |
strcpy(buf+len, sfn); |
80 |
> |
len += strlen(sfn) + 1; |
81 |
> |
disp_result(DS_ADDHOLO, len, buf); |
82 |
> |
} |
83 |
|
disp_flush(); |
84 |
|
} |
85 |
|
|
120 |
|
return(2); /* acceptable failure */ |
121 |
|
} |
122 |
|
if (msg.nbytes) { /* get the message body */ |
123 |
+ |
if (msg.nbytes < 0) |
124 |
+ |
error(INTERNAL, "anti-message from display process"); |
125 |
|
buf = (char *)malloc(msg.nbytes); |
126 |
|
if (buf == NULL) |
127 |
|
error(SYSTEM, "out of memory in disp_check"); |
128 |
< |
if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
128 |
> |
if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
129 |
|
goto fcntlerr; |
130 |
|
if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) |
131 |
|
goto readerr; |
132 |
|
} |
133 |
|
switch (msg.type) { /* take appropriate action */ |
134 |
< |
case DR_BUNDLE: |
134 |
> |
case DR_BUNDLE: /* new bundle to calculate */ |
135 |
|
if (msg.nbytes != sizeof(PACKHEAD)) |
136 |
|
error(INTERNAL, "bad DR_BUNDLE from display process"); |
137 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, 1); |
138 |
|
break; |
139 |
< |
case DR_NEWSET: |
139 |
> |
case DR_NEWSET: /* new calculation set */ |
140 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
141 |
|
error(INTERNAL, "bad DR_NEWSET from display process"); |
142 |
< |
disp_result(DS_STARTIMM, 0, NULL); |
142 |
> |
if (msg.nbytes) |
143 |
> |
disp_result(DS_STARTIMM, 0, NULL); |
144 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
145 |
< |
disp_result(DS_ENDIMM, 0, NULL); |
146 |
< |
disp_flush(); |
145 |
> |
if (msg.nbytes) { |
146 |
> |
disp_result(DS_ENDIMM, 0, NULL); |
147 |
> |
disp_flush(); |
148 |
> |
} |
149 |
|
break; |
150 |
< |
case DR_ADDSET: |
150 |
> |
case DR_ADDSET: /* add to calculation set */ |
151 |
> |
if (!msg.nbytes) |
152 |
> |
break; |
153 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
154 |
|
error(INTERNAL, "bad DR_ADDSET from display process"); |
155 |
|
disp_result(DS_STARTIMM, 0, NULL); |
156 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
157 |
|
disp_result(DS_ENDIMM, 0, NULL); |
158 |
< |
disp_check(0); /* hack -- delete usu. follows add */ |
158 |
> |
disp_flush(); |
159 |
|
break; |
160 |
< |
case DR_ADJSET: |
160 |
> |
case DR_ADJSET: /* adjust calculation set members */ |
161 |
> |
if (!msg.nbytes) |
162 |
> |
break; |
163 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
164 |
|
error(INTERNAL, "bad DR_ADJSET from display process"); |
165 |
|
disp_result(DS_STARTIMM, 0, NULL); |
167 |
|
disp_result(DS_ENDIMM, 0, NULL); |
168 |
|
disp_flush(); |
169 |
|
break; |
170 |
< |
case DR_DELSET: |
170 |
> |
case DR_DELSET: /* delete from calculation set */ |
171 |
> |
if (!msg.nbytes) |
172 |
> |
break; |
173 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
174 |
|
error(INTERNAL, "bad DR_DELSET from display process"); |
175 |
|
bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
176 |
|
break; |
177 |
< |
case DR_ATTEN: |
177 |
> |
case DR_VIEWPOINT: /* set target eye position */ |
178 |
> |
if (msg.nbytes != sizeof(VIEWPOINT)) |
179 |
> |
error(INTERNAL, "bad DR_VIEWPOINT from display process"); |
180 |
> |
copystruct(&myeye, (VIEWPOINT *)buf); |
181 |
> |
break; |
182 |
> |
case DR_ATTEN: /* block for priority request */ |
183 |
|
if (msg.nbytes) |
184 |
|
error(INTERNAL, "bad DR_ATTEN from display process"); |
185 |
|
/* send acknowledgement */ |
186 |
|
disp_result(DS_ACKNOW, 0, NULL); |
187 |
|
return(disp_check(1)); /* block on following request */ |
188 |
< |
case DR_SHUTDOWN: |
188 |
> |
case DR_KILL: /* kill computation process(es) */ |
189 |
|
if (msg.nbytes) |
190 |
+ |
error(INTERNAL, "bad DR_KILL from display process"); |
191 |
+ |
if (nprocs > 0) |
192 |
+ |
done_rtrace(); |
193 |
+ |
else |
194 |
+ |
error(WARNING, "no rtrace process to kill"); |
195 |
+ |
break; |
196 |
+ |
case DR_RESTART: /* restart computation process(es) */ |
197 |
+ |
if (msg.nbytes) |
198 |
+ |
error(INTERNAL, "bad DR_RESTART from display process"); |
199 |
+ |
if (ncprocs > nprocs) |
200 |
+ |
new_rtrace(); |
201 |
+ |
else if (nprocs > 0) |
202 |
+ |
error(WARNING, "rtrace already runnning"); |
203 |
+ |
else |
204 |
+ |
error(WARNING, "holodeck not open for writing"); |
205 |
+ |
break; |
206 |
+ |
case DR_CLOBBER: /* clobber holodeck */ |
207 |
+ |
if (msg.nbytes) |
208 |
+ |
error(INTERNAL, "bad DR_CLOBBER from display process"); |
209 |
+ |
if (!force || !ncprocs) |
210 |
+ |
error(WARNING, "request to clobber holodeck denied"); |
211 |
+ |
else { |
212 |
+ |
error(WARNING, "clobbering holodeck contents"); |
213 |
+ |
hdclobber(NULL); |
214 |
+ |
} |
215 |
+ |
break; |
216 |
+ |
case DR_SHUTDOWN: /* shut down program */ |
217 |
+ |
if (msg.nbytes) |
218 |
|
error(INTERNAL, "bad DR_SHUTDOWN from display process"); |
219 |
|
return(0); /* zero return signals shutdown */ |
220 |
< |
case DR_NOOP: |
220 |
> |
case DR_NOOP: /* do nothing */ |
221 |
|
break; |
222 |
|
default: |
223 |
|
error(INTERNAL, "unrecognized request from display process"); |
239 |
|
|
240 |
|
if (dpout == NULL) |
241 |
|
return(-1); |
242 |
+ |
myeye.rng = 0; |
243 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
244 |
|
fclose(dpout); |
245 |
|
dpout = NULL; |
252 |
|
char *p; |
253 |
|
{ |
254 |
|
MSGHEAD msg; |
255 |
< |
|
255 |
> |
/* consistency checks */ |
256 |
> |
#ifdef DEBUG |
257 |
> |
if (nbytes < 0 || nbytes > 0 & p == NULL) |
258 |
> |
error(CONSISTENCY, "bad buffer handed to disp_result"); |
259 |
> |
#endif |
260 |
|
if (dpout == NULL) |
261 |
|
return; |
262 |
|
msg.type = type; |