home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Genie / Projects / Pedestal / Source / Sources / Ped1AppProcess.cc next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  2.7 KB  |  130 lines

  1. /*    =================
  2.  *    Ped1AppProcess.cc
  3.  *    =================
  4.  */
  5.  
  6. #include "PedestalDebugging.h"
  7.  
  8. #include "Ped1AppProcess.hh"
  9.  
  10. #include "Ped0MacToolbox.hh"
  11.  
  12. // Pedestal classes
  13. #include "PedApplication.hh"
  14.  
  15. /*
  16.     Are the QD globals declared yet?  It depends on the runtime library.
  17.     We have no way of determining which library we'll be linked with,
  18.     so first we check a macro that can be defined in a makefile.
  19.     If that's not defined, then we guess the probable library based on
  20.     the compiler, and decide based on that.
  21. */
  22.  
  23. #if defined(PREDECLARED_QDGLOBALS) && !PREDECLARED_QDGLOBALS \
  24. || !defined(PREDECLARED_QDGLOBALS) && !defined(__MWERKS__)
  25. QDGlobals qd;
  26. #endif
  27.  
  28. EProcessState Ped1AppProcess::sProcessState = kProcessNull;
  29. Ped1AppProcess *Ped1AppProcess::sMe = NULL;
  30.  
  31. Ped1AppProcess::Ped1AppProcess()
  32. : mMainModule(NULL)
  33. {
  34.     // The app process uses global resources, so we can only have one.
  35.     // If this isn't the first one, we're in trouble!
  36.     if (sProcessState > kProcessNull)
  37.         throw;
  38.     sProcessState = kProcessInstantiated;
  39.     sMe = this;
  40. }
  41.  
  42. Ped1AppProcess::~Ped1AppProcess()
  43. {
  44. }
  45.  
  46. Ped1AppProcess &
  47. Ped1AppProcess::Me()
  48. {
  49.     if (sMe == NULL)
  50.         throw;
  51.     
  52.     return *sMe;
  53. }
  54.  
  55. PedApplication &
  56. Ped1AppProcess::MainModule()
  57. {
  58.     if (mMainModule == NULL)
  59.         throw;
  60.     
  61.     return *mMainModule;
  62. }
  63.  
  64. void
  65. Ped1AppProcess::Init()
  66. {
  67.     sProcessState = kProcessInitializing;
  68.     
  69.     // Initialize the Mac Toolbox.
  70.     Ped0MacToolbox::InitToolbox();
  71.     // Perform initial memory optimization.
  72.     Ped0MacToolbox::InitMemory(0);
  73.     
  74.     // Assuming we didn't open any resource files before instantiating
  75.     // the app process, ours is current.
  76.     mResFile = ::CurResFile();
  77.     // Using our resource file's access path, locate it in the file system.
  78.     {
  79.         FCBPBRec pb;
  80.         OSErr err;
  81.         pb.ioNamePtr = mFSS.name;
  82.         pb.ioVRefNum = 0;
  83.         pb.ioRefNum = mResFile;
  84.         pb.ioFCBIndx = 0;
  85.         err = ::PBGetFCBInfoSync(&pb);
  86.         if (err != noErr)
  87.             throw;
  88.         mFSS.vRefNum = pb.ioFCBVRefNum;
  89.         mFSS.parID = pb.ioFCBParID;
  90.     }
  91.     // Read our version resource.
  92.     VersRecHndl versH = VersRecHndl(::Get1Resource('vers', 1));
  93.     if (versH)
  94.         mVersion = **versH;
  95.     else {
  96.         *(UInt32 *)&mVersion.numericVersion = 0;
  97.         mVersion.countryCode = 0;
  98.         mVersion.shortVersion[0] = (unsigned char)0;
  99.     }
  100.     Ped0MacToolbox::InitObjectSupportLibrary();
  101.     
  102.     sProcessState = kProcessReady;
  103. }
  104.  
  105. // Designated method
  106. void
  107. Ped1AppProcess::Call(PedApplication &inApp)
  108. {
  109.     if (sProcessState != kProcessReady)
  110.         throw;
  111.     
  112.     // Save the module pointer, so we can replace it when we're done.
  113.     // It may be NULL or already set.
  114.     PedApplication *oldModule = mMainModule;
  115.     
  116.     mMainModule = &inApp;
  117.     sProcessState = kProcessRunning;
  118.     inApp.Run();
  119.     sProcessState = kProcessExiting;
  120.     mMainModule = oldModule;
  121. }
  122.  
  123. void
  124. Ped1AppProcess::Call()
  125. {
  126.     PedApplication app;
  127.     
  128.     Call(app);
  129. }
  130.