| 19 |
|
static int inp_flags; |
| 20 |
|
static int dpd[3]; |
| 21 |
|
static int pipesiz; |
| 22 |
+ |
static FILE *dpout; |
| 23 |
|
|
| 24 |
|
|
| 25 |
|
disp_open(dname) /* open the named display driver */ |
| 26 |
|
char *dname; |
| 27 |
|
{ |
| 28 |
< |
char dpath[128], *com[2]; |
| 28 |
> |
char dpath[128], *com[3]; |
| 29 |
|
int i; |
| 30 |
|
|
| 31 |
|
#ifdef DEVPATH |
| 33 |
|
#else |
| 34 |
|
sprintf(dpath, "dev/%s%s", dname, HDSUF); |
| 35 |
|
#endif |
| 36 |
< |
com[0] = dpath; com[1] = NULL; |
| 36 |
> |
com[0] = dpath; com[1] = froot; com[2] = NULL; |
| 37 |
|
pipesiz = open_process(dpd, com); |
| 38 |
|
if (pipesiz <= 0) |
| 39 |
|
error(USER, "cannot start display process"); |
| 40 |
+ |
if ((dpout = fdopen(dup(dpd[1]), "w")) == NULL) |
| 41 |
+ |
error(SYSTEM, "cannot associate FILE with display pipe"); |
| 42 |
|
inp_flags = 0; |
| 43 |
|
/* write out hologram grids */ |
| 44 |
|
for (i = 0; hdlist[i] != NULL; i++) |
| 45 |
|
disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); |
| 46 |
+ |
disp_flush(); |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
disp_packet(p) /* display a packet */ |
| 51 |
< |
register PACKET *p; |
| 51 |
> |
register PACKHEAD *p; |
| 52 |
|
{ |
| 53 |
< |
if (pipesiz <= 0) |
| 50 |
< |
return; |
| 51 |
< |
disp_result(DS_BUNDLE, sizeof(PACKHEAD) + p->nr*sizeof(RAYVAL), |
| 52 |
< |
(char *)p); |
| 53 |
> |
disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 63 |
|
|
| 64 |
|
if (pipesiz <= 0) |
| 65 |
|
return(-1); |
| 66 |
< |
restart: /* check read blocking */ |
| 66 |
> |
/* flush display output */ |
| 67 |
> |
disp_flush(); |
| 68 |
> |
/* check read blocking */ |
| 69 |
|
if (block != (inp_flags == 0)) { |
| 70 |
|
inp_flags = block ? 0 : FNONBLK; |
| 71 |
|
if (fcntl(dpd[0], F_SETFL, inp_flags) < 0) |
| 78 |
|
error(USER, "display process died"); |
| 79 |
|
if (errno != EAGAIN & errno != EINTR) |
| 80 |
|
goto readerr; |
| 81 |
< |
return(2); /* else acceptable failure */ |
| 81 |
> |
return(2); /* acceptable failure */ |
| 82 |
|
} |
| 83 |
|
if (msg.nbytes) { /* get the message body */ |
| 84 |
|
buf = (char *)malloc(msg.nbytes); |
| 101 |
|
disp_result(DS_STARTIMM, 0, NULL); |
| 102 |
|
bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
| 103 |
|
disp_result(DS_ENDIMM, 0, NULL); |
| 104 |
+ |
disp_flush(); |
| 105 |
|
break; |
| 106 |
|
case DR_ADDSET: |
| 107 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
| 109 |
|
disp_result(DS_STARTIMM, 0, NULL); |
| 110 |
|
bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); |
| 111 |
|
disp_result(DS_ENDIMM, 0, NULL); |
| 112 |
+ |
disp_flush(); |
| 113 |
|
break; |
| 114 |
|
case DR_DELSET: |
| 115 |
|
if (msg.nbytes % sizeof(PACKHEAD)) |
| 121 |
|
error(INTERNAL, "bad DR_ATTEN from display process"); |
| 122 |
|
/* send acknowledgement */ |
| 123 |
|
disp_result(DS_ACKNOW, 0, NULL); |
| 124 |
< |
block = 1; /* block on following request */ |
| 120 |
< |
goto restart; |
| 124 |
> |
return(disp_check(1)); /* block on following request */ |
| 125 |
|
case DR_SHUTDOWN: |
| 126 |
|
if (msg.nbytes) |
| 127 |
|
error(INTERNAL, "bad DR_SHUTDOWN from display process"); |
| 129 |
|
default: |
| 130 |
|
error(INTERNAL, "unrecognized request from display process"); |
| 131 |
|
} |
| 132 |
< |
if (msg.nbytes) |
| 132 |
> |
if (msg.nbytes) /* clean up */ |
| 133 |
|
free(buf); |
| 134 |
|
return(1); /* normal return value */ |
| 135 |
|
fcntlerr: |
| 147 |
|
if (pipesiz <= 0) |
| 148 |
|
return(-1); |
| 149 |
|
disp_result(DS_SHUTDOWN, 0, NULL); |
| 150 |
+ |
fclose(dpout); |
| 151 |
+ |
dpout = NULL; |
| 152 |
|
pipesiz = 0; |
| 153 |
|
return(close_process(dpd)); |
| 154 |
|
} |
| 155 |
|
|
| 156 |
|
|
| 157 |
< |
disp_result(type, nbytes, p) /* send result message to display process */ |
| 157 |
> |
disp_result(type, nbytes, p) /* queue result message to display process */ |
| 158 |
|
int type, nbytes; |
| 159 |
|
char *p; |
| 160 |
|
{ |
| 155 |
– |
struct iovec iov[2]; |
| 161 |
|
MSGHEAD msg; |
| 157 |
– |
int n; |
| 162 |
|
|
| 163 |
|
msg.type = type; |
| 164 |
|
msg.nbytes = nbytes; |
| 165 |
< |
if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) { |
| 166 |
< |
n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD)); |
| 167 |
< |
if (n != sizeof(MSGHEAD)) |
| 168 |
< |
goto writerr; |
| 169 |
< |
if (nbytes > 0) { |
| 170 |
< |
n = writebuf(dpd[1], p, nbytes); |
| 171 |
< |
if (n != nbytes) |
| 172 |
< |
goto writerr; |
| 173 |
< |
} |
| 174 |
< |
return; |
| 171 |
< |
} |
| 172 |
< |
iov[0].iov_base = (char *)&msg; |
| 173 |
< |
iov[0].iov_len = sizeof(MSGHEAD); |
| 174 |
< |
iov[1].iov_base = p; |
| 175 |
< |
iov[1].iov_len = nbytes; |
| 176 |
< |
n = writev(dpd[1], iov, 2); |
| 177 |
< |
if (n == nbytes+sizeof(MSGHEAD)) |
| 178 |
< |
return; |
| 179 |
< |
writerr: |
| 180 |
< |
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 |
|
} |