1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
1 |
> |
/* Copyright (c) 1998 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], fd0[8], fd1[8], *cmd[5]; |
32 |
< |
int i; |
31 |
> |
char buf[128], fd0[8], fd1[8], *cmd[5], *ofn; |
32 |
> |
int i, n; |
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 |
|
/* dup stdin and stdout */ |
40 |
|
if (readinp) |
43 |
|
strcpy(fd0, "-1"); |
44 |
|
sprintf(fd1, "%d", dup(1)); |
45 |
|
/* start the display process */ |
46 |
< |
cmd[0] = dpath; |
46 |
> |
cmd[0] = buf; |
47 |
|
cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0; |
48 |
|
cmd[4] = NULL; |
49 |
|
i = open_process(dpd, cmd); |
57 |
|
if (readinp) |
58 |
|
close(atoi(fd0)); |
59 |
|
close(atoi(fd1)); |
60 |
< |
/* write out hologram grids */ |
61 |
< |
for (i = 0; hdlist[i] != NULL; i++) |
62 |
< |
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
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 |
> |
n = vdef(OSECTION); |
72 |
> |
ofn = i<n ? nvalue(OSECTION,i) : |
73 |
> |
n ? nvalue(OSECTION,n-1) : vval(OCTREE); |
74 |
> |
strcpy(buf+sizeof(HDGRID), ofn); |
75 |
> |
disp_result(DS_ADDHOLO, sizeof(HDGRID)+1+strlen(ofn), buf); |
76 |
> |
} |
77 |
|
disp_flush(); |
78 |
|
} |
79 |
|
|
114 |
|
return(2); /* acceptable failure */ |
115 |
|
} |
116 |
|
if (msg.nbytes) { /* get the message body */ |
117 |
+ |
if (msg.nbytes < 0) |
118 |
+ |
error(INTERNAL, "anti-message from display process"); |
119 |
|
buf = (char *)malloc(msg.nbytes); |
120 |
|
if (buf == NULL) |
121 |
|
error(SYSTEM, "out of memory in disp_check"); |
122 |
< |
if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
122 |
> |
if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0) |
123 |
|
goto fcntlerr; |
124 |
|
if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes) |
125 |
|
goto readerr; |
133 |
|
case DR_NEWSET: /* new calculation set */ |
134 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
135 |
|
error(INTERNAL, "bad DR_NEWSET from display process"); |
136 |
< |
disp_result(DS_STARTIMM, 0, NULL); |
136 |
> |
if (msg.nbytes) |
137 |
> |
disp_result(DS_STARTIMM, 0, NULL); |
138 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
139 |
< |
disp_result(DS_ENDIMM, 0, NULL); |
140 |
< |
disp_flush(); |
139 |
> |
if (msg.nbytes) { |
140 |
> |
disp_result(DS_ENDIMM, 0, NULL); |
141 |
> |
disp_flush(); |
142 |
> |
} |
143 |
|
break; |
144 |
|
case DR_ADDSET: /* add to calculation set */ |
145 |
+ |
if (!msg.nbytes) |
146 |
+ |
break; |
147 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
148 |
|
error(INTERNAL, "bad DR_ADDSET from display process"); |
149 |
|
disp_result(DS_STARTIMM, 0, NULL); |
150 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
151 |
|
disp_result(DS_ENDIMM, 0, NULL); |
152 |
< |
disp_check(0); /* hack -- delete usu. follows add */ |
152 |
> |
disp_flush(); |
153 |
|
break; |
154 |
|
case DR_ADJSET: /* adjust calculation set members */ |
155 |
+ |
if (!msg.nbytes) |
156 |
+ |
break; |
157 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
158 |
|
error(INTERNAL, "bad DR_ADJSET from display process"); |
159 |
|
disp_result(DS_STARTIMM, 0, NULL); |
162 |
|
disp_flush(); |
163 |
|
break; |
164 |
|
case DR_DELSET: /* delete from calculation set */ |
165 |
+ |
if (!msg.nbytes) |
166 |
+ |
break; |
167 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
168 |
|
error(INTERNAL, "bad DR_DELSET from display process"); |
169 |
|
bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
170 |
|
break; |
171 |
+ |
case DR_VIEWPOINT: /* set target eye position */ |
172 |
+ |
if (msg.nbytes != sizeof(VIEWPOINT)) |
173 |
+ |
error(INTERNAL, "bad DR_VIEWPOINT from display process"); |
174 |
+ |
copystruct(&myeye, (VIEWPOINT *)buf); |
175 |
+ |
break; |
176 |
|
case DR_ATTEN: /* block for priority request */ |
177 |
|
if (msg.nbytes) |
178 |
|
error(INTERNAL, "bad DR_ATTEN from display process"); |
182 |
|
case DR_KILL: /* kill computation process(es) */ |
183 |
|
if (msg.nbytes) |
184 |
|
error(INTERNAL, "bad DR_KILL from display process"); |
185 |
< |
if (nprocs > 0) { |
186 |
< |
done_packets(flush_queue()); |
187 |
< |
if (end_rtrace()) |
154 |
< |
error(WARNING, "bad status returned by rtrace"); |
155 |
< |
} else |
185 |
> |
if (nprocs > 0) |
186 |
> |
done_rtrace(); |
187 |
> |
else |
188 |
|
error(WARNING, "no rtrace process to kill"); |
189 |
|
break; |
190 |
|
case DR_RESTART: /* restart computation process(es) */ |
191 |
|
if (msg.nbytes) |
192 |
|
error(INTERNAL, "bad DR_RESTART from display process"); |
193 |
< |
if (ncprocs > nprocs) { |
194 |
< |
checkrad(); |
195 |
< |
if (start_rtrace() < 1) |
164 |
< |
error(WARNING, "cannot restart rtrace"); |
165 |
< |
} else if (nprocs > 0) |
193 |
> |
if (ncprocs > nprocs) |
194 |
> |
new_rtrace(); |
195 |
> |
else if (nprocs > 0) |
196 |
|
error(WARNING, "rtrace already runnning"); |
197 |
|
else |
198 |
|
error(WARNING, "holodeck not open for writing"); |
233 |
|
|
234 |
|
if (dpout == NULL) |
235 |
|
return(-1); |
236 |
+ |
myeye.rng = 0; |
237 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
238 |
|
fclose(dpout); |
239 |
|
dpout = NULL; |
246 |
|
char *p; |
247 |
|
{ |
248 |
|
MSGHEAD msg; |
249 |
< |
|
249 |
> |
/* consistency checks */ |
250 |
> |
#ifdef DEBUG |
251 |
> |
if (nbytes < 0 || nbytes > 0 & p == NULL) |
252 |
> |
error(CONSISTENCY, "bad buffer handed to disp_result"); |
253 |
> |
#endif |
254 |
|
if (dpout == NULL) |
255 |
|
return; |
256 |
|
msg.type = type; |