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.20 by gwlarson, Tue Oct 6 18:09:49 1998 UTC vs.
Revision 3.35 by schorsch, Sun Jul 27 22:12:02 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1998 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   */
7  
8   #include "rholo.h"
9   #include "rhdisp.h"
10 + #include "rtprocess.h"
11   #include <sys/uio.h>
12 + #include <string.h>
13  
14   #ifndef HDSUF
15 < #define HDSUF   ".hdi"
15 > #define HDSUF           ".hdi"
16   #endif
17 + #ifndef SLAVENAME
18 + #define SLAVENAME       "slave"
19 + #endif
20  
21 + #ifndef FNONBLK
22 + #define FNONBLK         O_NONBLOCK
23 + #endif
24 +
25   static int      inp_flags;
26 < static int      dpd[3];
26 > static SUBPROC  dpd;
27   static FILE     *dpout;
28  
29  
30   disp_open(dname)                /* open the named display driver */
31   char    *dname;
32   {
33 <        char    dpath[128], fd0[8], fd1[8], *cmd[5];
34 <        int     i;
35 <                                /* get full display program name */
33 >        char    buf[sizeof(HDGRID)+512], fd0[8], fd1[8], *cmd[5], *sfn;
34 >        int     i, n, len;
35 >
36 >        if (!strcmp(dname, SLAVENAME)) {
37 >                dpd.r = 0;              /* read from stdin */
38 >                dpout = stdout;         /* write to stdout */
39 >                dpd.running = 0; /* we're the slave procees */
40 >        } else {
41 >                                        /* get full display program name */
42   #ifdef DEVPATH
43 <        sprintf(dpath, "%s/%s%s", DEVPATH, dname, HDSUF);
43 >                sprintf(buf, "%s/%s%s", DEVPATH, dname, HDSUF);
44   #else
45 <        sprintf(dpath, "dev/%s%s", dname, HDSUF);
45 >                sprintf(buf, "dev/%s%s", dname, HDSUF);
46   #endif
47 <                                /* dup stdin and stdout */
48 <        if (readinp)
49 <                sprintf(fd0, "%d", dup(0));
50 <        else
51 <                strcpy(fd0, "-1");
52 <        sprintf(fd1, "%d", dup(1));
53 <                                /* start the display process */
54 <        cmd[0] = dpath;
55 <        cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
56 <        cmd[4] = NULL;
57 <        i = open_process(dpd, cmd);
58 <        if (i <= 0)
59 <                error(USER, "cannot start display process");
60 <        if ((dpout = fdopen(dpd[1], "w")) == NULL)
61 <                error(SYSTEM, "cannot associate FILE with display pipe");
62 <        dpd[1] = -1;            /* causes ignored error in close_process() */
47 >                                        /* dup stdin and stdout */
48 >                if (readinp)
49 >                        sprintf(fd0, "%d", dup(0));
50 >                else
51 >                        strcpy(fd0, "-1");
52 >                sprintf(fd1, "%d", dup(1));
53 >                                        /* start the display process */
54 >                cmd[0] = buf;
55 >                cmd[1] = froot; cmd[2] = fd1; cmd[3] = fd0;
56 >                cmd[4] = NULL;
57 >                i = open_process(&dpd, cmd);
58 >                if (i <= 0)
59 >                        error(USER, "cannot start display process");
60 >                if ((dpout = fdopen(dpd.w, "w")) == NULL)
61 >                        error(SYSTEM, "problem opening display pipe");
62 >                                        /* close dup'ed stdin and stdout */
63 >                if (readinp)
64 >                        close(atoi(fd0));
65 >                close(atoi(fd1));
66 >        }
67 >        dpd.w = -1;             /* causes ignored error in close_process() */
68          inp_flags = 0;
52                                /* close dup'ed stdin and stdout */
53        if (readinp)
54                close(atoi(fd0));
55        close(atoi(fd1));
69                                  /* check if outside */
70          if (vdef(OBSTRUCTIONS) && vbool(OBSTRUCTIONS))
71                  disp_result(DS_OUTSECT, 0, NULL);
72                                  /* send eye separation if specified */
73          if (vdef(EYESEP)) {
74 <                char    fbuf[32];
75 <                sprintf(fbuf, "%.9e", vflt(EYESEP));
63 <                disp_result(DS_EYESEP, strlen(fbuf)+1, fbuf);
74 >                sprintf(buf, "%.9e", vflt(EYESEP));
75 >                disp_result(DS_EYESEP, strlen(buf)+1, buf);
76          }
77 <                                /* write out hologram grids */
78 <        for (i = 0; hdlist[i] != NULL; i++)
79 <                disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
77 >                                /* write out hologram grids & octrees */
78 >        for (i = 0; hdlist[i] != NULL; i++) {
79 >                memcpy(buf, (void *)hdlist[i], sizeof(HDGRID));
80 >                len = sizeof(HDGRID);
81 >                n = vdef(GEOMETRY);
82 >                sfn = i<n ? nvalue(GEOMETRY,i) :
83 >                                n ? nvalue(GEOMETRY,n-1) : vval(OCTREE);
84 >                strcpy(buf+len, sfn);
85 >                len += strlen(sfn) + 1;
86 >                n = vdef(PORTS);
87 >                sfn = i<n ? nvalue(PORTS,i) : n ? nvalue(PORTS,n-1) : "";
88 >                strcpy(buf+len, sfn);
89 >                len += strlen(sfn) + 1;
90 >                disp_result(DS_ADDHOLO, len, buf);
91 >        }
92          disp_flush();
93   }
94  
# Line 90 | Line 114 | int    block;
114                                          /* check read blocking */
115          if (block != (inp_flags == 0)) {
116                  inp_flags = block ? 0 : FNONBLK;
117 <                if (fcntl(dpd[0], F_SETFL, inp_flags) < 0)
117 >                if (fcntl(dpd.r, F_SETFL, inp_flags) < 0)
118                          goto fcntlerr;
119          }
120                                          /* read message header */
121 <        n = read(dpd[0], (char *)&msg, sizeof(MSGHEAD));
121 >        n = read(dpd.r, (char *)&msg, sizeof(MSGHEAD));
122          if (n != sizeof(MSGHEAD)) {
123                  if (n >= 0) {
124                          dpout = NULL;
125                          error(USER, "display process died");
126                  }
127 <                if (errno != EAGAIN & errno != EINTR)
127 >                if ((errno != EAGAIN) & (errno != EINTR))
128                          goto readerr;
129                  return(2);              /* acceptable failure */
130          }
# Line 110 | Line 134 | int    block;
134                  buf = (char *)malloc(msg.nbytes);
135                  if (buf == NULL)
136                          error(SYSTEM, "out of memory in disp_check");
137 <                if (inp_flags != 0 && fcntl(dpd[0], F_SETFL, inp_flags=0) < 0)
137 >                if (inp_flags != 0 && fcntl(dpd.r, F_SETFL, inp_flags=0) < 0)
138                          goto fcntlerr;
139 <                if (readbuf(dpd[0], buf, msg.nbytes) != msg.nbytes)
139 >                if (readbuf(dpd.r, buf, msg.nbytes) != msg.nbytes)
140                          goto readerr;
141          }
142          switch (msg.type) {             /* take appropriate action */
# Line 159 | Line 183 | int    block;
183                          error(INTERNAL, "bad DR_DELSET from display process");
184                  bundle_set(BS_DEL, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
185                  break;
186 +        case DR_VIEWPOINT:      /* set target eye position */
187 +                if (msg.nbytes != sizeof(VIEWPOINT))
188 +                        error(INTERNAL, "bad DR_VIEWPOINT from display process");
189 +                myeye = *((VIEWPOINT *)buf);
190 +                break;
191          case DR_ATTEN:          /* block for priority request */
192                  if (msg.nbytes)
193                          error(INTERNAL, "bad DR_ATTEN from display process");
# Line 186 | Line 215 | int    block;
215          case DR_CLOBBER:        /* clobber holodeck */
216                  if (msg.nbytes)
217                          error(INTERNAL, "bad DR_CLOBBER from display process");
218 <                if (!force || !ncprocs)
218 >                if ((force <= 0) | (ncprocs <= 0))
219                          error(WARNING, "request to clobber holodeck denied");
220                  else {
221                          error(WARNING, "clobbering holodeck contents");
# Line 219 | Line 248 | disp_close()                   /* close our display process */
248  
249          if (dpout == NULL)
250                  return(-1);
251 +        myeye.rng = 0;
252          disp_result(DS_SHUTDOWN, 0, NULL);
253          fclose(dpout);
254          dpout = NULL;
255 <        return(close_process(dpd));
255 >        return(dpd.running ? close_process(&dpd) : 0);
256 >
257   }
258  
259  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines