home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / New System Software Extensions / ASLM SDK v1.1.2 / ASLM Examples / Example Tools / Sources / TTaskSchedulerExample.cp < prev    next >
Encoding:
Text File  |  1994-11-21  |  3.3 KB  |  98 lines  |  [TEXT/MPS ]

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