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.7 by gregl, Thu Nov 20 18:07:00 1997 UTC vs.
Revision 3.13 by gregl, Fri Dec 12 11:13:17 1997 UTC

# Line 24 | Line 24 | static FILE    *dpout;
24   disp_open(dname)                /* open the named display driver */
25   char    *dname;
26   {
27 <        char    dpath[128], *com[3];
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] = froot; com[2] = NULL;
36 <        i = open_process(dpd, com);
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(dup(dpd[1]), "w")) == NULL)
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                                  /* write out hologram grids */
57          for (i = 0; hdlist[i] != NULL; i++)
58                  disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
# Line 73 | Line 87 | int    block;
87                                          /* read message header */
88          n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD));
89          if (n != sizeof(MSGHEAD)) {
90 <                if (n >= 0)
90 >                if (n >= 0) {
91 >                        dpout = NULL;
92                          error(USER, "display process died");
93 +                }
94                  if (errno != EAGAIN & errno != EINTR)
95                          goto readerr;
96                  return(2);              /* acceptable failure */
# Line 89 | Line 105 | int    block;
105                          goto readerr;
106          }
107          switch (msg.type) {             /* take appropriate action */
108 <        case DR_BUNDLE:
108 >        case DR_BUNDLE:         /* new bundle to calculate */
109                  if (msg.nbytes != sizeof(PACKHEAD))
110                          error(INTERNAL, "bad DR_BUNDLE from display process");
111                  bundle_set(BS_ADD, (PACKHEAD *)buf, 1);
112                  break;
113 <        case DR_NEWSET:
113 >        case DR_NEWSET:         /* new calculation set */
114                  if (msg.nbytes % sizeof(PACKHEAD))
115                          error(INTERNAL, "bad DR_NEWSET from display process");
116                  disp_result(DS_STARTIMM, 0, NULL);
# Line 102 | Line 118 | int    block;
118                  disp_result(DS_ENDIMM, 0, NULL);
119                  disp_flush();
120                  break;
121 <        case DR_ADDSET:
121 >        case DR_ADDSET:         /* add to calculation set */
122                  if (msg.nbytes % sizeof(PACKHEAD))
123                          error(INTERNAL, "bad DR_ADDSET from display process");
124                  disp_result(DS_STARTIMM, 0, NULL);
125                  bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
126                  disp_result(DS_ENDIMM, 0, NULL);
127 +                disp_check(0);          /* hack -- delete usu. follows add */
128 +                break;
129 +        case DR_ADJSET:         /* adjust calculation set members */
130 +                if (msg.nbytes % sizeof(PACKHEAD))
131 +                        error(INTERNAL, "bad DR_ADJSET from display process");
132 +                disp_result(DS_STARTIMM, 0, NULL);
133 +                bundle_set(BS_ADJ, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
134 +                disp_result(DS_ENDIMM, 0, NULL);
135                  disp_flush();
136                  break;
137 <        case DR_DELSET:
137 >        case DR_DELSET:         /* delete from calculation set */
138                  if (msg.nbytes % sizeof(PACKHEAD))
139                          error(INTERNAL, "bad DR_DELSET from display process");
140                  bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
141                  break;
142 <        case DR_ATTEN:
142 >        case DR_ATTEN:          /* block for priority request */
143                  if (msg.nbytes)
144                          error(INTERNAL, "bad DR_ATTEN from display process");
145                                          /* send acknowledgement */
146                  disp_result(DS_ACKNOW, 0, NULL);
147                  return(disp_check(1));  /* block on following request */
148 <        case DR_SHUTDOWN:
148 >        case DR_KILL:           /* kill computation process(es) */
149                  if (msg.nbytes)
150 +                        error(INTERNAL, "bad DR_KILL from display process");
151 +                if (nprocs > 0) {
152 +                        done_packets(flush_queue());
153 +                        if (end_rtrace())
154 +                                error(WARNING, "bad status returned by rtrace");
155 +                } else
156 +                        error(WARNING, "no rtrace process to kill");
157 +                break;
158 +        case DR_RESTART:        /* restart computation process(es) */
159 +                if (msg.nbytes)
160 +                        error(INTERNAL, "bad DR_RESTART from display process");
161 +                if (ncprocs > nprocs) {
162 +                        checkrad();
163 +                        if (start_rtrace() < 1)
164 +                                error(WARNING, "cannot restart rtrace");
165 +                } else if (nprocs > 0)
166 +                        error(WARNING, "rtrace already runnning");
167 +                else
168 +                        error(WARNING, "holodeck not open for writing");
169 +                break;
170 +        case DR_CLOBBER:        /* clobber holodeck */
171 +                if (msg.nbytes)
172 +                        error(INTERNAL, "bad DR_CLOBBER from display process");
173 +                if (!force || !ncprocs)
174 +                        error(WARNING, "request to clobber holodeck denied");
175 +                else {
176 +                        error(WARNING, "clobbering holodeck contents");
177 +                        hdclobber(NULL);
178 +                }
179 +                break;
180 +        case DR_SHUTDOWN:       /* shut down program */
181 +                if (msg.nbytes)
182                          error(INTERNAL, "bad DR_SHUTDOWN from display process");
183                  return(0);              /* zero return signals shutdown */
184 <        case DR_NOOP:
184 >        case DR_NOOP:           /* do nothing */
185                  break;
186          default:
187                  error(INTERNAL, "unrecognized request from display process");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines