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.17 by gregl, Sun Jan 4 18:37:11 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                                  /* write out hologram grids */
60          for (i = 0; hdlist[i] != NULL; i++)
61                  disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
62 +        disp_flush();
63   }
64  
65  
66   disp_packet(p)                  /* display a packet */
67 < register PACKET *p;
67 > register PACKHEAD       *p;
68   {
69 <        if (pipesiz <= 0)
50 <                return;
51 <        disp_result(DS_BUNDLE, sizeof(PACKHEAD) + p->nr*sizeof(RAYVAL),
52 <                        (char *)p);
69 >        disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
70   }
71  
72  
# Line 60 | Line 77 | int    block;
77          int     n;
78          char    *buf = NULL;
79  
80 <        if (pipesiz <= 0)
80 >        if (dpout == NULL)
81                  return(-1);
82 < restart:                                /* check read blocking */
82 >                                        /* flush display output */
83 >        disp_flush();
84 >                                        /* check read blocking */
85          if (block != (inp_flags == 0)) {
86                  inp_flags = block ? 0 : FNONBLK;
87                  if (fcntl(dpd[0], F_SETFL, inp_flags) < 0)
# Line 71 | Line 90 | restart:                               /* check read blocking */
90                                          /* read message header */
91          n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD));
92          if (n != sizeof(MSGHEAD)) {
93 <                if (n >= 0)
93 >                if (n >= 0) {
94 >                        dpout = NULL;
95                          error(USER, "display process died");
96 +                }
97                  if (errno != EAGAIN & errno != EINTR)
98                          goto readerr;
99 <                return(2);              /* else acceptable failure */
99 >                return(2);              /* acceptable failure */
100          }
101          if (msg.nbytes) {               /* get the message body */
102                  buf = (char *)malloc(msg.nbytes);
# Line 87 | Line 108 | restart:                               /* check read blocking */
108                          goto readerr;
109          }
110          switch (msg.type) {             /* take appropriate action */
111 <        case DR_BUNDLE:
111 >        case DR_BUNDLE:         /* new bundle to calculate */
112                  if (msg.nbytes != sizeof(PACKHEAD))
113                          error(INTERNAL, "bad DR_BUNDLE from display process");
114                  bundle_set(BS_ADD, (PACKHEAD *)buf, 1);
115                  break;
116 <        case DR_NEWSET:
116 >        case DR_NEWSET:         /* new calculation set */
117                  if (msg.nbytes % sizeof(PACKHEAD))
118                          error(INTERNAL, "bad DR_NEWSET from display process");
119                  disp_result(DS_STARTIMM, 0, NULL);
120                  bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
121                  disp_result(DS_ENDIMM, 0, NULL);
122 +                disp_flush();
123                  break;
124 <        case DR_ADDSET:
124 >        case DR_ADDSET:         /* add to calculation set */
125                  if (msg.nbytes % sizeof(PACKHEAD))
126                          error(INTERNAL, "bad DR_ADDSET from display process");
127                  disp_result(DS_STARTIMM, 0, NULL);
128                  bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
129                  disp_result(DS_ENDIMM, 0, NULL);
130 +                disp_flush();
131                  break;
132 <        case DR_DELSET:
132 >        case DR_ADJSET:         /* adjust calculation set members */
133                  if (msg.nbytes % sizeof(PACKHEAD))
134 +                        error(INTERNAL, "bad DR_ADJSET from display process");
135 +                disp_result(DS_STARTIMM, 0, NULL);
136 +                bundle_set(BS_ADJ, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
137 +                disp_result(DS_ENDIMM, 0, NULL);
138 +                disp_flush();
139 +                break;
140 +        case DR_DELSET:         /* delete from calculation set */
141 +                if (msg.nbytes % sizeof(PACKHEAD))
142                          error(INTERNAL, "bad DR_DELSET from display process");
143                  bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
144                  break;
145 <        case DR_ATTEN:
145 >        case DR_ATTEN:          /* block for priority request */
146                  if (msg.nbytes)
147                          error(INTERNAL, "bad DR_ATTEN from display process");
148                                          /* send acknowledgement */
149                  disp_result(DS_ACKNOW, 0, NULL);
150 <                block = 1;              /* block on following request */
151 <                goto restart;
121 <        case DR_SHUTDOWN:
150 >                return(disp_check(1));  /* block on following request */
151 >        case DR_KILL:           /* kill computation process(es) */
152                  if (msg.nbytes)
153 +                        error(INTERNAL, "bad DR_KILL from display process");
154 +                if (nprocs > 0)
155 +                        done_rtrace();
156 +                else
157 +                        error(WARNING, "no rtrace process to kill");
158 +                break;
159 +        case DR_RESTART:        /* restart computation process(es) */
160 +                if (msg.nbytes)
161 +                        error(INTERNAL, "bad DR_RESTART from display process");
162 +                if (ncprocs > nprocs)
163 +                        new_rtrace();
164 +                else if (nprocs > 0)
165 +                        error(WARNING, "rtrace already runnning");
166 +                else
167 +                        error(WARNING, "holodeck not open for writing");
168 +                break;
169 +        case DR_CLOBBER:        /* clobber holodeck */
170 +                if (msg.nbytes)
171 +                        error(INTERNAL, "bad DR_CLOBBER from display process");
172 +                if (!force || !ncprocs)
173 +                        error(WARNING, "request to clobber holodeck denied");
174 +                else {
175 +                        error(WARNING, "clobbering holodeck contents");
176 +                        hdclobber(NULL);
177 +                }
178 +                break;
179 +        case DR_SHUTDOWN:       /* shut down program */
180 +                if (msg.nbytes)
181                          error(INTERNAL, "bad DR_SHUTDOWN from display process");
182                  return(0);              /* zero return signals shutdown */
183 +        case DR_NOOP:           /* do nothing */
184 +                break;
185          default:
186                  error(INTERNAL, "unrecognized request from display process");
187          }
188 <        if (msg.nbytes)
188 >        if (msg.nbytes)                 /* clean up */
189                  free(buf);
190          return(1);                      /* normal return value */
191   fcntlerr:
# Line 140 | Line 200 | disp_close()                   /* close our display process */
200   {
201          int     rval;
202  
203 <        if (pipesiz <= 0)
203 >        if (dpout == NULL)
204                  return(-1);
205          disp_result(DS_SHUTDOWN, 0, NULL);
206 <        pipesiz = 0;
206 >        fclose(dpout);
207 >        dpout = NULL;
208          return(close_process(dpd));
209   }
210  
211  
212 < disp_result(type, nbytes, p)    /* send result message to display process */
212 > disp_result(type, nbytes, p)    /* queue result message to display process */
213   int     type, nbytes;
214   char    *p;
215   {
155        struct iovec    iov[2];
216          MSGHEAD msg;
157        int     n;
217  
218 +        if (dpout == NULL)
219 +                return;
220          msg.type = type;
221          msg.nbytes = nbytes;
222 <        if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) {
223 <                n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD));
224 <                if (n != sizeof(MSGHEAD))
225 <                        goto writerr;
226 <                if (nbytes > 0) {
227 <                        n = writebuf(dpd[1], p, nbytes);
228 <                        if (n != nbytes)
229 <                                goto writerr;
230 <                }
231 <                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");
222 >        fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout);
223 >        if (nbytes > 0)
224 >                fwrite(p, 1, nbytes, dpout);
225 > }
226 >
227 >
228 > disp_flush()                    /* flush output to display */
229 > {
230 >        if (fflush(dpout) < 0)
231 >                error(SYSTEM, "error writing to the display process");
232   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines