00001 /* 00002 Free Download Manager Copyright (c) 2003-2007 FreeDownloadManager.ORG 00003 Open Download Manager Copyright (c) 2008-2010 OpenDownloadManager.ORG 00004 */ 00005 00006 #ifndef __CAMSchedule__ 00007 #define __CAMSchedule__ 00008 00009 class CAMSchedule : private CBaseObject 00010 { 00011 public: 00012 virtual ~CAMSchedule(); 00013 00014 CAMSchedule( HANDLE ev ); 00015 00016 DWORD GetAdviseCount(); 00017 REFERENCE_TIME GetNextAdviseTime(); 00018 00019 00020 DWORD_PTR AddAdvisePacket( const REFERENCE_TIME & time1, const REFERENCE_TIME & time2, HANDLE h, BOOL periodic ); 00021 00022 HRESULT Unadvise(DWORD_PTR dwAdviseCookie); 00023 00024 REFERENCE_TIME Advise( const REFERENCE_TIME & rtTime ); 00025 00026 HANDLE GetEvent() const { return m_ev; } 00027 00028 private: 00029 00030 class CAdvisePacket 00031 { 00032 public: 00033 CAdvisePacket() 00034 {} 00035 00036 CAdvisePacket * m_next; 00037 DWORD_PTR m_dwAdviseCookie; 00038 REFERENCE_TIME m_rtEventTime; 00039 REFERENCE_TIME m_rtPeriod; 00040 HANDLE m_hNotify; 00041 BOOL m_bPeriodic; 00042 00043 CAdvisePacket( CAdvisePacket * next, LONGLONG time ) : m_next(next), m_rtEventTime(time) 00044 {} 00045 00046 void InsertAfter( CAdvisePacket * p ) 00047 { 00048 p->m_next = m_next; 00049 m_next = p; 00050 } 00051 00052 int IsZ() const 00053 { return m_next == 0; } 00054 00055 CAdvisePacket * RemoveNext() 00056 { 00057 CAdvisePacket *const next = m_next; 00058 CAdvisePacket *const new_next = next->m_next; 00059 m_next = new_next; 00060 return next; 00061 } 00062 00063 void DeleteNext() 00064 { 00065 delete RemoveNext(); 00066 } 00067 00068 CAdvisePacket * Next() const 00069 { 00070 CAdvisePacket * result = m_next; 00071 if (result->IsZ()) result = 0; 00072 return result; 00073 } 00074 00075 DWORD_PTR Cookie() const 00076 { return m_dwAdviseCookie; } 00077 }; 00078 00079 CAdvisePacket head, z; 00080 00081 volatile DWORD_PTR m_dwNextCookie; 00082 volatile DWORD m_dwAdviseCount; 00083 00084 CCritSec m_Serialize; 00085 00086 00087 DWORD_PTR AddAdvisePacket( CAdvisePacket * pPacket ); 00088 00089 const HANDLE m_ev; 00090 00091 void ShuntHead(); 00092 00093 00094 CAdvisePacket * m_pAdviseCache; 00095 DWORD m_dwCacheCount; 00096 enum { dwCacheMax = 5 }; 00097 00098 void Delete( CAdvisePacket * pLink ); 00099 00100 public: 00101 #ifdef DEBUG 00102 void DumpLinkedList(); 00103 #else 00104 void DumpLinkedList() {} 00105 #endif 00106 00107 }; 00108 00109 #endif
1.5.6