home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / include / krasyncm.hpp next >
Text File  |  1997-02-23  |  2KB  |  69 lines

  1. // Kroni's Classes: Object for asynchronous main function
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: krasyncm.hpp
  4.  
  5. // **********************************************************************************************************
  6. //
  7. // defines these classes:
  8. //
  9. //   KrAsyncMain             Define a main() function which is independent of the message queue
  10. //
  11. // defines those global symbols for private use:
  12. //
  13. //   _KrEventList
  14. //
  15. // **********************************************************************************************************
  16.  
  17.  
  18. #ifndef __KRASYNCM_HPP__
  19. #define __KRASYNCM_HPP__
  20.  
  21.  
  22. #include <icmdhdr.hpp>                           // ICommandHandler & Co.
  23. #include <ithread.hpp>                           // IThreadFn & Co.
  24. #include <istring.hpp>                           // IString
  25.  
  26.  
  27. class _KrEventList
  28. {
  29. public:
  30.   IEvent * event;
  31.   _KrEventList * next;
  32. };
  33.  
  34.  
  35. class KrAsyncMain : virtual public ICommandHandler, virtual public IThreadFn
  36. {
  37.  
  38. public:
  39.  
  40.   KrAsyncMain (IWindow * mainWindow);            // Construct this from your main frame window
  41.  
  42.   typedef enum {cmdStartUp = 1, cmdFuncFinished, cmdUser} commands;
  43.                                                  // All commands reserved for the object's internal use.
  44.                                                  //   Use only cmdUser and higher for your own commands
  45.   virtual void main (IEvent & event) = 0;        // Overwrite this to define your actual new main function
  46.  
  47.   virtual IString asString() const {return "KrAsyncMain: no Info available";};
  48.   virtual IString asDebugInfo() const {return "KrAsyncMain";};
  49.  
  50. private:
  51.  
  52.   virtual Boolean command (ICommandEvent & event);
  53.                                                  // This function starts the thread when needed
  54.   IThread thread;
  55.   virtual void run ();                           // Internal thread function
  56.   IEvent event;                                  // The event passed to main ()
  57.   ISemaphoreHandle sem;                          // handles stop/resume of asynchronous thread
  58.  
  59.   IWindow * window;
  60.   Boolean threadRunning;                         // Is the thread already running?
  61.   _KrEventList *listStart, *listEnd;             // List of unprocessed messages
  62.   IReference <IThreadFn> funcRef;                // Reference for this object as a thread function
  63.  
  64. };
  65.  
  66.  
  67. #endif
  68.  
  69.