mdm@wdl50.wdl.loral.com (Mike D Marchionna) (03/02/91)
Hey gang. Here is something unusual for this group, a programming question. :-) I have recently been toying with the idea of porting some X window code to NeXT step. Most of the code would seem to have similar or equivalent functionality to certain NeXT Step objects except for one aspect. In X there is a function called XtAddInput that allows the caller to specify a UNIX file descriptor to monitor. XtAddInput will invoke a specified callback routine whenever there is data to read on the indicated file descriptor. Basically XtAddInput generates a pseudo window event that your program can choose to respond as you see fit. I don't know if any such functionality exists under Next Step. In NeXT Stepese I guess what I what I would need is a function that could be called without blocking, and would send a specified message to a specified object whenever the indicated file descriptor has information to read. One approach I had in mind was to start a Mach thread that performed a blocking read and then sent an Objective C message to NXApp or some such object that read and processed the data and then restarted the the thread for the next read. Is there any way to implement such a function, or is one already available. Many thanks for any information this group is kind enough to provide. -- +--------------||--##--%%--@@------+--------------------------------------+ |El-Rayo-X-----||--##--%%--@@----->| Brain and brain! What is brain! | |El-Rayo-X-----||--##--%%--@@----->| --Star Trek (Spock's Brain) | +--------------||--##--%%--@@------+--------------------------------------+
glenn@heaven.woodside.ca.us (Glenn Reid) (03/02/91)
In article <1991Mar1.174526.17075@wdl1.wdl.loral.com> mdm@wdl50.wdl.loral.com (Mike D Marchionna) writes: > > In X there is a function called XtAddInput that allows the caller to specify a > UNIX file descriptor to monitor. XtAddInput will invoke a specified callback > routine whenever there is data to read on the indicated file descriptor. Check out DPSAddFD(). It's part of Display PostScript, but I think it will do what you want. -- Glenn Reid RightBrain Software glenn@heaven.woodside.ca.us NeXT/PostScript developers ..{adobe,next}!heaven!glenn 415-851-1785 (fax 851-1470)
wiml@milton.u.washington.edu (William Lewis) (03/02/91)
In article <1991Mar1.174526.17075@wdl1.wdl.loral.com> mdm@wdl50.wdl.loral.com (Mike D Marchionna) writes: >In X there is a function called XtAddInput that allows the caller to specify a >UNIX file descriptor to monitor. XtAddInput will invoke a specified callback >routine whenever there is data to read on the indicated file descriptor. You want DPSAddFD() (and the corresponding DPSRemoveFD()). These do just about exactly what you're looking for: when the specified file descriptor becomes readable, the application object (waiting for an event) will call a user-specified function to handle the event. There's another pair of functions for Mach ports: DPSAddPort() and DPSRemovePort(). > .... One approach I had in mind was to start a Mach thread >that performed a blocking read and then sent an Objective C message to NXApp >or some such object that read and processed the data and then restarted the >the thread for the next read. One problem with this: threads and higher level things (such as objc, appkit calls, stdio, malloc, etc.) don't tend to mix very well. The problem is that most libraries are written under the assumption that they are running as the only thread in their address space, so they don't try to lock information before using it. Even just sending one objC message can try to update the objC message cache and if two threads do it at once, things can become screwed up. I usually have subsidiary threads be very stripped-down, simple things, communicating with the main thread via Mach messages or mutex-protected shared memory. -- wiml@milton.acs.washington.edu Seattle, Washington (William Lewis) | 47 41' 15" N 122 42' 58" W "Just remember, wherever you go ... you're stuck there."