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.

336 lines
6.1 KiB

  1. /*++
  2. Copyright (C) 1996-2000 Microsoft Corporation
  3. Module Name:
  4. logsrc.cpp
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #include "polyline.h"
  9. #include "unihelpr.h"
  10. #include "logsrc.h"
  11. // Construction/Destruction
  12. CLogFileItem::CLogFileItem (
  13. CSysmonControl *pCtrl )
  14. : m_cRef ( 0 ),
  15. m_pCtrl ( pCtrl ),
  16. m_pImpIDispatch ( NULL ),
  17. m_pNextItem ( NULL ),
  18. m_szPath ( NULL )
  19. /*++
  20. Routine Description:
  21. Constructor for the CLogFileItem class. It initializes the member variables.
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. return;
  29. }
  30. CLogFileItem::~CLogFileItem (
  31. VOID
  32. )
  33. /*++
  34. Routine Description:
  35. Destructor for the CLogFileItem class. It frees any objects, storage, and
  36. interfaces that were created. If the item is part of a query it is removed
  37. from the query.
  38. Arguments:
  39. None.
  40. Return Value:
  41. None.
  42. --*/
  43. {
  44. if ( NULL != m_szPath )
  45. delete m_szPath;
  46. if ( NULL != m_pImpIDispatch )
  47. delete m_pImpIDispatch;
  48. }
  49. HRESULT
  50. CLogFileItem::Initialize (
  51. LPCTSTR pszPath,
  52. CLogFileItem** pListHead )
  53. {
  54. HRESULT hr = E_POINTER;
  55. WCHAR* pszNewPath = NULL;
  56. USES_CONVERSION
  57. if ( NULL != pszPath ) {
  58. if ( _T('\0') != (TCHAR)(*pszPath) ) {
  59. pszNewPath = new WCHAR [lstrlen(pszPath) + 1];
  60. if ( NULL != pszNewPath ) {
  61. lstrcpyW ( pszNewPath, T2W(pszPath) );
  62. m_szPath = pszNewPath;
  63. hr = S_OK;
  64. } else {
  65. hr = E_OUTOFMEMORY;
  66. }
  67. } else {
  68. hr = E_INVALIDARG;
  69. }
  70. }
  71. if ( SUCCEEDED ( hr ) ) {
  72. m_pNextItem = *pListHead;
  73. *pListHead = this;
  74. }
  75. return hr;
  76. }
  77. HRESULT
  78. CLogFileItem::SaveToStream (
  79. IN LPSTREAM pIStream,
  80. IN BOOL, // fWildCard,
  81. IN INT iVersMaj,
  82. IN INT // iVersMin
  83. )
  84. /*++
  85. Routine Description:
  86. SaveToStream writes the log source's properties to the provided stream.
  87. Arguments:
  88. pIStream - Pointer to stream interface
  89. Return Value:
  90. HRESULT - S_OK or stream error
  91. --*/
  92. {
  93. HRESULT hr = NOERROR;
  94. // TodoLogFiles: Wildcard support
  95. if ( SMONCTRL_MAJ_VERSION == iVersMaj ) {
  96. LOGFILE_DATA ItemData;
  97. // Move properties to storage structure
  98. ItemData.m_nPathLength = lstrlen(m_szPath);
  99. assert ( 0 < ItemData.m_nPathLength );
  100. // Write structure to stream
  101. hr = pIStream->Write(&ItemData, sizeof(ItemData), NULL);
  102. if (FAILED(hr))
  103. return hr;
  104. // Write path name to stream
  105. hr = pIStream->Write(m_szPath, ItemData.m_nPathLength*sizeof(WCHAR), NULL);
  106. if (FAILED(hr))
  107. return hr;
  108. }
  109. return S_OK;
  110. }
  111. HRESULT
  112. CLogFileItem::NullItemToStream (
  113. IN LPSTREAM pIStream,
  114. IN INT,// iVersMaj,
  115. IN INT // iVersMin
  116. )
  117. /*++
  118. Routine Description:
  119. NulItemToStream writes a log file item structiure with a 0 path length
  120. to the stream. This is used to marked the end of the log file data in
  121. the control's saved state.
  122. Arguments:
  123. pIStream - Pointer to stream interface
  124. Return Value:
  125. HRESULT - S_OK or stream error
  126. --*/
  127. {
  128. LOGFILE_DATA ItemData;
  129. // Zero path length, other fields needn't be initialized
  130. ItemData.m_nPathLength = 0;
  131. // Write structure to stream
  132. return pIStream->Write(&ItemData, sizeof(ItemData), NULL);
  133. }
  134. HRESULT
  135. CLogFileItem::SaveToPropertyBag (
  136. IN IPropertyBag* pIPropBag,
  137. IN INT iIndex,
  138. IN INT, // iVersMaj,
  139. IN INT // iVersMin
  140. )
  141. /*++
  142. Routine Description:
  143. SaveToPropertyBag writes the log file item's properties to the provided
  144. property bag interface.
  145. Arguments:
  146. pIPropBag - Pointer to property bag interface
  147. fWildCard
  148. iVersMaj
  149. iVersMin
  150. Return Value:
  151. HRESULT - S_OK or property bag error
  152. --*/
  153. {
  154. HRESULT hr = S_OK;
  155. TCHAR szPropertyName[20];
  156. DWORD dwPropertyNameLength;
  157. LPTSTR pszNext;
  158. USES_CONVERSION
  159. // TodoLogFiles: Wildcard support
  160. // Write properties
  161. // Write path name
  162. _stprintf ( szPropertyName, _T("%s%05d."), _T("LogFile"), iIndex );
  163. dwPropertyNameLength = lstrlen (szPropertyName);
  164. pszNext = szPropertyName + dwPropertyNameLength;
  165. lstrcpy ( pszNext, _T("Path") );
  166. hr = StringToPropertyBag (
  167. pIPropBag,
  168. szPropertyName,
  169. m_szPath );
  170. return hr;
  171. }
  172. /*
  173. * CLogFileItem::QueryInterface
  174. * CLogFileItem::AddRef
  175. * CLogFileItem::Release
  176. */
  177. STDMETHODIMP CLogFileItem::QueryInterface(REFIID riid
  178. , LPVOID *ppv)
  179. {
  180. HRESULT hr = NOERROR;
  181. if ( NULL != ppv ) {
  182. *ppv = NULL;
  183. if (riid == IID_ILogFileItem || riid == IID_IUnknown) {
  184. *ppv = this;
  185. } else if (riid == DIID_DILogFileItem) {
  186. if (m_pImpIDispatch == NULL) {
  187. m_pImpIDispatch = new CImpIDispatch(this, this);
  188. if ( NULL != m_pImpIDispatch ) {
  189. m_pImpIDispatch->SetInterface(DIID_DILogFileItem, this);
  190. *ppv = m_pImpIDispatch;
  191. } else {
  192. hr = E_OUTOFMEMORY;
  193. }
  194. } else {
  195. *ppv = m_pImpIDispatch;
  196. }
  197. } else {
  198. hr = E_NOINTERFACE;
  199. }
  200. if ( SUCCEEDED ( hr ) ) {
  201. ((LPUNKNOWN)*ppv)->AddRef();
  202. }
  203. } else {
  204. hr = E_POINTER;
  205. }
  206. return hr;
  207. }
  208. STDMETHODIMP_(ULONG) CLogFileItem::AddRef(void)
  209. {
  210. return ++m_cRef;
  211. }
  212. STDMETHODIMP_(ULONG) CLogFileItem::Release(void)
  213. {
  214. if ( 0 == --m_cRef ) {
  215. delete this;
  216. return 0;
  217. }
  218. return m_cRef;
  219. }
  220. STDMETHODIMP CLogFileItem::get_Path (
  221. OUT BSTR* pstrPath
  222. )
  223. {
  224. HRESULT hr = E_POINTER;
  225. if ( NULL != pstrPath ) {
  226. *pstrPath = SysAllocString ( m_szPath );
  227. if ( NULL == *pstrPath ) {
  228. hr = E_OUTOFMEMORY;
  229. } else {
  230. hr = NOERROR;
  231. }
  232. }
  233. return hr;
  234. }
  235. CLogFileItem*
  236. CLogFileItem::Next (
  237. void )
  238. {
  239. return m_pNextItem;
  240. }
  241. void
  242. CLogFileItem::SetNext (
  243. CLogFileItem* pNext )
  244. {
  245. m_pNextItem = pNext;
  246. }
  247. LPCWSTR
  248. CLogFileItem::GetPath (
  249. void )
  250. {
  251. return m_szPath;
  252. }