home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / DCLAP 4j / DClap / DTaskCentral.cpp < prev    next >
Encoding:
Text File  |  1995-12-17  |  1.5 KB  |  80 lines  |  [TEXT/R*ch]

  1. // DTaskCentral.cp
  2. // d.g.gilbert
  3.  
  4.  
  5. #include "DTaskCentral.h"
  6. #include "DTask.h"
  7. #include "DTaskMaster.h"
  8. #include "DList.h"
  9. #include "DCommand.h"
  10.  
  11. DTaskCentral *gTaskCentral = NULL;
  12.  
  13.  
  14.  
  15. //class DTaskCentral : public DObject
  16.  
  17. DTaskCentral::DTaskCentral() 
  18. {
  19.     fTaskQueue= new DList();
  20. }
  21.  
  22. DTaskCentral::~DTaskCentral() 
  23. {
  24.     fTaskQueue->FreeAllObjects();
  25.     delete fTaskQueue;
  26. }
  27.  
  28. void DTaskCentral::AddTask(DTask* theTask) 
  29. {
  30.     fTaskQueue->Queue( theTask);
  31. }
  32.         
  33. void DTaskCentral::NextTask() 
  34. {
  35.     DTask* next= (DTask*) fTaskQueue->Dequeue();  
  36.     if (next) {
  37.         if (next->fSource && next->fSource->IsMyTask(next)) {
  38.             if (next->fRepeat) AddTask(next);
  39.             else next->suicide();
  40.             }
  41.         else {
  42.             // if next->fSource doesn't handle (or its handler chain)
  43.             // then pass task on to a co-handler chain???        
  44.             next->Process(); // ? added mar'95
  45.             next->suicide();
  46.             }
  47.         }
  48. }
  49.  
  50.  
  51. void DTaskCentral::FinishTasksByOwner(DTaskMaster* taskOwner) 
  52. {
  53.     if (taskOwner) {
  54.         DTask* taskat;
  55.         long i, n= fTaskQueue->GetSize();
  56.             // first handle owner tasks in order
  57.         for (i=0; i<n; i++) {
  58.             taskat= (DTask*) fTaskQueue->At(i);  
  59.             if (taskOwner == taskat->fSource) {
  60.                 taskat->fSource->IsMyTask(taskat);
  61.                 taskat->suicide();
  62.                 }
  63.             }
  64.             // now delete owner tasks, in back-order
  65.         for (i=n-1; i>=0; i--) {
  66.             taskat= (DTask*) fTaskQueue->At(i);  
  67.             if (taskOwner == taskat->fSource)  
  68.                 fTaskQueue->AtDelete(i);
  69.             }
  70.             
  71.         if (gLastCommand && gLastCommand->fSource == taskOwner) {
  72.             delete gLastCommand; 
  73.             gLastCommand= NULL; 
  74.             }  
  75.         }
  76. }
  77.  
  78.             
  79.  
  80.