[comp.sys.mac.programmer] How do you write a bg only/faceless app?

gft_robert@gsbacd.uchicago.edu (opcode ranger) (02/15/91)

-- 

I'm working on a large programming project.  Currently we have it running as an
interactive app.  We need to convert it to a background application which will
be called from a server running MacWorkstation.

What are the issues involved in making an app "background only".  A while  ago
I read thru the MultiFinder programming guide and saw some discussion of
writing faceless apps (I'll be reading thru this and other info again, but want
to get any helpul hints from net people too).  Apart from doing nothing which
requires having a user interface, what does one need to do to write a
background only/faceless app?

Any info you can provide is much appreciated!

Robert

============================================================================
= gft_robert@gsbacd.uchicago.edu * generic disclaimer: * "It's more fun to =
=            		         * all my opinions are *  compute"         =
=                                * mine                *  -Kraftwerk       =
============================================================================

casseres@apple.com (David Casseres) (02/16/91)

In article <1991Feb14.150442.1@gsbacd.uchicago.edu> 
gft_robert@gsbacd.uchicago.edu (opcode ranger) writes:
> What are the issues involved in making an app "background only".

To write a faceless background app (FBA):  first of all, rip out 
everything that has to do with windows or menus.  Don't forget to rip out 
things like InitWindows, and don't forget that dialogs and alerts are 
windows too.

Write an event loop that doesn't expect to get things like mouse events.  
Just like any application, an FBA must call WaitNextEvent as often as 
possible to yield control to Multifinder so other code can run.  When the 
system is shut down, your FBA will be shot down unceremoniously, whatever 
its state may be.  Therefore, make sure you are not midway through editing 
a file or something when you yield.

Documentation says faceless background apps should be "small," but doesn't 
say what that means.  I run 4 different ones simultaneously, ranging up to 
about 512K.

The rest is done in the SIZE resource.  Set "can background" and "only 
background" (these are ResEdit's names for the bits, Rez has different 
ones just to be weird).  I also set "does activate on FG switch," but this 
is probably unnecessary.  I also set "32 bit compatible," since my code 
is, and I leave all the other bits off.

Debugging can be tricky.  I recommend building your application with a 
minimal user interface so you can at least see when it's actually running, 
and using conditional compilation to take the user interface out when you 
are satisfied that the rest of the program runs correctly.

The above applies to System 6.0x.  System 7.0 provides somewhat better 
support but can also be slightly more demanding; I won't go into detail 
here because I'm not quite sure what's been announced and what has not.

David Casseres
     Exclaimer:  Hey!

time@ice.com (02/18/91)

In article <1991Feb18.164753.17148@cbnewsk.att.com>, ech@cbnewsk.att.com (ned.horvath) writes:
> But don't rip out ALL the initializations: for reasons that are arcane and
> have no reasonable explanation -- i.e. please take this one on faith, boys
> and girls, it works for me and people far smarter than me who don't
> understand it either -- leave in the calls to InitGraf and InitFonts.

InitGraf() is required to get certain globals (QD only?) established isn't it?

-------------------------------------------------------------
Tim Endres                |  time@ice.com
ICE Engineering           |  uupsi!ice.com!time
8840 Main Street          |  Voice            FAX
Whitmore Lake MI. 48189   |  (313) 449 8288   (313) 449 9208

ech@cbnewsk.att.com (ned.horvath) (02/19/91)

From article <12126@goofy.Apple.COM>, by casseres@apple.com (David Casseres):
> In article <1991Feb14.150442.1@gsbacd.uchicago.edu> 
> gft_robert@gsbacd.uchicago.edu (opcode ranger) writes:
>> What are the issues involved in making an app "background only".
> 
> To write a faceless background app (FBA):  first of all, rip out 
> everything that has to do with windows or menus.  Don't forget to rip out 
> things like InitWindows, and don't forget that dialogs and alerts are 
> windows too.

But don't rip out ALL the initializations: for reasons that are arcane and
have no reasonable explanation -- i.e. please take this one on faith, boys
and girls, it works for me and people far smarter than me who don't
understand it either -- leave in the calls to InitGraf and InitFonts.

=Ned Horvath=
ehorvath@attmail.com