Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!usc!ucsd!hub!orange!dz
From: dz@orange.ucsb.edu (Daniel James Zerkle)
Newsgroups: comp.sys.next
Subject: Re: communication between programs with Speaker and Listener
Keywords: speaker listener ipc port kernel preview
Message-ID: <2227@hub.UUCP>
Date: 18 Aug 89 16:07:49 GMT
References: <2220@hub.UUCP>
Sender: news@hub.UUCP
Reply-To: dz@cornu.ucsb.edu (Daniel James Zerkle)
Distribution: usa
Organization: University of California, Santa Barbara
Lines: 68

In article <2220@hub.UUCP> I write:
>You know the way that Digital Librarian can communicate with WriteNow
>to display certain documents?  Ever notice that the print panel does
>the same thing with Preview in many applications?  I am trying to do
>something similar, but I am having no luck at all.  I want to be able
>to send a message to Preview to display certain PostScript documents.

The following code will do the job.  Types declared in the interface are
port_t port; id SpeakerId, inputForm; int returnOk; char dfile[500];

- doDisplay:sender
{
    [inputForm selectTextAt:0]; /* I'm getting it from a Form */
    
    returnOk=YES;  /* this probably is not necessary */
    SpeakerId = [Speaker new];
    port = NXPortFromName("Preview",NULL);
    strcpy(dfile, [inputForm stringValueAt:0]); /* dfile is full path of doc */
    if (port != PORT_NULL)
      {
      [SpeakerId setSendPort:port];
      [SpeakerId openFile:dfile ok:&returnOk];
      }
    [SpeakerId free];
    return self;
}

>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?

The reason my code wasn't working is because I was using the full
pathname for Preview.  NXPortFromName is now returning the proper
port, somehow, with just "Preview", and not "/NextDeveloper/Demos/Preview".

>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?

NXPortFromName() will automatically start up the Preview application,
if it is not already started.  If you kill Preview, it will re-start
it the next time.  This would seem to indicate that Preview does NOT
need to be registered anywhere.  Note, however, that I create a new
instance of a Speaker every time I use this method, and therefore get
the port anew each time.  If I retain the port, and don't re-get it, it
is possible for Preview to die before the next time I use it.

By the way, I have developed a slight case of athelete's tongue (foot
in mouth disease).  About ten minutes after I posted my second message,
I discovered "don't use the full path, dummy".  I do, however, greatly
appreciate the people who have attempted to answer my questions, as all
I really know is that the above code works, not *why* it works (which is
far more important).  The bit about messaging the Workspace directly
could prove to be very, very useful.  Thanks for the help.

My code above is really trivial.  It's wonderful that NeXT provided such
powerful tools to make programming easier.  Unfortunately, they didn't
document carefully enough.  They will have a whole lot of programs out
there if release 1.0 can document more carefully and *let* people write
code without being either psychic or priveledged to another, capable infor-
mation source (such as this net).  Are the tech writers listening?

| Dan Zerkle home:(805) 968-4683 morning:961-2434 afternoon:687-0110  |
| dz@cornu.ucsb.edu dz%cornu@ucsbuxa.bitnet ...ucbvax!hub!cornu!dz    |
| Snailmail: 6681 Berkshire Terrace #5, Isla Vista, CA  93117         |
| Disclaimer: If it's wrong or stupid, pretend I didn't do it.        |