00001 00002 // Program Name: taskqueue.h 00003 // 00004 // Purpose - Used to process delayed tasks 00005 // 00006 // Created By : David Blain Created On : Oct. 24, 2005 00007 // Modified By : Modified On: 00008 // 00010 00011 #ifndef __TASKQUEUE_H__ 00012 #define __TASKQUEUE_H__ 00013 00014 // POSIX headers 00015 #include <sys/types.h> 00016 #ifndef USING_MINGW 00017 #include <sys/socket.h> 00018 #include <netinet/in.h> 00019 #include <arpa/inet.h> 00020 #endif // USING_MINGW 00021 00022 // C++ headers 00023 #include <map> 00024 00025 // Qt headers 00026 #include <qthread.h> 00027 #include <qsocketdevice.h> 00028 00029 // MythTV headers 00030 #include "upnputil.h" 00031 #include "refcounted.h" 00032 00033 class Task; 00034 class TaskQueue; 00035 00037 // Typedefs 00039 00040 typedef std::multimap< TaskTime, Task *> TaskMap; 00041 00044 // 00045 // Task Class Definition 00046 // 00049 00050 class Task : public RefCounted 00051 { 00052 protected: 00053 static long m_nTaskCount; 00054 00055 long m_nTaskId; 00056 00057 protected: 00058 00059 // Destructor protected to force use of Release Method 00060 00061 virtual ~Task(); 00062 00063 public: 00064 00065 Task(); 00066 00067 long Id() { return( m_nTaskId ); } 00068 00069 virtual void Execute( TaskQueue *pQueue ) = 0; 00070 virtual QString Name () = 0; 00071 00072 }; 00073 00074 00076 // 00078 00079 class TaskQueue : public QThread 00080 { 00081 protected: 00082 00083 TaskMap m_mapTasks; 00084 QMutex m_mutex; 00085 bool m_bTermRequested; 00086 00087 protected: 00088 00089 bool IsTermRequested(); 00090 00091 virtual void run (); 00092 00093 public: 00094 00095 TaskQueue(); 00096 virtual ~TaskQueue(); 00097 00098 void RequestTerminate ( ); 00099 00100 void Clear ( ); 00101 void AddTask ( long msec , Task *pTask ); 00102 void AddTask ( TaskTime tt, Task *pTask ); 00103 void AddTask ( Task *pTask ); 00104 00105 Task *GetNextExpiredTask ( TaskTime tt, long nWithinMilliSecs = 50 ); 00106 00107 }; 00108 00109 #endif
1.5.5