ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo4.c
(Generate patch)

Comparing ray/src/hd/rholo4.c (file contents):
Revision 3.2 by gregl, Mon Nov 3 18:33:14 1997 UTC vs.
Revision 3.18 by gwlarson, Fri May 22 08:30:41 1998 UTC

# Line 13 | Line 13 | 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   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], fd0[8], fd1[8], *cmd[5];
28          int     i;
29 <
29 >                                /* get full display program name */
30   #ifdef DEVPATH
31          sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF);
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 >                                /* dup stdin and stdout */
36 >        if (readinp)
37 >                sprintf(fd0, "%d", dup(0));
38 >        else
39 >                strcpy(fd0, "-1");
40 >        sprintf(fd1, "%d", dup(1));
41 >                                /* start the display process */
42 >        cmd[0] = dpath;
43 >        cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
44 >        cmd[4] = NULL;
45 >        i = open_process(dpd, cmd);
46 >        if (i <= 0)
47                  error(USER, "cannot start display process");
48 +        if ((dpout = fdopen(dpd[1], "w")) == NULL)
49 +                error(SYSTEM, "cannot associate FILE with display pipe");
50 +        dpd[1] = -1;            /* causes ignored error in close_process() */
51          inp_flags = 0;
52 +                                /* close dup'ed stdin and stdout */
53 +        if (readinp)
54 +                close(atoi(fd0));
55 +        close(atoi(fd1));
56 +                                /* check if outside */
57 +        if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS))
58 +                disp_result(DS_OUTSECT, 0, NULL);
59 +                                /* send eye separation if specified */
60 +        if (vdef(EYESEP)) {
61 +                char    fbuf[32];
62 +                sprintf(fbuf, "%.9e", vflt(EYESEP));
63 +                disp_result(DS_EYESEP, strlen(fbuf)+1, fbuf);
64 +        }
65                                  /* write out hologram grids */
66          for (i = 0; hdlist[i] != NULL; i++)
67                  disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
68 +        disp_flush();
69   }
70  
71  
72   disp_packet(p)                  /* display a packet */
73 < register PACKET *p;
73 > register PACKHEAD       *p;
74   {
75 <        if (pipesiz <= 0)
50 <                return;
51 <        disp_result(DS_BUNDLE, sizeof(PACKHEAD) + p->nr*sizeof(RAYVAL),
52 <                        (char *)p);
75 >        disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
76   }
77  
78  
# Line 60 | Line 83 | int    block;
83          int     n;
84          char    *buf = NULL;
85  
86 <        if (pipesiz <= 0)
86 >        if (dpout == NULL)
87                  return(-1);
88 < restart:                                /* check read blocking */
88 >                                        /* flush display output */
89 >        disp_flush();
90 >                                        /* check read blocking */
91          if (block != (inp_flags == 0)) {
92                  inp_flags = block ? 0 : FNONBLK;
93                  if (fcntl(dpd[0], F_SETFL, inp_flags) < 0)
# Line 71 | Line 96 | restart:                               /* check read blocking */
96                                          /* read message header */
97          n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD));
98          if (n != sizeof(MSGHEAD)) {
99 <                if (n >= 0)
99 >                if (n >= 0) {
100 >                        dpout = NULL;
101                          error(USER, "display process died");
102 +                }
103                  if (errno != EAGAIN & errno != EINTR)
104                          goto readerr;
105 <                return(2);              /* else acceptable failure */
105 >                return(2);              /* acceptable failure */
106          }
107          if (msg.nbytes) {               /* get the message body */
108                  buf = (char *)malloc(msg.nbytes);
# Line 87 | Line 114 | restart:                               /* check read blocking */
114                          goto readerr;
115          }
116          switch (msg.type) {             /* take appropriate action */
117 <        case DR_BUNDLE:
117 >        case DR_BUNDLE:         /* new bundle to calculate */
118                  if (msg.nbytes != sizeof(PACKHEAD))
119                          error(INTERNAL, "bad DR_BUNDLE from display process");
120                  bundle_set(BS_ADD, (PACKHEAD *)buf, 1);
121                  break;
122 <        case DR_NEWSET:
122 >        case DR_NEWSET:         /* new calculation set */
123                  if (msg.nbytes % sizeof(PACKHEAD))
124                          error(INTERNAL, "bad DR_NEWSET from display process");
125                  disp_result(DS_STARTIMM, 0, NULL);
126                  bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
127                  disp_result(DS_ENDIMM, 0, NULL);
128 +                disp_flush();
129                  break;
130 <        case DR_ADDSET:
130 >        case DR_ADDSET:         /* add to calculation set */
131                  if (msg.nbytes % sizeof(PACKHEAD))
132                          error(INTERNAL, "bad DR_ADDSET from display process");
133                  disp_result(DS_STARTIMM, 0, NULL);
134                  bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
135                  disp_result(DS_ENDIMM, 0, NULL);
136 +                disp_flush();
137                  break;
138 <        case DR_DELSET:
138 >        case DR_ADJSET:         /* adjust calculation set members */
139                  if (msg.nbytes % sizeof(PACKHEAD))
140 +                        error(INTERNAL, "bad DR_ADJSET from display process");
141 +                disp_result(DS_STARTIMM, 0, NULL);
142 +                bundle_set(BS_ADJ, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
143 +                disp_result(DS_ENDIMM, 0, NULL);
144 +                disp_flush();
145 +                break;
146 +        case DR_DELSET:         /* delete from calculation set */
147 +                if (msg.nbytes % sizeof(PACKHEAD))
148                          error(INTERNAL, "bad DR_DELSET from display process");
149                  bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
150                  break;
151 <        case DR_ATTEN:
151 >        case DR_ATTEN:          /* block for priority request */
152                  if (msg.nbytes)
153                          error(INTERNAL, "bad DR_ATTEN from display process");
154                                          /* send acknowledgement */
155                  disp_result(DS_ACKNOW, 0, NULL);
156 <                block = 1;              /* block on following request */
157 <                goto restart;
121 <        case DR_SHUTDOWN:
156 >                return(disp_check(1));  /* block on following request */
157 >        case DR_KILL:           /* kill computation process(es) */
158                  if (msg.nbytes)
159 +                        error(INTERNAL, "bad DR_KILL from display process");
160 +                if (nprocs > 0)
161 +                        done_rtrace();
162 +                else
163 +                        error(WARNING, "no rtrace process to kill");
164 +                break;
165 +        case DR_RESTART:        /* restart computation process(es) */
166 +                if (msg.nbytes)
167 +                        error(INTERNAL, "bad DR_RESTART from display process");
168 +                if (ncprocs > nprocs)
169 +                        new_rtrace();
170 +                else if (nprocs > 0)
171 +                        error(WARNING, "rtrace already runnning");
172 +                else
173 +                        error(WARNING, "holodeck not open for writing");
174 +                break;
175 +        case DR_CLOBBER:        /* clobber holodeck */
176 +                if (msg.nbytes)
177 +                        error(INTERNAL, "bad DR_CLOBBER from display process");
178 +                if (!force || !ncprocs)
179 +                        error(WARNING, "request to clobber holodeck denied");
180 +                else {
181 +                        error(WARNING, "clobbering holodeck contents");
182 +                        hdclobber(NULL);
183 +                }
184 +                break;
185 +        case DR_SHUTDOWN:       /* shut down program */
186 +                if (msg.nbytes)
187                          error(INTERNAL, "bad DR_SHUTDOWN from display process");
188                  return(0);              /* zero return signals shutdown */
189 +        case DR_NOOP:           /* do nothing */
190 +                break;
191          default:
192                  error(INTERNAL, "unrecognized request from display process");
193          }
194 <        if (msg.nbytes)
194 >        if (msg.nbytes)                 /* clean up */
195                  free(buf);
196          return(1);                      /* normal return value */
197   fcntlerr:
# Line 140 | Line 206 | disp_close()                   /* close our display process */
206   {
207          int     rval;
208  
209 <        if (pipesiz <= 0)
209 >        if (dpout == NULL)
210                  return(-1);
211          disp_result(DS_SHUTDOWN, 0, NULL);
212 <        pipesiz = 0;
212 >        fclose(dpout);
213 >        dpout = NULL;
214          return(close_process(dpd));
215   }
216  
217  
218 < disp_result(type, nbytes, p)    /* send result message to display process */
218 > disp_result(type, nbytes, p)    /* queue result message to display process */
219   int     type, nbytes;
220   char    *p;
221   {
155        struct iovec    iov[2];
222          MSGHEAD msg;
157        int     n;
223  
224 +        if (dpout == NULL)
225 +                return;
226          msg.type = type;
227          msg.nbytes = nbytes;
228 <        if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) {
229 <                n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD));
230 <                if (n != sizeof(MSGHEAD))
231 <                        goto writerr;
232 <                if (nbytes > 0) {
233 <                        n = writebuf(dpd[1], p, nbytes);
234 <                        if (n != nbytes)
235 <                                goto writerr;
236 <                }
237 <                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");
228 >        fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout);
229 >        if (nbytes > 0)
230 >                fwrite(p, 1, nbytes, dpout);
231 > }
232 >
233 >
234 > disp_flush()                    /* flush output to display */
235 > {
236 >        if (fflush(dpout) < 0)
237 >                error(SYSTEM, "error writing to the display process");
238   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines