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.

546 lines
17 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation, 1997 - 1999
  4. Module Name:
  5. LocalFileLoggingNode.cpp
  6. Abstract:
  7. Implementation file for the CClient class.
  8. Author:
  9. Michael A. Maguire 12/15/97
  10. Revision History:
  11. mmaguire 12/15/97 - created
  12. --*/
  13. //////////////////////////////////////////////////////////////////////
  14. //////////////////////////////////////////////////////////////////////////////
  15. // BEGIN INCLUDES
  16. //
  17. // standard includes:
  18. //
  19. #include "Precompiled.h"
  20. //
  21. // where we can find declaration for main class in this file:
  22. //
  23. #include "logcomp.h"
  24. #include "LocalFileLoggingNode.h"
  25. #include "LogCompD.h"
  26. #include "SnapinNode.cpp" // Template class implementation
  27. //
  28. //
  29. // where we can find declarations needed in this file:
  30. //
  31. #include "LoggingMethodsNode.h"
  32. #include "LocalFileLoggingPage1.h"
  33. #include "LocalFileLoggingPage2.h"
  34. #include "LogMacNd.h"
  35. // Need to include this at least once to get in build:
  36. #include "sdohelperfuncs.cpp"
  37. //
  38. // END INCLUDES
  39. //////////////////////////////////////////////////////////////////////////////
  40. //////////////////////////////////////////////////////////////////////////////
  41. /*++
  42. CLocalFileLoggingNode::CLocalFileLoggingNode
  43. Constructor
  44. --*/
  45. //////////////////////////////////////////////////////////////////////////////
  46. CLocalFileLoggingNode::CLocalFileLoggingNode( CSnapInItem * pParentNode )
  47. :CSnapinNode<CLocalFileLoggingNode, CLoggingComponentData, CLoggingComponent>(pParentNode)
  48. {
  49. ATLTRACE(_T("# +++ CLocalFileLoggingNode::CLocalFileLoggingNode\n"));
  50. // Check for preconditions:
  51. // None.
  52. // for help files
  53. m_helpIndex = (((CLoggingMethodsNode *)m_pParentNode)->m_ExtendRas)? RAS_HELP_INDEX:0;
  54. // Set the display name for this object
  55. TCHAR lpszName[IAS_MAX_STRING];
  56. int nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOCAL_FILE_LOGGING_NODE__NAME, lpszName, IAS_MAX_STRING );
  57. _ASSERT( nLoadStringResult > 0 );
  58. m_bstrDisplayName = lpszName;
  59. m_resultDataItem.nImage = IDBI_NODE_LOCAL_FILE_LOGGING;
  60. }
  61. //////////////////////////////////////////////////////////////////////////////
  62. /*++
  63. CLocalFileLoggingNode::InitSdoPointers
  64. Call as soon as you have constructed this class and pass in it's SDO pointer.
  65. --*/
  66. //////////////////////////////////////////////////////////////////////////////
  67. HRESULT CLocalFileLoggingNode::InitSdoPointers( ISdo *pSdoMachine )
  68. {
  69. ATLTRACE(_T("# CLocalFileLoggingNode::InitSdoPointers\n"));
  70. // Check for preconditions:
  71. _ASSERTE( pSdoMachine != NULL );
  72. HRESULT hr = S_OK;
  73. hr = pSdoMachine->QueryInterface( IID_ISdoServiceControl, (void **) &m_spSdoServiceControl );
  74. if( FAILED(hr) || ! m_spSdoServiceControl )
  75. {
  76. ShowErrorDialog( NULL, IDS_ERROR__CANT_READ_DATA_FROM_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  77. return 0;
  78. }
  79. // Get the SDO accounting object.
  80. hr = ::SDOGetSdoFromCollection( pSdoMachine
  81. , PROPERTY_IAS_REQUESTHANDLERS_COLLECTION
  82. , PROPERTY_COMPONENT_ID
  83. , IAS_PROVIDER_MICROSOFT_ACCOUNTING
  84. , &m_spSdoAccounting
  85. );
  86. if( m_spSdoAccounting == NULL )
  87. {
  88. ShowErrorDialog( NULL, IDS_ERROR__CANT_READ_DATA_FROM_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  89. return 0;
  90. }
  91. return hr;
  92. }
  93. // refresh date
  94. HRESULT CLocalFileLoggingNode::DataRefresh(ISdo* pSdoMachine)
  95. {
  96. // Check for preconditions:
  97. _ASSERTE( pSdoMachine != NULL );
  98. HRESULT hr = S_OK;
  99. m_spSdoServiceControl.Release();
  100. hr = pSdoMachine->QueryInterface( IID_ISdoServiceControl, (void **) &m_spSdoServiceControl );
  101. if( FAILED(hr) || ! m_spSdoServiceControl )
  102. {
  103. ShowErrorDialog( NULL, IDS_ERROR__CANT_READ_DATA_FROM_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  104. return 0;
  105. }
  106. // Get the SDO accounting object.
  107. m_spSdoAccounting.Release();
  108. hr = ::SDOGetSdoFromCollection( pSdoMachine
  109. , PROPERTY_IAS_REQUESTHANDLERS_COLLECTION
  110. , PROPERTY_COMPONENT_ID
  111. , IAS_PROVIDER_MICROSOFT_ACCOUNTING
  112. , &m_spSdoAccounting
  113. );
  114. if( m_spSdoAccounting == NULL )
  115. {
  116. ShowErrorDialog( NULL, IDS_ERROR__CANT_READ_DATA_FROM_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  117. return 0;
  118. }
  119. return hr;
  120. }
  121. //////////////////////////////////////////////////////////////////////////////
  122. /*++
  123. CLocalFileLoggingNode::LoadCachedInfoFromSdo
  124. For quick screen updates, we cache some information like client name,
  125. address, protocol and NAS type. Call this to load this information
  126. from the SDO's into the caches.
  127. --*/
  128. //////////////////////////////////////////////////////////////////////////////
  129. HRESULT CLocalFileLoggingNode::LoadCachedInfoFromSdo( void )
  130. {
  131. ATLTRACE(_T("# CLocalFileLoggingNode::LoadCachedInfoFromSdo\n"));
  132. // Check for preconditions:
  133. if( m_spSdoAccounting == NULL )
  134. {
  135. return E_FAIL;
  136. }
  137. HRESULT hr;
  138. CComVariant spVariant;
  139. // Load the log file directory.
  140. hr = m_spSdoAccounting->GetProperty( PROPERTY_ACCOUNTING_LOG_FILE_DIRECTORY, &spVariant );
  141. if( SUCCEEDED( hr ) )
  142. {
  143. _ASSERTE( spVariant.vt == VT_BSTR );
  144. m_bstrDescription = spVariant.bstrVal;
  145. }
  146. spVariant.Clear();
  147. return hr;
  148. }
  149. //////////////////////////////////////////////////////////////////////////////
  150. /*++
  151. CLocalFileLoggingNode::~CLocalFileLoggingNode
  152. Destructor
  153. --*/
  154. //////////////////////////////////////////////////////////////////////////////
  155. CLocalFileLoggingNode::~CLocalFileLoggingNode()
  156. {
  157. ATLTRACE(_T("# --- CLocalFileLoggingNode::~CLocalFileLoggingNode\n"));
  158. }
  159. //////////////////////////////////////////////////////////////////////////////
  160. /*++
  161. CLocalFileLoggingNode::CreatePropertyPages
  162. See CSnapinNode::CreatePropertyPages (which this method overrides) for detailed info.
  163. --*/
  164. //////////////////////////////////////////////////////////////////////////////
  165. STDMETHODIMP CLocalFileLoggingNode::CreatePropertyPages (
  166. LPPROPERTYSHEETCALLBACK pPropertySheetCallback
  167. , LONG_PTR hNotificationHandle
  168. , IUnknown* pUnknown
  169. , DATA_OBJECT_TYPES type
  170. )
  171. {
  172. ATLTRACE(_T("# CLocalFileLoggingNode::CreatePropertyPages\n"));
  173. // Check for preconditions:
  174. _ASSERTE( pPropertySheetCallback != NULL );
  175. HRESULT hr;
  176. CLoggingMachineNode * pServerNode = GetServerRoot();
  177. _ASSERTE( pServerNode != NULL );
  178. hr = pServerNode->CheckConnectionToServer();
  179. if( FAILED( hr ) )
  180. {
  181. return hr;
  182. }
  183. TCHAR lpszTab1Name[IAS_MAX_STRING];
  184. TCHAR lpszTab2Name[IAS_MAX_STRING];
  185. int nLoadStringResult;
  186. // Load property page tab name from resource.
  187. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOCAL_FILE_LOGGING_PAGE1__TAB_NAME, lpszTab1Name, IAS_MAX_STRING );
  188. _ASSERT( nLoadStringResult > 0 );
  189. // This page will take care of deleting itself when it
  190. // receives the PSPCB_RELEASE message.
  191. // We specify TRUE for the bOwnsNotificationHandle parameter so that this page's destructor will be
  192. // responsible for freeing the notification handle. Only one page per sheet should do this.
  193. CLocalFileLoggingPage1 * pLocalFileLoggingPage1 = new CLocalFileLoggingPage1( hNotificationHandle, this, lpszTab1Name, TRUE );
  194. if( NULL == pLocalFileLoggingPage1 )
  195. {
  196. ATLTRACE(_T("# ***FAILED***: CLocalFileLoggingNode::CreatePropertyPages -- Couldn't create property pages\n"));
  197. return E_OUTOFMEMORY;
  198. }
  199. // Load property page tab name from resource.
  200. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOCAL_FILE_LOGGING_PAGE2__TAB_NAME, lpszTab2Name, IAS_MAX_STRING );
  201. _ASSERT( nLoadStringResult > 0 );
  202. // This page will take care of deleting itself when it
  203. // receives the PSPCB_RELEASE message.
  204. CLocalFileLoggingPage2 * pLocalFileLoggingPage2 = new CLocalFileLoggingPage2( hNotificationHandle, this, lpszTab2Name );
  205. if( NULL == pLocalFileLoggingPage2 )
  206. {
  207. ATLTRACE(_T("# ***FAILED***: CLocalFileLoggingNode::CreatePropertyPages -- Couldn't create property pages\n"));
  208. // Clean up the first page we created.
  209. delete pLocalFileLoggingPage1;
  210. return E_OUTOFMEMORY;
  211. }
  212. // Marshall the ISdo pointer so that the property page, which
  213. // runs in another thread, can unmarshall it and use it properly.
  214. hr = CoMarshalInterThreadInterfaceInStream(
  215. IID_ISdo //Reference to the identifier of the interface
  216. , m_spSdoAccounting //Pointer to the interface to be marshaled
  217. , &( pLocalFileLoggingPage1->m_pStreamSdoAccountingMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  218. );
  219. if( FAILED( hr ) )
  220. {
  221. delete pLocalFileLoggingPage1;
  222. delete pLocalFileLoggingPage2;
  223. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  224. return E_FAIL;
  225. }
  226. // Marshall the ISdo pointer so that the property page, which
  227. // runs in another thread, can unmarshall it and use it properly.
  228. hr = CoMarshalInterThreadInterfaceInStream(
  229. IID_ISdo //Reference to the identifier of the interface
  230. , m_spSdoAccounting //Pointer to the interface to be marshaled
  231. , &( pLocalFileLoggingPage2->m_pStreamSdoAccountingMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  232. );
  233. if( FAILED( hr ) )
  234. {
  235. delete pLocalFileLoggingPage1;
  236. delete pLocalFileLoggingPage2;
  237. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  238. return E_FAIL;
  239. }
  240. // Marshall the ISdo pointer so that the property page, which
  241. // runs in another thread, can unmarshall it and use it properly.
  242. hr = CoMarshalInterThreadInterfaceInStream(
  243. IID_ISdoServiceControl //Reference to the identifier of the interface
  244. , m_spSdoServiceControl //Pointer to the interface to be marshaled
  245. , &( pLocalFileLoggingPage1->m_pStreamSdoServiceControlMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  246. );
  247. if( FAILED( hr ) )
  248. {
  249. delete pLocalFileLoggingPage1;
  250. delete pLocalFileLoggingPage2;
  251. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  252. return E_FAIL;
  253. }
  254. // Marshall the ISdo pointer so that the property page, which
  255. // runs in another thread, can unmarshall it and use it properly.
  256. hr = CoMarshalInterThreadInterfaceInStream(
  257. IID_ISdoServiceControl //Reference to the identifier of the interface
  258. , m_spSdoServiceControl //Pointer to the interface to be marshaled
  259. , &( pLocalFileLoggingPage2->m_pStreamSdoServiceControlMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  260. );
  261. if( FAILED( hr ) )
  262. {
  263. delete pLocalFileLoggingPage1;
  264. delete pLocalFileLoggingPage2;
  265. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  266. return E_FAIL;
  267. }
  268. // Add the pages to the MMC property sheet.
  269. hr = pPropertySheetCallback->AddPage( pLocalFileLoggingPage1->Create() );
  270. _ASSERT( SUCCEEDED( hr ) );
  271. hr = pPropertySheetCallback->AddPage( pLocalFileLoggingPage2->Create() );
  272. _ASSERT( SUCCEEDED( hr ) );
  273. // Add a synchronization object which makes sure we only commit data
  274. // when all pages are OK with their data.
  275. CSynchronizer * pSynchronizer = new CSynchronizer();
  276. _ASSERTE( pSynchronizer != NULL );
  277. // Hand the sycnchronizer off to the pages.
  278. pLocalFileLoggingPage1->m_pSynchronizer = pSynchronizer;
  279. pSynchronizer->AddRef();
  280. pLocalFileLoggingPage2->m_pSynchronizer = pSynchronizer;
  281. pSynchronizer->AddRef();
  282. return hr;
  283. }
  284. //////////////////////////////////////////////////////////////////////////////
  285. /*++
  286. CLocalFileLoggingNode::QueryPagesFor
  287. See CSnapinNode::QueryPagesFor (which this method overrides) for detailed info.
  288. --*/
  289. //////////////////////////////////////////////////////////////////////////////
  290. STDMETHODIMP CLocalFileLoggingNode::QueryPagesFor ( DATA_OBJECT_TYPES type )
  291. {
  292. ATLTRACE(_T("# CLocalFileLoggingNode::QueryPagesFor\n"));
  293. // S_OK means we have pages to display
  294. return S_OK;
  295. }
  296. //////////////////////////////////////////////////////////////////////////////
  297. /*++
  298. CLocalFileLoggingNode::GetResultPaneColInfo
  299. See CSnapinNode::GetResultPaneColInfo (which this method overrides) for detailed info.
  300. --*/
  301. //////////////////////////////////////////////////////////////////////////////
  302. OLECHAR* CLocalFileLoggingNode::GetResultPaneColInfo(int nCol)
  303. {
  304. ATLTRACE(_T("# CLocalFileLoggingNode::GetResultPaneColInfo\n"));
  305. // Check for preconditions:
  306. // None.
  307. switch( nCol )
  308. {
  309. case 0:
  310. return m_bstrDisplayName;
  311. break;
  312. case 1:
  313. return m_bstrDescription;
  314. break;
  315. default:
  316. // ISSUE: error -- should we assert here?
  317. return NULL;
  318. break;
  319. }
  320. }
  321. //////////////////////////////////////////////////////////////////////////////
  322. /*++
  323. CLocalFileLoggingNode::SetVerbs
  324. See CSnapinNode::SetVerbs (which this method overrides) for detailed info.
  325. --*/
  326. //////////////////////////////////////////////////////////////////////////////
  327. HRESULT CLocalFileLoggingNode::SetVerbs( IConsoleVerb * pConsoleVerb )
  328. {
  329. ATLTRACE(_T("# CLocalFileLoggingNode::SetVerbs\n"));
  330. // Check for preconditions:
  331. _ASSERTE( pConsoleVerb != NULL );
  332. HRESULT hr = S_OK;
  333. // We want the user to be able to choose Properties on this node
  334. hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  335. // We want Properties to be the default
  336. hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  337. return hr;
  338. }
  339. //////////////////////////////////////////////////////////////////////////////
  340. /*++
  341. CLocalFileLoggingNode::GetComponentData
  342. This method returns our unique CComponentData object representing the scope
  343. pane of this snapin.
  344. It relies upon the fact that each node has a pointer to its parent,
  345. except for the root node, which instead has a member variable pointing
  346. to CComponentData.
  347. This would be a useful function to use if, for example, you need a reference
  348. to some IConsole but you weren't passed one. You can use GetComponentData
  349. and then use the IConsole pointer which is a member variable of our
  350. CComponentData object.
  351. --*/
  352. //////////////////////////////////////////////////////////////////////////////
  353. CLoggingComponentData * CLocalFileLoggingNode::GetComponentData( void )
  354. {
  355. ATLTRACE(_T("# CLocalFileLoggingNode::GetComponentData\n"));
  356. // Check for preconditions:
  357. _ASSERTE( m_pParentNode != NULL );
  358. return ((CLoggingMethodsNode *) m_pParentNode)->GetComponentData();
  359. }
  360. //////////////////////////////////////////////////////////////////////////////
  361. /*++
  362. CLocalFileLoggingNode::GetServerRoot
  363. This method returns the Server node under which this node can be found.
  364. It relies upon the fact that each node has a pointer to its parent,
  365. all the way up to the server node.
  366. This would be a useful function to use if, for example, you need a reference
  367. to some data specific to a server.
  368. --*/
  369. //////////////////////////////////////////////////////////////////////////////
  370. CLoggingMachineNode * CLocalFileLoggingNode::GetServerRoot( void )
  371. {
  372. ATLTRACE(_T("# CLocalFileLoggingNode::GetServerRoot\n"));
  373. // Check for preconditions:
  374. _ASSERTE( m_pParentNode != NULL );
  375. return ((CLoggingMethodsNode *) m_pParentNode)->GetServerRoot();
  376. }
  377. //////////////////////////////////////////////////////////////////////////////
  378. /*++
  379. CLocalFileLoggingNode::OnPropertyChange
  380. This is our own custom response to the MMCN_PROPERTY_CHANGE notification.
  381. MMC never actually sends this notification to our snapin with a specific lpDataObject,
  382. so it would never normally get routed to a particular node but we have arranged it
  383. so that our property pages can pass the appropriate CSnapInItem pointer as the param
  384. argument. In our CComponent::Notify override, we map the notification message to
  385. the appropriate node using the param argument.
  386. --*/
  387. //////////////////////////////////////////////////////////////////////////////
  388. HRESULT CLocalFileLoggingNode::OnPropertyChange(
  389. LPARAM arg
  390. , LPARAM param
  391. , IComponentData * pComponentData
  392. , IComponent * pComponent
  393. , DATA_OBJECT_TYPES type
  394. )
  395. {
  396. ATLTRACE(_T("# CLocalFileLoggingNode::OnPropertyChange\n"));
  397. // Check for preconditions:
  398. // None.
  399. return LoadCachedInfoFromSdo();
  400. }