00001 #ifndef __TIMER_H 00002 #define __TIMER_H 00003 00004 #include <iostream> 00005 #include <string> 00006 #include <list> 00007 #include <pthread.h> 00008 #include "Mutex.h" 00009 #include "Condition.h" 00010 #include "TimerNode.h" 00011 00012 using namespace std; 00013 00014 class Timer: public BasicObject 00015 { 00016 public: 00017 void addEvent(int millisec, void* (*func)(void*), void* arg, bool* set); 00018 virtual void toStream(std::ostream&); 00019 00020 void setName(string); 00021 string getName(); 00022 00023 protected: 00025 Timer(); 00026 virtual ~Timer(); 00027 00029 static void* timerThread(void*); 00030 void timerThreadImpl(); 00031 00033 virtual void doAction(TimerNode*) = 0; 00034 00036 pthread_t m_timerThreadId; 00037 00039 Condition m_eventListSignal; 00040 00042 Mutex m_eventListMutex; 00043 00045 list<TimerNode*> m_eventList; 00046 00048 bool m_destroyed; 00049 00051 string m_name; 00052 }; 00053 00054 #endif // __TIMER_H