home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / os2thred.zip / MSGTHRD.H < prev    next >
C/C++ Source or Header  |  1994-06-09  |  2KB  |  66 lines

  1. // Listing 5 -- MsgThrd.h
  2.  
  3. #if !defined(MSGTHREAD_INC)
  4. #define MSGTHREAD_INC
  5.  
  6. //----------------------------- Includes ---------------------------
  7.  
  8. #include "QThread.h"
  9. #include "MsgQ.h"
  10.  
  11. //----------------------------- defines ----------------------------
  12.  
  13. const USHORT MSG_DEF_QSIZE        = 10;
  14.  
  15. //----------------------------------------------------
  16. // The following two values are reserved messages ID's.
  17. // All MsgThread's must be prepared to receive them.
  18. // All other message ID's are user defined.
  19.  
  20. const ULONG MSG_THRD_SHUTDOWN    = 0;  // Received during shutdown
  21. const ULONG MSG_THRD_STARTUP    = 1;  // Received at startup
  22.  
  23. const ULONG MSG_THRD_USER        = 2;  // First user defined msg ID
  24.  
  25. //------------------------------ Types -----------------------------
  26.  
  27. typedef VOID FNMSGTHRDPROC (ULONG objAddr, 
  28.                             ULONG msgID, MPARAM mp1, MPARAM mp2, 
  29.                             ULONG ulParam);
  30.                         
  31. typedef FNMSGTHRDPROC* PFNMSGTHRDPROC;
  32.  
  33. //------------------------------ Class -----------------------------
  34.  
  35. class MsgThread : public QThread {
  36. public:
  37.     MsgThread (    PFNMSGTHRDPROC pfn, 
  38.                 USHORT usQSize=MSG_DEF_QSIZE,
  39.                 ULONG ulStack=THRDS_DEF_STACK);
  40.     ~MsgThread ();
  41.     
  42.     VOID SendMsg (ULONG objAddr, ULONG msgID, MPARAM mp1, MPARAM mp2)
  43.             { pMsgQ->PostMsg(objAddr, msgID, mp1, mp2); }
  44.  
  45. protected:
  46.     BOOL GetMessage (QMSG & qmsg) 
  47.             { return pMsgQ->WaitMsg(qmsg); }
  48.     
  49.     VOID DispatchMsg (QMSG & qmsg) 
  50.             { pfnMsg((ULONG)qmsg.hwnd,qmsg.msg,qmsg.mp1,qmsg.mp2,ulParam); }
  51.             
  52.     VOID Startup (ULONG ulArg)
  53.             { pfnMsg((ULONG)this, MSG_THRD_STARTUP, 
  54.                      (MPARAM)ulArg, (MPARAM)NULL,ulArg); }
  55.             
  56.     BOOL Shutdown(ULONG ulArg);
  57.         
  58. private:
  59.     MsgQueue*        pMsgQ;        // pointer to msg queue
  60.     PFNMSGTHRDPROC    pfnMsg;        // pointer to client thread proc
  61.  
  62. };
  63.  
  64. //-------------------------- End of Header -------------------------
  65. #endif
  66.