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.13 by gregl, Fri Dec 12 11:13:17 1997 UTC vs.
Revision 3.28 by greg, Sat Feb 22 02:07:25 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1997 Silicon Graphics, Inc. */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Holodeck display process communication
6   */
# Line 13 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10   #include <sys/uio.h>
11  
12   #ifndef HDSUF
13 < #define HDSUF   ".hdisp"
13 > #define HDSUF           ".hdi"
14   #endif
15 + #ifndef SLAVENAME
16 + #define SLAVENAME       "slave"
17 + #endif
18  
19 + #ifndef FNONBLK
20 + #define FNONBLK         O_NONBLOCK
21 + #endif
22 +
23   static int      inp_flags;
24   static int      dpd[3];
25   static FILE     *dpout;
# Line 24 | Line 28 | static FILE    *dpout;
28   disp_open(dname)                /* open the named display driver */
29   char    *dname;
30   {
31 <        char    dpath[128], fd0[8], fd1[8], *cmd[5];
32 <        int     i;
33 <                                /* get full display program name */
31 >        char    buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn;
32 >        int     i, n, len;
33 >
34 >        if (!strcmp(dname, SLAVENAME)) {
35 >                dpd[0] = 0;             /* read from stdin */
36 >                dpout = stdout;         /* write to stdout */
37 >                dpd[2] = -1;            /* we're the slave process */
38 >        } else {
39 >                                        /* get full display program name */
40   #ifdef DEVPATH
41 <        sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF);
41 >                sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF);
42   #else
43 <        sprintf(dpath, "dev/%s%s", dname, HDSUF);
43 >                sprintf(buf, "dev/%s%s", dname, HDSUF);
44   #endif
45 <                                /* dup stdin and stdout */
46 <        if (readinp)
47 <                sprintf(fd0, "%d", dup(0));
48 <        else
49 <                strcpy(fd0, "-1");
50 <        sprintf(fd1, "%d", dup(1));
51 <                                /* start the display process */
52 <        cmd[0] = dpath;
53 <        cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
54 <        cmd[4] = NULL;
55 <        i = open_process(dpd, cmd);
56 <        if (i <= 0)
57 <                error(USER, "cannot start display process");
58 <        if ((dpout = fdopen(dpd[1], "w")) == NULL)
59 <                error(SYSTEM, "cannot associate FILE with display pipe");
45 >                                        /* dup stdin and stdout */
46 >                if (readinp)
47 >                        sprintf(fd0, "%d", dup(0));
48 >                else
49 >                        strcpy(fd0, "-1");
50 >                sprintf(fd1, "%d", dup(1));
51 >                                        /* start the display process */
52 >                cmd[0] = buf;
53 >                cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
54 >                cmd[4] = NULL;
55 >                i = open_process(dpd, cmd);
56 >                if (i <= 0)
57 >                        error(USER, "cannot start display process");
58 >                if ((dpout = fdopen(dpd[1], "w")) == NULL)
59 >                        error(SYSTEM, "problem opening display pipe");
60 >                                        /* close dup'ed stdin and stdout */
61 >                if (readinp)
62 >                        close(atoi(fd0));
63 >                close(atoi(fd1));
64 >        }
65          dpd[1] = -1;            /* causes ignored error in close_process() */
66          inp_flags = 0;
67 <                                /* close dup'ed stdin and stdout */
68 <        if (readinp)
69 <                close(atoi(fd0));
70 <        close(atoi(fd1));
71 <                                /* write out hologram grids */
72 <        for (i = 0; hdlist[i] != NULL; i++)
73 <                disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
67 >                                /* check if outside */
68 >        if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS))
69 >                disp_result(DS_OUTSECT, 0, NULL);
70 >                                /* send eye separation if specified */
71 >        if (vdef(EYESEP)) {
72 >                sprintf(buf, "%.9e", vflt(EYESEP));
73 >                disp_result(DS_EYESEP, strlen(buf)+1, buf);
74 >        }
75 >                                /* write out hologram grids & octrees */
76 >        for (i = 0; hdlist[i] != NULL; i++) {
77 >                bcopy((char *)hdlist[i], buf, sizeof(HDGRID));
78 >                len = sizeof(HDGRID);
79 >                n = vdef(GEOMETRY);
80 >                sfn = i<n ? nvalue(GEOMETRY,i) :
81 >                                n ? nvalue(GEOMETRY,n-1) : vval(OCTREE);
82 >                strcpy(buf+len, sfn);
83 >                len += strlen(sfn) + 1;
84 >                n = vdef(PORTS);
85 >                sfn = i<n ? nvalue(PORTS,i) : n ? nvalue(PORTS,n-1) : "";
86 >                strcpy(buf+len, sfn);
87 >                len += strlen(sfn) + 1;
88 >                disp_result(DS_ADDHOLO, len, buf);
89 >        }
90          disp_flush();
91   }
92  
# Line 96 | Line 127 | int    block;
127                  return(2);              /* acceptable failure */
128          }
129          if (msg.nbytes) {               /* get the message body */
130 +                if (msg.nbytes < 0)
131 +                        error(INTERNAL, "anti-message from display process");
132                  buf = (char *)malloc(msg.nbytes);
133                  if (buf == NULL)
134                          error(SYSTEM, "out of memory in disp_check");
135 <                if (fcntl(dpd[0], F_SETFL, inp_flags=0) < 0)
135 >                if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0)
136                          goto fcntlerr;
137                  if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes)
138                          goto readerr;
# Line 113 | Line 146 | int    block;
146          case DR_NEWSET:         /* new calculation set */
147                  if (msg.nbytes % sizeof(PACKHEAD))
148                          error(INTERNAL, "bad DR_NEWSET from display process");
149 <                disp_result(DS_STARTIMM, 0, NULL);
149 >                if (msg.nbytes)
150 >                        disp_result(DS_STARTIMM, 0, NULL);
151                  bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
152 <                disp_result(DS_ENDIMM, 0, NULL);
153 <                disp_flush();
152 >                if (msg.nbytes) {
153 >                        disp_result(DS_ENDIMM, 0, NULL);
154 >                        disp_flush();
155 >                }
156                  break;
157          case DR_ADDSET:         /* add to calculation set */
158 +                if (!msg.nbytes)
159 +                        break;
160                  if (msg.nbytes % sizeof(PACKHEAD))
161                          error(INTERNAL, "bad DR_ADDSET from display process");
162                  disp_result(DS_STARTIMM, 0, NULL);
163                  bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
164                  disp_result(DS_ENDIMM, 0, NULL);
165 <                disp_check(0);          /* hack -- delete usu. follows add */
165 >                disp_flush();
166                  break;
167          case DR_ADJSET:         /* adjust calculation set members */
168 +                if (!msg.nbytes)
169 +                        break;
170                  if (msg.nbytes % sizeof(PACKHEAD))
171                          error(INTERNAL, "bad DR_ADJSET from display process");
172                  disp_result(DS_STARTIMM, 0, NULL);
# Line 135 | Line 175 | int    block;
175                  disp_flush();
176                  break;
177          case DR_DELSET:         /* delete from calculation set */
178 +                if (!msg.nbytes)
179 +                        break;
180                  if (msg.nbytes % sizeof(PACKHEAD))
181                          error(INTERNAL, "bad DR_DELSET from display process");
182                  bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
183                  break;
184 +        case DR_VIEWPOINT:      /* set target eye position */
185 +                if (msg.nbytes != sizeof(VIEWPOINT))
186 +                        error(INTERNAL, "bad DR_VIEWPOINT from display process");
187 +                copystruct(&myeye, (VIEWPOINT *)buf);
188 +                break;
189          case DR_ATTEN:          /* block for priority request */
190                  if (msg.nbytes)
191                          error(INTERNAL, "bad DR_ATTEN from display process");
# Line 148 | Line 195 | int    block;
195          case DR_KILL:           /* kill computation process(es) */
196                  if (msg.nbytes)
197                          error(INTERNAL, "bad DR_KILL from display process");
198 <                if (nprocs > 0) {
199 <                        done_packets(flush_queue());
200 <                        if (end_rtrace())
154 <                                error(WARNING, "bad status returned by rtrace");
155 <                } else
198 >                if (nprocs > 0)
199 >                        done_rtrace();
200 >                else
201                          error(WARNING, "no rtrace process to kill");
202                  break;
203          case DR_RESTART:        /* restart computation process(es) */
204                  if (msg.nbytes)
205                          error(INTERNAL, "bad DR_RESTART from display process");
206 <                if (ncprocs > nprocs) {
207 <                        checkrad();
208 <                        if (start_rtrace() < 1)
164 <                                error(WARNING, "cannot restart rtrace");
165 <                } else if (nprocs > 0)
206 >                if (ncprocs > nprocs)
207 >                        new_rtrace();
208 >                else if (nprocs > 0)
209                          error(WARNING, "rtrace already runnning");
210                  else
211                          error(WARNING, "holodeck not open for writing");
# Line 170 | Line 213 | int    block;
213          case DR_CLOBBER:        /* clobber holodeck */
214                  if (msg.nbytes)
215                          error(INTERNAL, "bad DR_CLOBBER from display process");
216 <                if (!force || !ncprocs)
216 >                if (force <= 0 | ncprocs <= 0)
217                          error(WARNING, "request to clobber holodeck denied");
218                  else {
219                          error(WARNING, "clobbering holodeck contents");
# Line 203 | Line 246 | disp_close()                   /* close our display process */
246  
247          if (dpout == NULL)
248                  return(-1);
249 +        myeye.rng = 0;
250          disp_result(DS_SHUTDOWN, 0, NULL);
251          fclose(dpout);
252          dpout = NULL;
253 <        return(close_process(dpd));
253 >        return(dpd[2]<0 ? 0 : close_process(dpd));
254   }
255  
256  
# Line 215 | Line 259 | int    type, nbytes;
259   char    *p;
260   {
261          MSGHEAD msg;
262 <
262 >                                        /* consistency checks */
263 > #ifdef DEBUG
264 >        if (nbytes < 0 || nbytes > 0 & p == NULL)
265 >                error(CONSISTENCY, "bad buffer handed to disp_result");
266 > #endif
267          if (dpout == NULL)
268                  return;
269          msg.type = type;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines