home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / Example Tools / Sources / TTimeSchedulerExample.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  1.6 KB  |  52 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TTimeSchedulerExample.cp
  3.  
  4.     Contains:    This module shows an example the TTimeScheduler class.
  5.  
  6.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #include "TInitSLM.h"            // the TInitSLM class and SLM include files
  11. #include "TTimeSchedulerExample.h"
  12.  
  13. /*————————————————————————————————————————————————————————————————————————————————————
  14.     main 
  15.     
  16.     This example simply schedules an operation to occur after a given time. First we
  17.     create an instance of TTimeSheduler, Next we create an instance of the operation. Here
  18.     the operation simply beeps twice to let us know that it has fired.
  19. ————————————————————————————————————————————————————————————————————————————————————*/
  20. main() 
  21. {    
  22.     TInitSLM initLibraryManager;            // initialize the shared library manager
  23.     
  24.     if( initLibraryManager.Failed() )        // If we failed, let's go home
  25.         return 1;
  26.  
  27.     TAlert                *thebeeper;            // This operation will beep twice        
  28.     TTimeScheduler         *timeScheduler;
  29.     
  30.     if( timeScheduler = new TTimeScheduler )
  31.         if( thebeeper = new TAlert() ) {    // create a new alert operation
  32.             thebeeper->SetTime( 2000 );        // alert us roughly after 2 seconds
  33.             
  34.             TStopwatch *stopwatch = new TStopwatch;    // let's see if it really fires after 2 seconds
  35.             
  36.             timeScheduler->Schedule( thebeeper );    // schedule the operation
  37.             
  38.             while (!thebeeper->GetDone());        // loop until the operation fires
  39.             
  40.             if (stopwatch)
  41.                 cout << "Fired after " << stopwatch->ElapsedMilliseconds()
  42.                     << " milliseconds" << endl;
  43.             
  44.             delete timeScheduler;            // free the Scheduler
  45.             delete thebeeper;                // free the alert operation
  46.             delete stopwatch;                // free the stopwatch
  47.         }
  48.             
  49.     return 0;
  50. }
  51.  
  52.