[comp.sys.next] Can an App launch itself?

cs171faj@sdcc8.ucsd.edu (06/08/90)

HI!

Can anyone tell me about the possibility of doing the
following using Objective-C and Interface Builder;

Let's say you have an app running; can you make a certain 
button create another copy of the app that has the same
functionality as the original (i.e. looks the same, with
all buttons and things functioning)?

Sounds simple, but Sounds simple, but confusing.confusing.

thanks in advance!

jeff beck 
cs171faj@sdcc8.ucsd.edu

jacob@gore.com (Jacob Gore) (06/08/90)

/ comp.sys.next / cs171faj@sdcc8.ucsd.edu / Jun  7, 1990 /
> Let's say you have an app running; can you make a certain 
> button create another copy of the app that has the same
> functionality as the original (i.e. looks the same, with
> all buttons and things functioning)?

Do you want the "copy" to start running at its beginning, or do you want it
to be in the exact same state as the "original"?

Jacob
--
Jacob Gore		Jacob@Gore.Com			boulder!gore!jacob

Eric.Thayer@cs.cmu.edu (Eric H. Thayer) (06/08/90)

If you want the Workspace Manager to "know about" your application, you should
use the open command in your string to system().  For example,
    system("open /NextApps/Terminal")
as opposed to
    system("/NextApps/Terminal")

If you want a cool tour of the AppKit, you could also create a Speaker and
connect it to the Workspace Manager and then use the launchProgram:ok: 
method.  You should look at the Speaker class doc.  There is example code 
on how to connect a Speaker to an application.  The trick to get a Speaker 
connected to the Workspace is to know what to pass to the NXPortFromName() 
call.  So far, NXPortFromName(getenv("Workspace"), NULL) has worked for me.







Replies may have NeXT attachments in them
Phone: (412)268-7679

wjs@fred.cs.washington.edu (William Shipley) (06/08/90)

In article <11277@sdcc6.ucsd.edu> cs171faj@sdcc8.ucsd.edu writes:
>Let's say you have an app running; can you make a certain 
>button create another copy of the app that has the same
>functionality as the original (i.e. looks the same, with
>all buttons and things functioning)?
>
>jeff beck 

If all you want is a brand-new, pristine copy of your app running, you
ought to be able to do a system("open myApp") or some such.  (You could
fork and exec, if you wish).  There's a global variable or function that
will give you the path in which your app resides, if you don't expect it
to be in the normal places.

However, if you want your variables to be inherited, it's a little trickier.
The Application class isn't re-entrant, that is, you can't have more than
one instance of the Application class in any given process.  This is a Major
Bummer, because it means you can't create a bunch of cthreads, all with 
different Application objects.  What would be the advantage to this, you
ask?  Well, you could change NXHost for each Application object, so that
a single process could support multiple windows on multiple NeXTs.

This would be totally keen for multi-player game design, but there are myriad
other applications, including courseware.

One fix is that you CAN do is many normal forks (which mark memory for the
child as copy-on-write, meaning they are memory efficient) BEFORE you ever
create any Application object.  (This involves rewriting the IB-provided 
main.m so that you fork before you do the NXApp = [Application new];).
Each process can then have its own Application object running.  "What do
you win?" you are asking.  If, before you fork, you mark some pages as
SHARED, then you can have shared memory between the Applications, which is
sometimes more convienient than messaging.

This all sounds complicated and hypothetical, but I've actually tried it,
and I'll send anyone (ugly) code on request.

-william "please NeXT make your classes re-entrant" shipley

ObSilliness:  THE Jeff Beck?  No kidding.  How's the band?

hannum@chopin.psu.edu (Charles Hannum) (06/09/90)

Yes, this is really quite simple.  If you're using the Interface Builder, then
all you need to do is this:  (Note that this is all from memory, so don't flame
me if it's not quite right.  It should give you enough info to figure it out on
your own.)

  #import <appkit/Application.h>
  extern char *appname;

  [[NXApp appSpeaker] setSendPort:NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
  [[NXApp appSpeaker] openFile:appname];

In your main program, do this:

  char *appname;

  /* Blah, blah */

  int main(int argc, char **argv)
  {
      appname = *argv;

      /* Blah, blah */
  }

That should do exactly what you want, shart a fresh copy of the application.
Hm.  Maybe someone at NeXT could put a 'Spawn' button in Terminal ... B-)


Now, if you're *not* using the Interface Builder, you can do this:

  #import <appkit/Speaker.h>
  id      mySpeaker;

  /* Blah, blah */

  mySpeaker = [Speaker New];
  [mySpeaker setSendPort:NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
  [mySpeaker openFile:appname];
  [mySpeaker free];

NOTE:  You could keep the Speaker allocated throughout the program; you really
don't need to deallocate it.  It's just a matter of your personal preference.


(I'd say 'Hope this helps.', but I know it will ... B-)


ObQuery:  Is there a global version of 'argv'?  Then I wouldn't have to have
main() store a pointer to the app's name; I could just reference argv[0] every
time.
--
 
Virtually,
Charles Martin Hannum		 "Those who say a thing cannot be done should
Please send mail to:		  under no circumstances stand in the way of
hannum@schubert.psu.edu		  he who is doing it." - a misquote

Eric.Thayer@cs.cmu.edu (Eric H. Thayer) (06/10/90)

In article <614@nic.stolaf.edu> hannum@chopin.psu.edu (Charles Hannum) 
writes:
> ObQuery:  Is there a global version of 'argv'?  Then I wouldn't have to 
have
> main() store a pointer to the app's name; I could just reference argv[0] 
every
> time.

NXArgv will do it for you.


Replies may have NeXT attachments in them
Phone: (412)268-7679