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

  1. /*
  2.     File:        TSerialSchedulerExample.cp
  3.  
  4.     Contains:    This module shows an example of the TSerialScheduler class.
  5.  
  6.     Copyright:    © 1993-1994 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #include "TInitSLM.h"            // the TInitSLM class and SLM include files
  11. #include "TSchedulerExample.h"
  12.  
  13. ///————————————————————————————————————————————————————————————————————————————————————
  14. ///    CONSTANTS
  15. ///————————————————————————————————————————————————————————————————————————————————————
  16.  
  17. const unsigned  kNumofStudents = 8;        //     no. of students                            
  18.  
  19.  
  20. ///————————————————————————————————————————————————————————————————————————————————————
  21. ///    GLOBALS
  22. ///————————————————————————————————————————————————————————————————————————————————————
  23.  
  24. // array of student names
  25. char    *gStudents[kNumofStudents] ={"John Sculley",
  26.                                      "Jane Doe    ", 
  27.                                      "Bill Clinton",
  28.                                      "George Bush ", 
  29.                                      "Mick Jagger ", 
  30.                                      "Ren & Stimpy",
  31.                                      "Joe Montana ", 
  32.                                      "Al Einstein "};
  33.  
  34. // grades for the above students
  35. Grade    gGrades[kNumofStudents]    ={kB, kA, kA, kF, kA, kC, kB, kB};
  36.  
  37. ///————————————————————————————————————————————————————————————————————————————————————
  38. ///    PROTOTYPES
  39. ///————————————————————————————————————————————————————————————————————————————————————
  40. static void memory_error();
  41.  
  42. /*————————————————————————————————————————————————————————————————————————————————————
  43.     main 
  44.     
  45.     This example schedules a list of student to be displayed depending to first come
  46.     first serve bases. First it creates a TSerialScheduler, then for each student it
  47.     schedules a TReport operation. This operation once invoked, displays the student's
  48.     name and his/her grade. The operations are executed depending in the order that
  49.     they are scheduled.
  50. ————————————————————————————————————————————————————————————————————————————————————*/
  51. main() 
  52. {    
  53.     TInitSLM initLibraryManager;        // initialize the shared library manager
  54.     
  55.     if( initLibraryManager.Failed() )    // If we failed, let's go home
  56.         return 1;
  57.  
  58.     TReport                *thereport[kNumofStudents];
  59.     TSerialScheduler     *reportScheduler;
  60.     
  61.     TRY
  62.         reportScheduler = new TSerialScheduler;// create an instance of Serial Scheduler
  63.         FailNULL( reportScheduler, kASLMOutOfMemoryErr, NULL );
  64.     
  65.         // for each student schedule a TOperation to report the grade
  66.         for( short i=0; i<kNumofStudents; i++ ) {
  67.             FailNULL(thereport[i] = new TReport, kASLMOutOfMemoryErr, NULL );
  68.             thereport[i]->NewStudent( gStudents[i] );
  69.             thereport[i]->SetGrade( gGrades[i] );
  70.             reportScheduler->Schedule( thereport[i] );
  71.         }
  72.         // display the report cards in order scheduled
  73.         cout << "Displaying report cards in order scheduled\n" << endl;
  74.         reportScheduler->Run();    
  75.     
  76.         delete reportScheduler;            // great, we are done now
  77.     CATCH_ALL
  78.         memory_error();                    // just in case anything ever failed
  79.     ENDTRY
  80.  
  81.     return 0;
  82. }
  83.  
  84. /*————————————————————————————————————————————————————————————————————————————————————
  85.     memory_error
  86.     
  87.     error handler for new.
  88. ————————————————————————————————————————————————————————————————————————————————————*/
  89. static void memory_error()
  90. {
  91.     cout<<"Memory failure, not enough space available" << endl;
  92. }
  93.  
  94.