00001 //--------------------------------------------------------------------------- 00002 /// \file CATMsgThread.h 00003 /// \brief Message Thread Base Class 00004 /// \ingroup CAT 00005 /// 00006 /// Copyright (c) 2008 by Michael Ellison. 00007 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00008 /// 00009 // $Author: mikeellison $ 00010 // $Date: 2008-01-23 08:59:02 -0600 (Wed, 23 Jan 2008) $ 00011 // $Revision: $ 00012 // $NoKeywords: $ 00013 //--------------------------------------------------------------------------- 00014 00015 #ifndef CATMsgThread_H_ 00016 #define CATMsgThread_H_ 00017 00018 #include "CATThread.h" 00019 #include "CATSignal.h" 00020 00021 /// \class CATMsgThread 00022 /// \brief Message Thread Base Class 00023 /// \ingroup CAT 00024 /// 00025 /// CATMsgThread is the class to inherit from when you want a thread 00026 /// that responds to messages and has a periodic loop. 00027 class CATMsgThread : protected CATThread 00028 { 00029 public: 00030 /// Thread construction 00031 CATMsgThread(); 00032 00033 /// Thread destruction 00034 virtual ~CATMsgThread(); 00035 00036 /// Start a thread. 00037 virtual bool Start( CATUInt32 pollFreq); 00038 00039 /// Stop a thread, cleanly if possible. 00040 virtual void Stop ( CATUInt32 timeout = (CATUInt32)-1); 00041 00042 /// Called once per timeout 00043 virtual void OnThreadIdle(); 00044 00045 /// Called when messages are received 00046 virtual CATUInt32 OnThreadMessage(CATUInt32 msg, CATUInt32 wParam, CATUInt32 lParam); 00047 00048 /// Posts a message to the thread 00049 bool Post(CATUInt32 msg, CATUInt32 wParam, CATUInt32 lParam); 00050 00051 protected: 00052 virtual void ThreadFunction(); 00053 CATUInt32 fPollFreq; 00054 CATSignal fExitSignal; 00055 }; 00056 00057 #endif //CATMsgThread_H_