Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!agate!shelby!portia!Jessica!duggie From: duggie@Jessica.stanford.edu (Doug Felt) Newsgroups: comp.sys.next Subject: Re: communication between programs with Speaker and Listener Keywords: speaker listener ipc port kernel preview Message-ID: <4594@portia.Stanford.EDU> Date: 17 Aug 89 19:06:41 GMT References: <2220@hub.UUCP> Sender: USENET News SystemReply-To: duggie@Jessica.UUCP (Doug Felt) Distribution: usa Organization: Stanford University Lines: 123 In article <2220@hub.UUCP> dz@cornu.ucsb.edu (Daniel James Zerkle) writes: [description of app launching via Speaker/Listener omitted ] >This is the code I made that is utterly failing to work: > >/*****************************/ >- doDisplay:sender >{ > printf("Displayer is messaged...\n"); > [inputForm selectTextAt:0]; > > SpeakerId = [Speaker new]; > port = NXPortFromName("/NextDeveloper/Demos/Preview",NULL); > strcpy(dfile, [inputForm stringValueAt:0]); > printf("File name is %s.\n",dfile); > if (port != PORT_NULL) > { > printf("messaging the speaker\n"); > [SpeakerId openFile:dfile ok:&returnOk]; > } > [SpeakerId free]; > return self; >} >/*****************************/ > >... Thusly, port must in fact == PORT_NULL (whatever that is). >The problem is, therefore, in the NXPortFromName() call. Unfortunately, ... >Seeing "hostName", I tried changing the NULL to both "." and "pab" (our NeXT >is christened "pab", and it isn't my fault). That had no effect whatsoever. > >These are some good questions to answer: > >1. How do I get the proper port identification, when all I know is the > name of the program I want to use? Will this work if I don't even have > the full pathname? Should I use just the name and not the full path? It depends on how the application you want to messaage has registered itself. This is done in the main program that Interface Builder generates, in the setAppName: call to the newly created app. I think an app can register itself as anything (if the Workspace is smart). I don't know how you can find out what an app registers itself as. You should use NULL as the second parameter to talk to an application registered on your own system. Using your own hostname will also work, but there is no reason to. >2a.Applications such as Digital Librarian and WriteNow (not to mention > the Workspace Manager) will start up an application they need if it is > not already started. Is this automatic, or do I need to do it myself > upon receipt of some error saying that there is no port registered > under the desired application's name? If the application is not running, it is not registered. To launch the application you need to ask the Workspace to do it, like this: Speaker speak; /* created somewhere else */ port_t port; int ec; int ok; if ((port = NXPortFromName(NX_WORKSPACEREQUEST,NULL)) != PORT_NULL) { [speak setSendPort: port]; if (((ec = [speak launchProgram: "TargetApp" ok: &ok]) == 0) && ok) { /* ... program launched... */ } } >2b.How do I get this error message? How do I know that the receiving >program is ready (it may take awhile to start up)? I think you just get PORT_NULL back when you try to get its port. The app can terminate between messages, too, which will also cause requests for its port to fail. I myself would like to know if there is a better option than just going to sleep and polling for the port every once in awhile. Additionally, there is a chance that an app can terminate between the time you get port rights to it and the time you message it. I'd like to know myself if there is any way to get notified when a port that you have send rights to is destroyed. Otherwise you might as well cache the port rather than using NXPortFromName each time, except for the greater chance that the port would get reused by another app in that window. Ali? >3. Who takes care of these sorts of things? Should I be talking to the > Workspace Manager, or directly to the kernel? Is there more than one > option? If so, what is better under which circumstances? I'll let Ali answer this one. >4. Will the documentation be any better under 1.0? It was rather a cheap > shot to bring up NXPortFromName() and not have it documented anywhere. That's beta software for you... :-) >5. Just what exactly do ports do? How do they do it? Chapter 15 of the > technical manual talks about them but it is rather hard to follow. Reread it a few times and parts will start to make sense. It could use a few more examples, I agree. Try to fork some tasks and pass port rights back and forth. You can pass rights using the Speaker/Listener classes too. >6. Is there anything else I should know? I don't think you can message the Workspace on other machines. To talk to an app on another machine, it has to be running and registered. This is probably for security. If you use Speaker/Listener to message yourself, you will hang. You'd think separate threads could handle this, but I don't know how the messaging works. I've just been experimenting with this stuff myself, and have no special knowledge other than what I've been able to figure out. Take everything I say with a giant rock of salt. >| Dan Zerkle Doug Felt duggie@jessica.stanford.edu