DownloadCache::CacheMonitor Class Reference

#include <camnet.h>

List of all members.

Public Types

enum  EVENTS { EVENT_DEACTIVATE = 0, EVENT_CHANGE }

Public Member Functions

 CacheMonitor ()
 
  • constructor

 ~CacheMonitor ()
 
  • destructor

BOOL Activate (String_256 &strCachePath)
 
  • start up the cache monitor

BOOL Deactivate ()
 
  • cache monitor close-down function - should be called on exit

void IgnoreEvents (INT32 nEvents)

Static Private Member Functions

static void OnCacheEvent ()
 
  • very simple cache event-handling function. It will only output a warning message and update the cache data

static unsigned __stdcall Monitor (LPVOID lpParam)
 
  • monitor thread function


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


Detailed Description

Definition at line 505 of file camnet.h.


Member Enumeration Documentation

enum DownloadCache::CacheMonitor::EVENTS
 

Enumerator:
EVENT_DEACTIVATE 
EVENT_CHANGE 

Definition at line 508 of file camnet.h.


Constructor & Destructor Documentation

DownloadCache::CacheMonitor::CacheMonitor  ) 
 

  • constructor

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/06/97
Parameters:
- [INPUTS]
Returns:
-

Definition at line 1794 of file camnet.cpp.

01795  {
01796      m_hMonitorThread = NULL;
01797      m_dwMonitorThreadID = 0;
01798      ::InitializeCriticalSection(&m_CacheDataCriticalSection);
01799  }

DownloadCache::CacheMonitor::~CacheMonitor  ) 
 

  • destructor

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/06/97
Parameters:
- [INPUTS]
Returns:
-

Definition at line 1812 of file camnet.cpp.

01813  {
01814      if (m_hMonitorThread && m_dwMonitorThreadID)
01815          Deactivate();
01816      ::DeleteCriticalSection(&m_CacheDataCriticalSection);
01817  }


Member Function Documentation

BOOL DownloadCache::CacheMonitor::Activate String_256 strCachePath  ) 
 

  • start up the cache monitor

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/06/97
Parameters:
- strCachePath - the cache path to be monitored [INPUTS]
Returns:
- TRUE if succesful, FALSE otherwise

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 }

BOOL DownloadCache::CacheMonitor::Deactivate  ) 
 

  • cache monitor close-down function - should be called on exit

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/06/97
Parameters:
- [INPUTS]
Returns:
- TRUE if succesful, FALSE otherwise

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 }

void DownloadCache::CacheMonitor::IgnoreEvents INT32  nEvents  )  [inline]
 

Definition at line 513 of file camnet.h.

00513 {m_nIgnoreCount += nEvents;}  

unsigned __stdcall DownloadCache::CacheMonitor::Monitor LPVOID  pParam  )  [static, private]
 

  • monitor thread function

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/06/97
Parameters:
- pParam - pointer to an array of event handles [INPUTS]
Returns:
- 0 if succesful, 0xFFFFFFFF otherwise

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 }

void DownloadCache::CacheMonitor::OnCacheEvent  )  [static, private]
 

  • very simple cache event-handling function. It will only output a warning message and update the cache data

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
17/06/97
Parameters:
- [INPUTS]
Returns:
-

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 }


Friends And Related Function Documentation

friend class DownloadCache [friend]
 

Definition at line 522 of file camnet.h.


Member Data Documentation

CRITICAL_SECTION DownloadCache::CacheMonitor::m_CacheDataCriticalSection [static, private]
 

Definition at line 516 of file camnet.h.

unsigned DownloadCache::CacheMonitor::m_dwMonitorThreadID [private]
 

Definition at line 519 of file camnet.h.

HANDLE DownloadCache::CacheMonitor::m_hMonitorThread [private]
 

Definition at line 518 of file camnet.h.

volatile INT32 DownloadCache::CacheMonitor::m_nIgnoreCount [static, private]
 

Definition at line 517 of file camnet.h.

HANDLE DownloadCache::CacheMonitor::rgEvents [static, private]
 

Definition at line 515 of file camnet.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:51 2007 for Camelot by  doxygen 1.4.4