home *** CD-ROM | disk | FTP | other *** search
- /* =================
- * Ped1AppProcess.cc
- * =================
- */
-
- #include "PedestalDebugging.h"
-
- #include "Ped1AppProcess.hh"
-
- #include "Ped0MacToolbox.hh"
-
- // Pedestal classes
- #include "PedApplication.hh"
-
- /*
- Are the QD globals declared yet? It depends on the runtime library.
- We have no way of determining which library we'll be linked with,
- so first we check a macro that can be defined in a makefile.
- If that's not defined, then we guess the probable library based on
- the compiler, and decide based on that.
- */
-
- #if defined(PREDECLARED_QDGLOBALS) && !PREDECLARED_QDGLOBALS \
- || !defined(PREDECLARED_QDGLOBALS) && !defined(__MWERKS__)
- QDGlobals qd;
- #endif
-
- EProcessState Ped1AppProcess::sProcessState = kProcessNull;
- Ped1AppProcess *Ped1AppProcess::sMe = NULL;
-
- Ped1AppProcess::Ped1AppProcess()
- : mMainModule(NULL)
- {
- // The app process uses global resources, so we can only have one.
- // If this isn't the first one, we're in trouble!
- if (sProcessState > kProcessNull)
- throw;
- sProcessState = kProcessInstantiated;
- sMe = this;
- }
-
- Ped1AppProcess::~Ped1AppProcess()
- {
- }
-
- Ped1AppProcess &
- Ped1AppProcess::Me()
- {
- if (sMe == NULL)
- throw;
-
- return *sMe;
- }
-
- PedApplication &
- Ped1AppProcess::MainModule()
- {
- if (mMainModule == NULL)
- throw;
-
- return *mMainModule;
- }
-
- void
- Ped1AppProcess::Init()
- {
- sProcessState = kProcessInitializing;
-
- // Initialize the Mac Toolbox.
- Ped0MacToolbox::InitToolbox();
- // Perform initial memory optimization.
- Ped0MacToolbox::InitMemory(0);
-
- // Assuming we didn't open any resource files before instantiating
- // the app process, ours is current.
- mResFile = ::CurResFile();
- // Using our resource file's access path, locate it in the file system.
- {
- FCBPBRec pb;
- OSErr err;
- pb.ioNamePtr = mFSS.name;
- pb.ioVRefNum = 0;
- pb.ioRefNum = mResFile;
- pb.ioFCBIndx = 0;
- err = ::PBGetFCBInfoSync(&pb);
- if (err != noErr)
- throw;
- mFSS.vRefNum = pb.ioFCBVRefNum;
- mFSS.parID = pb.ioFCBParID;
- }
- // Read our version resource.
- VersRecHndl versH = VersRecHndl(::Get1Resource('vers', 1));
- if (versH)
- mVersion = **versH;
- else {
- *(UInt32 *)&mVersion.numericVersion = 0;
- mVersion.countryCode = 0;
- mVersion.shortVersion[0] = (unsigned char)0;
- }
- Ped0MacToolbox::InitObjectSupportLibrary();
-
- sProcessState = kProcessReady;
- }
-
- // Designated method
- void
- Ped1AppProcess::Call(PedApplication &inApp)
- {
- if (sProcessState != kProcessReady)
- throw;
-
- // Save the module pointer, so we can replace it when we're done.
- // It may be NULL or already set.
- PedApplication *oldModule = mMainModule;
-
- mMainModule = &inApp;
- sProcessState = kProcessRunning;
- inApp.Run();
- sProcessState = kProcessExiting;
- mMainModule = oldModule;
- }
-
- void
- Ped1AppProcess::Call()
- {
- PedApplication app;
-
- Call(app);
- }
-