#include <camnet.h>
Public Types | |
enum | EVENTS { EVENT_DEACTIVATE = 0, EVENT_CHANGE } |
Public Member Functions | |
CacheMonitor () | |
| |
~CacheMonitor () | |
| |
BOOL | Activate (String_256 &strCachePath) |
| |
BOOL | Deactivate () |
| |
void | IgnoreEvents (INT32 nEvents) |
Static Private Member Functions | |
static void | OnCacheEvent () |
| |
static unsigned __stdcall | Monitor (LPVOID lpParam) |
| |
Private Attributes | |
HANDLE | m_hMonitorThread |
unsigned | m_dwMonitorThreadID |
Static Private Attributes | |
static HANDLE | rgEvents [2] |
static CRITICAL_SECTION | m_CacheDataCriticalSection |
static volatile INT32 | m_nIgnoreCount |
Friends | |
class | DownloadCache |
Definition at line 505 of file camnet.h.
|
Definition at line 508 of file camnet.h. 00508 {EVENT_DEACTIVATE = 0, EVENT_CHANGE};
|
|
Definition at line 1794 of file camnet.cpp. 01795 { 01796 m_hMonitorThread = NULL; 01797 m_dwMonitorThreadID = 0; 01798 ::InitializeCriticalSection(&m_CacheDataCriticalSection); 01799 }
|
|
Definition at line 1812 of file camnet.cpp. 01813 { 01814 if (m_hMonitorThread && m_dwMonitorThreadID) 01815 Deactivate(); 01816 ::DeleteCriticalSection(&m_CacheDataCriticalSection); 01817 }
|
|
Definition at line 1831 of file camnet.cpp. 01832 { 01833 if (rgEvents[EVENT_DEACTIVATE] || rgEvents[EVENT_CHANGE]) 01834 return FALSE; 01835 if (!(rgEvents[EVENT_DEACTIVATE] = ::CreateEvent(NULL, TRUE, FALSE, NULL))) 01836 return FALSE; 01837 if ((rgEvents[EVENT_CHANGE] = ::FindFirstChangeNotification(strCachePath, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME)) == INVALID_HANDLE_VALUE) 01838 return FALSE; 01839 if (!(m_hMonitorThread = (HANDLE) ::_beginthreadex(NULL, 0, &Monitor, (LPVOID) rgEvents, 0, &m_dwMonitorThreadID))) 01840 return FALSE; 01841 return TRUE; 01842 }
|
|
Definition at line 1891 of file camnet.cpp. 01892 { 01893 BOOL bRet = TRUE; 01894 if (!m_hMonitorThread) 01895 return bRet; 01896 if (!::SetEvent(rgEvents[0])) 01897 goto TERMINATE; 01898 if (::WaitForSingleObject(m_hMonitorThread, 1000) == WAIT_TIMEOUT) 01899 { 01900 TERMINATE: 01901 bRet = FALSE; 01902 ERROR3("Warning: monitor thread not released - will attempt to terminate it"); 01903 if (!::TerminateThread(m_hMonitorThread, 0xFFFFFFFF)) 01904 { 01905 TCHAR szErrorMsg[96]; 01906 wsprintf(szErrorMsg, "Cannot kill zombie thread, thread ID = %lx", m_dwMonitorThreadID); 01907 ERROR3(szErrorMsg); 01908 } 01909 } 01910 ::CloseHandle(m_hMonitorThread); 01911 m_hMonitorThread = NULL; 01912 m_dwMonitorThreadID = 0; 01913 ::CloseHandle(rgEvents[0]); 01914 ::FindCloseChangeNotification(rgEvents[1]); 01915 memset(rgEvents, 0x00, sizeof(rgEvents)); 01916 return bRet; 01917 }
|
|
Definition at line 513 of file camnet.h. 00513 {m_nIgnoreCount += nEvents;}
|
|
Definition at line 1855 of file camnet.cpp. 01856 { 01857 TRACEUSER( "adrian", _T("Entering monitor thread\n")); 01858 HANDLE* lpEvents = (HANDLE*) pParam; 01859 while (::WaitForMultipleObjects(2, lpEvents, FALSE, INFINITE) != WAIT_OBJECT_0) 01860 { 01861 TRACEUSER( "adrian", _T("\n\n\nCache event detected\n")); 01862 if (m_nIgnoreCount > 0) 01863 { 01864 m_nIgnoreCount--; 01865 #ifdef _DEBUG 01866 TCHAR szMsg[96]; 01867 wsprintf(szMsg, "Cache ignore count decremented to %d\n\n\n", m_nIgnoreCount); 01868 TRACEUSER("adrian", szMsg); 01869 #endif 01870 } 01871 else 01872 OnCacheEvent(); 01873 if (!::FindNextChangeNotification(*(lpEvents + 1))) 01874 ::_endthreadex(0xFFFFFFFF); 01875 } 01876 TRACEUSER( "adrian", _T("Exiting monitor thread\n")); 01877 return 0; 01878 }
|
|
Definition at line 1931 of file camnet.cpp. 01932 { 01933 String_256 strErrorMsg(_R(IDS_CACHEMODIFIED)); 01934 String_256 strCaption(_R(IDS_ERRORBOX_WARNING)); 01935 ::MessageBox(NULL, strErrorMsg, strCaption, MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_OK); 01936 ::EnterCriticalSection(&m_CacheDataCriticalSection); 01937 DownloadCache::Refresh(); 01938 ::LeaveCriticalSection(&m_CacheDataCriticalSection); 01939 }
|
|
|
|
|
|
|
|
|
|
|
|
|