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.

217 lines
5.4 KiB

  1. //
  2. // MODULE: TOPIC.CPP
  3. //
  4. // PURPOSE: Class CTopic brings together all of the data structures that represent a
  5. // troubleshooting topic. Most importantly, this represents the belief network,
  6. // but it also represents the HTI template, the data derived from the BES (back
  7. // end search) file, and any other persistent data.
  8. //
  9. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  10. //
  11. // AUTHOR: Joe Mabel
  12. //
  13. // ORIGINAL DATE: 9-9-98
  14. //
  15. // NOTES:
  16. // 1. The bulk of the methods on this class are inherited from CBeliefNetwork
  17. //
  18. // Version Date By Comments
  19. //--------------------------------------------------------------------
  20. // V3.0 09-09-98 JM
  21. //
  22. #pragma warning(disable:4786)
  23. #include "stdafx.h"
  24. #include "Topic.h"
  25. #include "propnames.h"
  26. #include "event.h"
  27. #include "CharConv.h"
  28. #include "SafeTime.h"
  29. #ifdef LOCAL_TROUBLESHOOTER
  30. #include "CHMFileReader.h"
  31. #include "apgtstscread.h"
  32. #endif
  33. #include "apgts.h" // Need for Local-Online macros.
  34. //////////////////////////////////////////////////////////////////////
  35. // Construction/Destruction
  36. //////////////////////////////////////////////////////////////////////
  37. CTopic::CTopic( LPCTSTR pathDSC
  38. ,LPCTSTR pathHTI
  39. ,LPCTSTR pathBES
  40. ,LPCTSTR pathTSC ) :
  41. CBeliefNetwork(pathDSC),
  42. m_pHTI(NULL),
  43. m_pBES(NULL),
  44. m_pathHTI(pathHTI),
  45. m_pathBES(pathBES),
  46. m_pathTSC(pathTSC),
  47. m_bTopicIsValid(true),
  48. m_bTopicIsRead(false)
  49. {
  50. }
  51. CTopic::~CTopic()
  52. {
  53. if (m_pHTI)
  54. delete m_pHTI;
  55. if (m_pBES)
  56. delete m_pBES;
  57. }
  58. bool CTopic::IsRead()
  59. {
  60. bool ret = false;
  61. LOCKOBJECT();
  62. ret = m_bTopicIsRead;
  63. UNLOCKOBJECT();
  64. return ret;
  65. }
  66. bool CTopic::Read()
  67. {
  68. LOCKOBJECT();
  69. m_bTopicIsValid = false;
  70. try
  71. {
  72. if (CBeliefNetwork::Read())
  73. {
  74. if (m_pHTI)
  75. delete m_pHTI;
  76. if (RUNNING_LOCAL_TS())
  77. m_pHTI = new CAPGTSHTIReader( CPhysicalFileReader::makeReader( m_pathHTI ), GetMultilineNetProp(H_NET_HTI_LOCAL, _T("%s\r\n")) );
  78. else
  79. m_pHTI = new CAPGTSHTIReader( new CNormalFileReader( m_pathHTI ), GetMultilineNetProp(H_NET_HTI_ONLINE, _T("%s\r\n")) );
  80. if (m_pHTI->Read())
  81. {
  82. #ifdef LOCAL_TROUBLESHOOTER
  83. // it can fail reading TCS file - we don't care
  84. CAPGTSTSCReader( CPhysicalFileReader::makeReader( m_pathTSC ), &m_Cache ).Read();
  85. #endif
  86. // at this point, we're OK, because BES is optional
  87. m_bTopicIsValid = true;
  88. if (m_pBES)
  89. {
  90. delete m_pBES;
  91. m_pBES= NULL;
  92. }
  93. CString strBESfromNet= GetMultilineNetProp( H_NET_BES, _T("%s\r\n") );
  94. if ((!m_pathBES.IsEmpty()) || (!strBESfromNet.IsEmpty()))
  95. {
  96. // Only allocate a BESReader for a valid filename.
  97. m_pBES = new CAPGTSBESReader(new CNormalFileReader(m_pathBES), strBESfromNet );
  98. m_pBES->Read();
  99. }
  100. }
  101. }
  102. }
  103. catch (bad_alloc&)
  104. {
  105. // Note memory failure in event log.
  106. CBuildSrcFileLinenoStr SrcLoc( __FILE__, __LINE__ );
  107. CEvent::ReportWFEvent( SrcLoc.GetSrcFileLineStr(),
  108. SrcLoc.GetSrcFileLineStr(),
  109. _T(""), _T(""), EV_GTS_CANT_ALLOC );
  110. }
  111. m_bTopicIsRead = true;
  112. UNLOCKOBJECT();
  113. return m_bTopicIsValid;
  114. }
  115. // should only be called in a context where we know we have a valid topic.
  116. // Needn't lock, because m_pBES won't change once topic is read.
  117. bool CTopic::HasBES()
  118. {
  119. return (m_pBES ? true : false);
  120. }
  121. // Should only be called in a context where we know we have a valid topic.
  122. // Does not need to lock, because:
  123. // - CAPGTSBESReader provides its own locking
  124. // - m_pBES won't change once topic is read.
  125. void CTopic::GenerateBES(
  126. const vector<CString> & arrstrIn,
  127. CString & strEncoded,
  128. CString & strRaw)
  129. {
  130. if (m_pBES)
  131. m_pBES->GenerateBES(arrstrIn, strEncoded, strRaw);
  132. }
  133. // Should only be called in a context where we know we have a valid topic.
  134. // Does not need to lock, because:
  135. // - CAPGTSHTIReader provides its own locking
  136. // - m_pHTI won't change once topic is read.
  137. void CTopic::CreatePage( const CHTMLFragments& fragments,
  138. CString& out,
  139. const map<CString,CString> & mapStrs,
  140. CString strHTTPcookies/*= _T("")*/ )
  141. {
  142. if (m_pHTI)
  143. {
  144. // You can compile with the SHOWPROGRESS option to get a report on the progress of this page.
  145. #ifdef SHOWPROGRESS
  146. time_t timeStart = 0;
  147. time_t timeEnd = 0;
  148. time(&timeStart);
  149. #endif // SHOWPROGRESS
  150. m_pHTI->CreatePage(fragments, out, mapStrs, strHTTPcookies );
  151. #ifdef SHOWPROGRESS
  152. time(&timeEnd);
  153. CString strProgress;
  154. CSafeTime safetimeStart(timeStart);
  155. CSafeTime safetimeEnd(timeEnd);
  156. strProgress = _T("\n<BR>-----------------------------");
  157. strProgress += _T("\n<BR>Start CTopic::CreatePage ");
  158. strProgress += safetimeStart.StrLocalTime();
  159. strProgress += _T("\n<BR>End CTopic::CreatePage ");
  160. strProgress += safetimeEnd.StrLocalTime();
  161. int i = out.Find(_T("<BODY"));
  162. i = out.Find(_T('>'), i); // end of BODY tag
  163. if (i>=0)
  164. {
  165. out = out.Left(i+1)
  166. + strProgress
  167. + out.Mid(i+1);
  168. }
  169. #endif // SHOWPROGRESS
  170. }
  171. }
  172. // JSM V3.2
  173. // Should only be called in a context where we know we have a valid topic.
  174. // Does not need to lock, because:
  175. // - CAPGTSHTIReader provides its own locking
  176. // - m_pHTI won't change once topic is read.
  177. void CTopic::ExtractNetProps(vector <CString> &arr_props)
  178. {
  179. if (m_pHTI)
  180. m_pHTI->ExtractNetProps(arr_props);
  181. }
  182. // Should only be called in a context where we know we have a valid topic.
  183. // Does not need to lock, because:
  184. // - CAPGTSHTIReader provides its own locking
  185. // - m_pHTI won't change once topic is read.
  186. bool CTopic::HasHistoryTable()
  187. {
  188. bool ret = false;
  189. if (m_pHTI)
  190. ret = m_pHTI->HasHistoryTable();
  191. return ret;
  192. }