Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.3 KiB

  1. //
  2. // MODULE: DirMonitor.h
  3. //
  4. // PURPOSE: Monitor changes to LST, DSC, HTI, BES files.
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Joe Mabel
  9. //
  10. // ORIGINAL DATE: 9-17-98
  11. //
  12. // NOTES:
  13. // 1. It would be equally appropriate for CDirectoryMonitor to inherit from CTopicShop
  14. // instead of having a member of type CDirectoryMonitor. Really an arbitrary choice.
  15. //
  16. // Version Date By Comments
  17. //--------------------------------------------------------------------
  18. // V3.0 09-17-98 JM
  19. //
  20. #if !defined(AFX_DIRMONITOR_H__493CF34D_4E79_11D2_95F8_00C04FC22ADD__INCLUDED_)
  21. #define AFX_DIRMONITOR_H__493CF34D_4E79_11D2_95F8_00C04FC22ADD__INCLUDED_
  22. #if _MSC_VER >= 1000
  23. #pragma once
  24. #endif // _MSC_VER >= 1000
  25. #include "TopicShop.h"
  26. #include "FileTracker.h"
  27. class CTopicFileTracker: public CFileTracker
  28. {
  29. private:
  30. CTopicInfo m_topicinfo;
  31. public:
  32. CTopicFileTracker();
  33. ~CTopicFileTracker();
  34. void AddTopicInfo(const CTopicInfo & topicinfo);
  35. const CTopicInfo & GetTopicInfo() const;
  36. };
  37. class CTemplateFileTracker: public CFileTracker
  38. {
  39. private:
  40. CString m_strTemplateName;
  41. public:
  42. CTemplateFileTracker();
  43. ~CTemplateFileTracker();
  44. void AddTemplateName( const CString & strTemplateName );
  45. const CString& GetTemplateName() const;
  46. };
  47. const CString k_strErrorTemplateFileName = _T("ErrorTemplate.hti");
  48. const CString k_strDefaultErrorTemplateBefore =
  49. _T("<HTML><HEAD><TITLE>AP GTS Error</TITLE></HEAD>")
  50. _T("<BODY BGCOLOR=#FFFFFF><H1>AP GTS reports an Error</H1>");
  51. const CString k_strErrorTemplateKey = _T("$Error");
  52. const CString k_strDefaultErrorTemplateAfter = _T("</BODY></HTML>");
  53. class CDirectoryMonitor : public CStateless
  54. {
  55. public:
  56. enum ThreadStatus{eBeforeInit, eFail, eWaitDirPath, eWaitChange, eWaitSettle,
  57. eRun, eBeforeWaitChange, eExiting};
  58. static CString ThreadStatusText(ThreadStatus ts);
  59. private:
  60. CTopicShop & m_TopicShop;
  61. CSimpleTemplate * m_pErrorTemplate; // template for reporting error messages (regardless
  62. // of topic)
  63. CString m_strDirPath; // Directory to monitor
  64. bool m_bDirPathChanged;
  65. CString m_strLstPath; // LST file (always in directory m_strDirPath)
  66. CString m_strErrorTemplatePath; // Error template file (always in directory m_strDirPath)
  67. CFileTracker * m_pTrackLst;
  68. CFileTracker * m_pTrackErrorTemplate;
  69. vector<CTopicFileTracker> m_arrTrackTopic;
  70. vector<CTemplateFileTracker> m_arrTrackTemplate;
  71. CAPGTSLSTReader * m_pLst; // current LST file contents
  72. HANDLE m_hThread;
  73. HANDLE m_hevMonitorRequested; // event to wake up DirectoryMonitorTask
  74. // this allows it to be wakened other than
  75. // by the directory change event. Currently used
  76. // for shutdown or change of directory.
  77. HANDLE m_hevThreadIsShut; // event just to indicate exit of DirectoryMonitorTask thread
  78. bool m_bShuttingDown; // lets topic directory monitor thread know we're shutting down
  79. DWORD m_secsReloadDelay; // number of second to let directory "settle down"
  80. // before we start to update topics.
  81. DWORD m_dwErr; // status from starting the thread
  82. ThreadStatus m_ThreadStatus;
  83. time_t m_time; // time last changed ThreadStatus. Initialized
  84. // to zero ==> unknown
  85. CString m_strTopicName; // This string is ignored in the Online Troubleshooter.
  86. // Done under the guise of binary compatibility.
  87. public:
  88. CDirectoryMonitor(CTopicShop & TopicShop, const CString& strTopicName ); // strTopicName is ignored in the Online Troubleshooter.
  89. // Done under the guise of binary compatibility.
  90. ~CDirectoryMonitor();
  91. void SetReloadDelay(DWORD secsReloadDelay);
  92. void SetResourceDirectory(const CString & strDirPath);
  93. void CreateErrorPage(const CString & strError, CString& out) const;
  94. DWORD GetStatus(ThreadStatus &ts, DWORD & seconds) const;
  95. void AddTemplateToTrack( const CString& strTemplateName );
  96. private:
  97. CDirectoryMonitor(); // do not instantiate
  98. void SetThreadStatus(ThreadStatus ts);
  99. // just for use by own destructor
  100. void ShutDown();
  101. // functions for use by the DirectoryMonitorTask thread.
  102. void Monitor();
  103. void LstFileDrivesTopics();
  104. void ReadErrorTemplate();
  105. void AckShutDown();
  106. // main function of the DirectoryMonitorTask thread.
  107. static UINT WINAPI DirectoryMonitorTask(LPVOID lpParams);
  108. };
  109. #endif // !defined(AFX_DIRMONITOR_H__493CF34D_4E79_11D2_95F8_00C04FC22ADD__INCLUDED_)