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.

233 lines
9.2 KiB

  1. //
  2. // MODULE: TOPICSHOP.H
  3. //
  4. // PURPOSE: Provide a means of "publishing" troubleshooter topics. This is where a
  5. // working thread goes to obtain a CTopic to use
  6. //
  7. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  8. //
  9. // AUTHOR: Joe Mabel
  10. //
  11. // ORIGINAL DATE: 9-10-98
  12. //
  13. // NOTES:
  14. //
  15. // Version Date By Comments
  16. //--------------------------------------------------------------------
  17. // V3.0 09-10-98 JM
  18. //
  19. #if !defined(AFX_TOPICSHOP_H__0CEED643_48C2_11D2_95F3_00C04FC22ADD__INCLUDED_)
  20. #define AFX_TOPICSHOP_H__0CEED643_48C2_11D2_95F3_00C04FC22ADD__INCLUDED_
  21. #if _MSC_VER >= 1000
  22. #pragma once
  23. #endif // _MSC_VER >= 1000
  24. #include "apgtslstread.h"
  25. #include "apgtsHTIread.h"
  26. #include "Pointer.h"
  27. #include "Topic.h"
  28. #include "counter.h"
  29. #include <map>
  30. #pragma warning(disable:4786)
  31. #define LSTFILENAME _T("apgts.lst")
  32. typedef counting_ptr<CTopic> CP_TOPIC;
  33. class CTopicInCatalog
  34. {
  35. public:
  36. enum TopicStatus {eNotInited, eFail, eOK};
  37. private:
  38. CTopicInfo m_topicinfo; // symbolic name of topic, associated file names
  39. bool m_bTopicInfoMayNotBeCurrent; // set when we change topic info & haven't yet built.
  40. mutable CRITICAL_SECTION m_csTopicinfo; // must lock to access m_topicinfo or
  41. // m_bTopicInfoMayNotBeCurrent (outside the constructor)
  42. bool m_bInited; // true if we have attempted to build m_cpTopic.
  43. // Mainly, this is here so that if we have tried to build
  44. // the relevant CTopic and failed, we don't waste our time
  45. // trying to build it again. If this is true and
  46. // m_cpTopic.IsNull(), then we are unable to build this
  47. // troubleshooting topic.
  48. CP_TOPIC m_cpTopic; // smart (counting) pointer. If non-null, points to a
  49. // "published" topic, which is guaranteed to persist as
  50. // long as this points to it, or as long as a CP_TOPIC
  51. // copied from this pointer points to it.
  52. HANDLE m_hev; // event to trigger when this topic is (successfully or
  53. // unsuccessfully) loaded.
  54. CHourlyDailyCounter m_countLoad; // track attempted loads of this topic
  55. CHourlyDailyCounter m_countLoadOK; // track successful loads of this topic
  56. CHourlyDailyCounter m_countEvent; // track: initial placement in catalog, file change,
  57. // or operator request for change. More interesting for
  58. // first & last times than total number.
  59. CHourlyDailyCounter m_countHit; // track user requests for this topic...
  60. // ... and break them down to hits which are the first on a new cookie
  61. // & those which are not
  62. CHourlyDailyCounter m_countHitNewCookie;
  63. CHourlyDailyCounter m_countHitOldCookie;
  64. public:
  65. CTopicInCatalog(const CTopicInfo & topicinfo);
  66. ~CTopicInCatalog();
  67. CTopicInfo GetTopicInfo() const;
  68. void SetTopicInfo(const CTopicInfo &topicinfo);
  69. void CountHit(bool bNewCookie);
  70. CP_TOPIC & GetTopicNoWait(CP_TOPIC& cpTopic) const;
  71. CP_TOPIC & GetTopic(CP_TOPIC& cpTopic) const;
  72. void Init(const CTopic* pTopic);
  73. void CountChange();
  74. TopicStatus GetTopicStatus() const;
  75. bool GetTopicInfoMayNotBeCurrent() const;
  76. void TopicInfoIsCurrent();
  77. }; // EOF of class CTopicInCatalog.
  78. // This class was created utilizing CTopicInCatalog as a model. We might in the
  79. // future revisit these two classes and abstract the common functionality into a
  80. // base class. RAB-981030.
  81. typedef counting_ptr<CAPGTSHTIReader> CP_TEMPLATE;
  82. class CTemplateInCatalog
  83. {
  84. public:
  85. enum TemplateStatus {eNotInited, eFail, eOK};
  86. private:
  87. CString m_strTemplate; // name to the template
  88. bool m_bInited; // true if we have attempted to build m_cpTemplate.
  89. // Mainly, this is here so that if we have tried to build
  90. // the relevant CAPGTSHTIReader and failed, we don't waste our
  91. // time trying to build it again. If this is true and
  92. // m_cpTemplate.IsNull(), then we are unable to build this
  93. // troubleshooting template.
  94. CP_TEMPLATE m_cpTemplate; // smart (counting) pointer. If non-null, points to a
  95. // "published" template, which is guaranteed to persist as
  96. // long as this points to it, or as long as a CP_TEMPLATE
  97. // copied from this pointer points to it.
  98. HANDLE m_hev; // event to trigger when this template is (successfully or
  99. // unsuccessfully) loaded.
  100. CHourlyDailyCounter m_countLoad; // track attempted loads of this template
  101. CHourlyDailyCounter m_countLoadOK; // track successful loads of this template
  102. CHourlyDailyCounter m_countEvent; // track: initial placement in catalog, file change,
  103. // or operator request for change. More interesting for
  104. // first & last times than total number.
  105. CHourlyDailyCounter m_countHit; // track user requests for this template...
  106. public:
  107. CTemplateInCatalog( const CString & strTemplate );
  108. ~CTemplateInCatalog();
  109. const CString & GetTemplateInfo() const;
  110. void CountHit( bool bNewCookie );
  111. CP_TEMPLATE & GetTemplateNoWait( CP_TEMPLATE& cpTemplate ) const;
  112. CP_TEMPLATE & GetTemplate( CP_TEMPLATE& cpTemplate ) const;
  113. void Init( const CAPGTSHTIReader* pTemplate );
  114. void CountChange();
  115. void CountFailed();
  116. TemplateStatus GetTemplateStatus() const;
  117. DWORD CountOfFailedLoads() const;
  118. }; // EOF of class CTemplateInCatalog.
  119. // The only functions which need to lock class CTopicShop itself are those which modify TopicCatalog.
  120. // TopicBuildQueue has its own protection.
  121. class CTopicShop : public CStateless
  122. {
  123. public:
  124. // although this status pertains to CTopicBuildQueue, it must be declared public at
  125. // this level, so that we can pass thread status up out of CTopicShop.
  126. enum ThreadStatus{eBeforeInit, eFail, eWait, eRun, eExiting};
  127. static CString ThreadStatusText(ThreadStatus ts);
  128. private:
  129. typedef map<CString, CTopicInCatalog*> CTopicCatalog;
  130. typedef map<CString, CTemplateInCatalog*> CTemplateCatalog;
  131. // Queue of topics to build
  132. class CTopicBuildQueue : public CStateless
  133. {
  134. protected:
  135. enum CatalogCategory {eUnknown, eTopic, eTemplate};
  136. private:
  137. CTopicCatalog & m_TopicCatalog;
  138. CTemplateCatalog & m_TemplateCatalog;
  139. CString m_CurrentlyBuilding; // topic currently being built. Strictly lowercase.
  140. // it is assumed/enforced that only one topic at
  141. // a time will be built.
  142. CatalogCategory m_eCurrentlyBuilding;// Category type currently being built.
  143. // All strings in the next 4 vectors are strictly lowercase.
  144. vector<CString>m_PriorityBuild; // build these first. Someone's waiting for them.
  145. vector<CString>m_NonPriorityBuild;
  146. vector<CString>m_PriorityBuildTemplates;
  147. vector<CString>m_NonPriorityBuildTemplates;
  148. HANDLE m_hThread;
  149. HANDLE m_hevBuildRequested; // event to wake up TopicBuilderTask.
  150. HANDLE m_hevThreadIsShut; // event just to indicate exit of TopicBuilderTask thread
  151. bool m_bShuttingDown; // lets topic builder thread know we're shutting down
  152. DWORD m_dwErr; // status from starting the thread
  153. ThreadStatus m_ThreadStatus;
  154. time_t m_time; // time last changed ThreadStatus. Initialized
  155. public:
  156. CTopicBuildQueue( CTopicCatalog & TopicCatalog, CTemplateCatalog & TemplateCatalog );
  157. ~CTopicBuildQueue();
  158. void RequestBuild(const CString &strTopic, bool bPriority, CatalogCategory eCat );
  159. DWORD GetStatus(ThreadStatus &ts, DWORD & seconds) const;
  160. void GetTopicsStatus(DWORD &Total, DWORD &NoInit, DWORD &Fail, vector<CString>*parrstrFail) const;
  161. void GetTemplatesStatus( vector<CString>*parrstrFail, vector<DWORD>*parrcntFail ) const;
  162. // Used to shutdown the topic building thread.
  163. void ShutDown();
  164. private:
  165. CTopicBuildQueue(); // do not instantiate
  166. void SetThreadStatus(ThreadStatus ts);
  167. // functions for use by the TopicBuilderTask thread.
  168. void Build();
  169. bool GetNextToBuild( CString &strTopic, CatalogCategory &eCat );
  170. void BuildComplete();
  171. void AckShutDown();
  172. // main function of the TopicBuilderTask thread.
  173. static UINT WINAPI TopicBuilderTask(LPVOID lpParams);
  174. }; // EOF of class CTopicBuildQueue.
  175. /* class CTopicShop */
  176. private:
  177. CTopicCatalog m_TopicCatalog;
  178. CTemplateCatalog m_TemplateCatalog;
  179. CTopicBuildQueue m_TopicBuildQueue;
  180. HANDLE m_hevShopIsOpen; // so that threads wait till we know our list of topics
  181. public:
  182. CTopicShop();
  183. virtual ~CTopicShop();
  184. void AddTopic(const CTopicInfo & topicinfo);
  185. void AddTemplate( const CString & strTemplateName );
  186. void OpenShop();
  187. void BuildTopic(const CString & strTopic, bool *pbAlreadyInCatalog = NULL);
  188. void BuildTemplate(const CString & strTemplate);
  189. CP_TOPIC & GetTopic(const CString & strTopic, CP_TOPIC & cpTopic, bool bNewCookie);
  190. CP_TEMPLATE & GetTemplate( const CString & strTemplate, CP_TEMPLATE & cpTemplate, bool bNewCookie);
  191. void GetListOfTopicNames(vector<CString>&arrstrTopic) const;
  192. void RebuildAll();
  193. DWORD GetThreadStatus(ThreadStatus &ts, DWORD & seconds) const;
  194. void GetTopicsStatus(DWORD &Total, DWORD &NoInit, DWORD &Fail, vector<CString>*parrstrFail) const;
  195. void GetTemplatesStatus( vector<CString>*parrstrFail, vector<DWORD>*parrcntFail ) const;
  196. CTopicInCatalog* GetCatalogEntry(const CString& strTopic) const;
  197. bool RetTemplateInCatalogStatus( const CString& strTemplate, bool& bValid ) const;
  198. private:
  199. CTopicInCatalog * GetCatalogEntryPtr(const CString & strTopic) const;
  200. CTemplateInCatalog * GetTemplateCatalogEntryPtr(const CString & strTemplate) const;
  201. }; // EOF of class CTopicShop.
  202. #endif // !defined(AFX_TOPICSHOP_H__0CEED643_48C2_11D2_95F3_00C04FC22ADD__INCLUDED_)