18 |
|
|
19 |
|
static int inp_flags; |
20 |
|
static int dpd[3]; |
21 |
< |
static int pipesiz; |
21 |
> |
static FILE *dpout; |
22 |
|
|
23 |
|
|
24 |
|
disp_open(dname) /* open the named display driver */ |
25 |
|
char *dname; |
26 |
|
{ |
27 |
< |
char dpath[128], *com[2]; |
27 |
> |
char dpath[128], *com[3]; |
28 |
|
int i; |
29 |
|
|
30 |
|
#ifdef DEVPATH |
32 |
|
#else |
33 |
|
sprintf(dpath, "dev/%s%s", dname, HDSUF); |
34 |
|
#endif |
35 |
< |
com[0] = dpath; com[1] = NULL; |
36 |
< |
pipesiz = open_process(dpd, com); |
37 |
< |
if (pipesiz <= 0) |
35 |
> |
com[0] = dpath; com[1] = froot; com[2] = NULL; |
36 |
> |
i = open_process(dpd, com); |
37 |
> |
if (i <= 0) |
38 |
|
error(USER, "cannot start display process"); |
39 |
+ |
if ((dpout = fdopen(dup(dpd[1]), "w")) == NULL) |
40 |
+ |
error(SYSTEM, "cannot associate FILE with display pipe"); |
41 |
|
inp_flags = 0; |
42 |
|
/* write out hologram grids */ |
43 |
|
for (i = 0; hdlist[i] != NULL; i++) |
44 |
|
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
45 |
+ |
disp_flush(); |
46 |
|
} |
47 |
|
|
48 |
|
|
60 |
|
int n; |
61 |
|
char *buf = NULL; |
62 |
|
|
63 |
< |
if (pipesiz <= 0) |
63 |
> |
if (dpout == NULL) |
64 |
|
return(-1); |
65 |
+ |
/* flush display output */ |
66 |
+ |
disp_flush(); |
67 |
|
/* check read blocking */ |
68 |
|
if (block != (inp_flags == 0)) { |
69 |
|
inp_flags = block ? 0 : FNONBLK; |
100 |
|
disp_result(DS_STARTIMM, 0, NULL); |
101 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
102 |
|
disp_result(DS_ENDIMM, 0, NULL); |
103 |
+ |
disp_flush(); |
104 |
|
break; |
105 |
|
case DR_ADDSET: |
106 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
108 |
|
disp_result(DS_STARTIMM, 0, NULL); |
109 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
110 |
|
disp_result(DS_ENDIMM, 0, NULL); |
111 |
+ |
disp_flush(); |
112 |
|
break; |
113 |
|
case DR_DELSET: |
114 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
143 |
|
{ |
144 |
|
int rval; |
145 |
|
|
146 |
< |
if (pipesiz <= 0) |
146 |
> |
if (dpout == NULL) |
147 |
|
return(-1); |
148 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
149 |
< |
pipesiz = 0; |
149 |
> |
fclose(dpout); |
150 |
> |
dpout = NULL; |
151 |
|
return(close_process(dpd)); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
< |
disp_result(type, nbytes, p) /* send result message to display process */ |
155 |
> |
disp_result(type, nbytes, p) /* queue result message to display process */ |
156 |
|
int type, nbytes; |
157 |
|
char *p; |
158 |
|
{ |
151 |
– |
struct iovec iov[2]; |
159 |
|
MSGHEAD msg; |
153 |
– |
int n; |
160 |
|
|
161 |
< |
if (pipesiz <= 0) |
161 |
> |
if (dpout == NULL) |
162 |
|
return; |
163 |
|
msg.type = type; |
164 |
|
msg.nbytes = nbytes; |
165 |
< |
if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) { |
166 |
< |
do |
167 |
< |
n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD)); |
168 |
< |
while (n < 0 && errno == EINTR); |
169 |
< |
if (n != sizeof(MSGHEAD)) |
170 |
< |
goto writerr; |
171 |
< |
if (nbytes > 0 && writebuf(dpd[1], p, nbytes) != nbytes) |
172 |
< |
goto writerr; |
173 |
< |
return; |
174 |
< |
} |
169 |
< |
iov[0].iov_base = (char *)&msg; |
170 |
< |
iov[0].iov_len = sizeof(MSGHEAD); |
171 |
< |
iov[1].iov_base = p; |
172 |
< |
iov[1].iov_len = nbytes; |
173 |
< |
do |
174 |
< |
n = writev(dpd[1], iov, 2); |
175 |
< |
while (n < 0 && errno == EINTR); |
176 |
< |
if (n == sizeof(MSGHEAD)+nbytes) |
177 |
< |
return; |
178 |
< |
writerr: |
179 |
< |
error(SYSTEM, "write error in disp_result"); |
165 |
> |
fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout); |
166 |
> |
if (nbytes > 0) |
167 |
> |
fwrite(p, 1, nbytes, dpout); |
168 |
> |
} |
169 |
> |
|
170 |
> |
|
171 |
> |
disp_flush() /* flush output to display */ |
172 |
> |
{ |
173 |
> |
if (fflush(dpout) < 0) |
174 |
> |
error(SYSTEM, "error writing to the display process"); |
175 |
|
} |