00001 00002 #ifndef _Q_TIMER_DISPATCHER_HH_ 00003 #define _Q_TIMER_DISPATCHER_HH_ 00004 00005 #include <pthread.h> 00006 #include <sys/types.h> 00007 #include <event.h> 00008 00009 #include "QError.hh" 00010 #include "QSemaphore.hh" 00011 00020 class QTimerDispatcher 00021 { 00022 public: 00024 static QTimerDispatcher& GetInstance(); 00025 00027 ~QTimerDispatcher(); 00028 00035 void AddTimer(); 00036 00038 bool HasError() const; 00040 void SetError(const QError& err); 00042 const QError& GetError() const; 00043 00044 void Cleanup(); 00045 00046 bool ThreadDone(); 00047 00048 private: 00050 QTimerDispatcher(); 00051 00053 void ExecuteThread(); 00054 00059 static void* ThreadEntryPoint(void* ptr); 00060 00061 pthread_t fThread; 00062 void* fEvBase; 00063 QError fError; 00064 static pthread_mutex_t fThreadMutex; 00065 00066 static void EventEntryPoint(int fd, short event, void * ptr); 00067 void CheckStatus(); 00068 00069 bool fDoExit; 00070 struct event fEvent; 00071 struct timeval fTimeout; 00072 00073 QSemaphore fSemaphore; 00074 }; 00075 #endif