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 / TTaskSchedulerExample.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  3.3 KB  |  97 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TTaskSchedulerExample.cp
  3.  
  4.     Contains:    This module shows an example of the TTaskScheduler 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 "TTaskSchedulerExample.h"
  12.  
  13. #include <Events.h>
  14. #include <Desk.h>
  15.  
  16. ///————————————————————————————————————————————————————————————————————————————————————
  17. ///    CONSTANTS
  18. ///————————————————————————————————————————————————————————————————————————————————————
  19.  
  20. const unsigned  kNumArcs = 360*2;            //     no. of arcs to draw                            
  21.  
  22.  
  23. ///————————————————————————————————————————————————————————————————————————————————————
  24. ///    GLOBALS
  25. ///————————————————————————————————————————————————————————————————————————————————————
  26.  
  27. static void init_toolbox( WindowPtr *window );
  28.  
  29. /*————————————————————————————————————————————————————————————————————————————————————
  30.     main 
  31.     
  32.     This example shows the use of a TTaskScheduler. The TaskScheduler is going to sche-
  33.     dule a FillArc operation on a given window.  We allocate the window before hand,
  34.     so the operation does not need to wory about it. TTaskScheduler is derived from
  35.     from TPriorityScheduler, and operations are prioritised depending on the order 
  36.     of their scheduling. The TTaskScheduler does not have run method, it automatically
  37.     gets called during SystemTask. When we call SystemTask all the operations will be
  38.     processed. Note you can also call WaitNextEvent to get the TTaskScheduler to run.
  39. ————————————————————————————————————————————————————————————————————————————————————*/
  40.  
  41. main() 
  42. {    
  43.     TInitSLM initLibraryManager;        // initialize the shared library manager
  44.     
  45.     if( initLibraryManager.Failed() )    // If we failed, let's go home
  46.         return 1;
  47.     
  48.     WindowPtr    window;        
  49.     init_toolbox( &window );            // initialize the tool box and our window
  50.     
  51.     TArcTask        *thearcs[kNumArcs];
  52.     TTaskScheduler     taskscheduler;        // create a TTaskScheduler
  53.     
  54.     // create and schedule kNumArcs TArcTasks
  55.     for( short i=0; i<kNumArcs; i++ ) {
  56.         // create a TArcTask
  57.         thearcs[i] = new TArcTask( window, i );
  58.         
  59.         // Give each successive operation a lower priority then the previous
  60.         // one so they are processed the ordered created. Actually if they
  61.         // have the same priority they are processed in the ordered schedule,
  62.         // so we could also have scheduled them in the opposite order.
  63.         thearcs[i]->SetPriority( kNormalPriority + i*kToLowerPriority );
  64.         
  65.         // schedule the operation
  66.         taskscheduler.Schedule( thearcs[i] );
  67.     }
  68.  
  69.     SystemTask();    // call SystemTask so our operations will be processed
  70.  
  71.     DisposeWindow( window );            // close the window
  72.     
  73.     return 0;
  74. }
  75.  
  76. /*————————————————————————————————————————————————————————————————————————————————————
  77.     init_toolbox
  78.     
  79.     initalize the macintosh toolbox
  80. ————————————————————————————————————————————————————————————————————————————————————*/
  81. static void init_toolbox( WindowPtr *window )
  82. {
  83.     // Initialize the macintosh toolbox
  84.     MaxApplZone();
  85.  
  86.     InitGraf( (Ptr)&qd.thePort );
  87.     InitFonts();
  88.     InitWindows();
  89.     InitDialogs( nil );
  90.     InitCursor();
  91.  
  92.     // create a window to draw our arcs in
  93.     Rect    rect;
  94.     *window = NewCWindow( 0L, &rect, "\p", false, documentProc,(WindowPtr)-1L, true, 0L );                        
  95.     MoveWindow( *window, qd.screenBits.bounds.left+10, qd.screenBits.bounds.top+40, true );
  96.     SizeWindow( *window, 100, 100, false );
  97. }