appletlaunch.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletlaunch.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include <Processes.h>
00008 #include "appletmemory.h"
00009 #include "appletlaunch.h"
00010 
00011 
00012 static Boolean appRunning (OSType appid) {
00013     
00014     /*
00015     return true if the server application is running. 
00016     */
00017     
00018     ProcessInfoRec info;
00019     ProcessSerialNumber psn;
00020     Str255 bsname;
00021     FSSpec fss;
00022     
00023     info.processInfoLength = sizeof (info);
00024     
00025     info.processName = bsname; /*place to store process name*/
00026     
00027     info.processAppSpec = &fss; /*place to store process filespec*/
00028     
00029     psn.highLongOfPSN = kNoProcess;
00030     
00031     psn.lowLongOfPSN = kNoProcess;
00032     
00033     while (GetNextProcess (&psn) == noErr) {
00034         
00035         info.processInfoLength = sizeof (ProcessInfoRec);
00036         
00037         if (GetProcessInformation (&psn, &info) != noErr)
00038             continue; /*keep going -- ignore error*/
00039         
00040         if (info.processSignature == appid)
00041             return (true);
00042         } /*while*/
00043     
00044     return (false); /*loop completed, no server*/
00045     } /*appRunning*/
00046 
00047 
00048 static Boolean hasdesktopmanager (short vnum) {
00049     
00050     GetVolParmsInfoBuffer volparms;
00051     HParamBlockRec pb;
00052     
00053     pb.volumeParam.ioVRefNum = vnum;
00054     
00055     pb.volumeParam.ioNamePtr = nil;
00056     
00057     pb.ioParam.ioBuffer = (Ptr) &volparms;
00058     
00059     pb.ioParam.ioReqCount = sizeof (volparms);
00060     
00061     if (PBHGetVolParmsSync (&pb) != noErr)
00062         return (false);
00063     
00064     return ((volparms.vMAttrib & (1 << bHasDesktopMgr)) != 0);
00065     } /*hasdesktopmanager*/
00066 
00067 
00068 static Boolean findApp (OSType appid, FSSpec *fs) {
00069     
00070     /*
00071     find the app whose creator id is appid. return true if we found it, 
00072     false otherwise.
00073     */
00074     
00075     DTPBRec dt;
00076     ParamBlockRec pb;
00077     Str255 appfname;
00078     
00079     clearbytes (&pb, (long) sizeof (pb));
00080     
00081     while (true) {
00082         
00083         ++pb.volumeParam.ioVolIndex;
00084         
00085         if (PBGetVInfoSync (&pb) != noErr)
00086             return (false);
00087         
00088         if (!hasdesktopmanager (pb.volumeParam.ioVRefNum))
00089             continue;
00090         
00091         dt.ioNamePtr = NULL;
00092         
00093         dt.ioVRefNum = pb.volumeParam.ioVRefNum;
00094         
00095         if (PBDTGetPath (&dt) != noErr)
00096             return (false);
00097         
00098         dt.ioNamePtr = (StringPtr) &appfname;
00099         
00100         dt.ioIndex = 0;
00101         
00102         dt.ioFileCreator = appid;
00103         
00104         if (PBDTGetAPPLSync (&dt) == noErr) {
00105         
00106             if (FSMakeFSSpec (pb.volumeParam.ioVRefNum, dt.ioAPPLParID, appfname, fs) == noErr)
00107                 return (true);
00108             }
00109         } /*while*/
00110         
00111     return (false);
00112     } /*findApp*/
00113 
00114 
00115 static Boolean launchApp (FSSpec *fs) {
00116     
00117     LaunchParamBlockRec pb;
00118     
00119     clearbytes (&pb, (long) sizeof (pb));
00120     
00121     pb.launchAppSpec = fs;
00122     
00123     pb.launchBlockID = extendedBlock;
00124     
00125     pb.launchEPBLength = extendedBlockLen;
00126     
00127     pb.launchControlFlags = launchContinue | launchNoFileFlags/* | launchDontSwitch*/;
00128     
00129     return (LaunchApplication (&pb) == noErr);
00130     } /*launchApp*/
00131 
00132 
00133 Boolean launchServer (OSType serverid) {
00134     
00135     /*
00136     if the application whose creator id is serverid is running, return true.
00137     
00138     if not, we look for the application and try to launch it. we wait until it's 
00139     actually running and ready to receive Apple Events.
00140     */
00141     
00142     FSSpec fs;
00143     
00144     if (appRunning (serverid))
00145         return (true);
00146         
00147     if (!findApp (serverid, &fs))
00148         return (false);
00149         
00150     if (!launchApp (&fs))
00151         return (false);
00152         
00153     while (!appRunning (serverid)) {
00154         
00155         EventRecord ev;
00156         
00157         EventAvail (everyEvent, &ev);
00158         } /*while*/
00159         
00160     return (true);
00161     } /*launchServer*/
00162     
00163     

Generated on Wed May 31 18:19:42 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6