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.3 by gregl, Tue Nov 4 09:58:24 1997 UTC vs.
Revision 3.11 by gregl, Mon Dec 8 18:51:15 1997 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
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                                  /* write out hologram grids */
57          for (i = 0; hdlist[i] != NULL; i++)
58                  disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
59 +        disp_flush();
60   }
61  
62  
63   disp_packet(p)                  /* display a packet */
64 < register PACKET *p;
64 > register PACKHEAD       *p;
65   {
66 <        disp_result(DS_BUNDLE, sizeof(PACKHEAD) + p->nr*sizeof(RAYVAL),
50 <                        (char *)p);
66 >        disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
67   }
68  
69  
# Line 58 | Line 74 | int    block;
74          int     n;
75          char    *buf = NULL;
76  
77 <        if (pipesiz <= 0)
77 >        if (dpout == NULL)
78                  return(-1);
79 +                                        /* flush display output */
80 +        disp_flush();
81                                          /* check read blocking */
82          if (block != (inp_flags == 0)) {
83                  inp_flags = block ? 0 : FNONBLK;
# Line 69 | 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 96 | Line 116 | int    block;
116                  disp_result(DS_STARTIMM, 0, NULL);
117                  bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
118                  disp_result(DS_ENDIMM, 0, NULL);
119 +                disp_flush();
120                  break;
121          case DR_ADDSET:
122                  if (msg.nbytes % sizeof(PACKHEAD))
# Line 103 | Line 124 | int    block;
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:
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:
138                  if (msg.nbytes % sizeof(PACKHEAD))
139                          error(INTERNAL, "bad DR_DELSET from display process");
# Line 119 | Line 149 | int    block;
149                  if (msg.nbytes)
150                          error(INTERNAL, "bad DR_SHUTDOWN from display process");
151                  return(0);              /* zero return signals shutdown */
152 +        case DR_NOOP:
153 +                break;
154          default:
155                  error(INTERNAL, "unrecognized request from display process");
156          }
# Line 137 | Line 169 | disp_close()                   /* close our display process */
169   {
170          int     rval;
171  
172 <        if (pipesiz <= 0)
172 >        if (dpout == NULL)
173                  return(-1);
174          disp_result(DS_SHUTDOWN, 0, NULL);
175 <        pipesiz = 0;
175 >        fclose(dpout);
176 >        dpout = NULL;
177          return(close_process(dpd));
178   }
179  
180  
181 < disp_result(type, nbytes, p)    /* send result message to display process */
181 > disp_result(type, nbytes, p)    /* queue result message to display process */
182   int     type, nbytes;
183   char    *p;
184   {
152        struct iovec    iov[2];
185          MSGHEAD msg;
154        int     n;
186  
187 <        if (pipesiz <= 0)
187 >        if (dpout == NULL)
188                  return;
189          msg.type = type;
190          msg.nbytes = nbytes;
191 <        if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) {
192 <                do
193 <                        n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD));
194 <                while (n < 0 && errno == EINTR);
195 <                if (n != sizeof(MSGHEAD))
196 <                        goto writerr;
197 <                if (nbytes > 0) {
198 <                        n = writebuf(dpd[1], p, nbytes);
199 <                        if (n != nbytes)
200 <                                goto writerr;
170 <                }
171 <                return;
172 <        }
173 <        iov[0].iov_base = (char *)&msg;
174 <        iov[0].iov_len = sizeof(MSGHEAD);
175 <        iov[1].iov_base = p;
176 <        iov[1].iov_len = nbytes;
177 <        do
178 <                n = writev(dpd[1], iov, 2);
179 <        while (n < 0 && errno == EINTR);
180 <        if (n == sizeof(MSGHEAD)+nbytes)
181 <                return;
182 < writerr:
183 <        error(SYSTEM, "write error in disp_result");
191 >        fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout);
192 >        if (nbytes > 0)
193 >                fwrite(p, 1, nbytes, dpout);
194 > }
195 >
196 >
197 > disp_flush()                    /* flush output to display */
198 > {
199 >        if (fflush(dpout) < 0)
200 >                error(SYSTEM, "error writing to the display process");
201   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines