Leaked source code of windows server 2003
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.

442 lines
14 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. : LoggingMethod(IAS_PROVIDER_MICROSOFT_ACCOUNTING, pParentNode)
  48. {
  49. // for help files
  50. m_helpIndex = (((CLoggingMethodsNode *)m_pParentNode)->m_ExtendRas)? RAS_HELP_INDEX:0;
  51. // Set the display name for this object
  52. TCHAR lpszName[IAS_MAX_STRING];
  53. int nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOCAL_FILE_LOGGING_NODE__NAME, lpszName, IAS_MAX_STRING );
  54. _ASSERT( nLoadStringResult > 0 );
  55. m_bstrDisplayName = lpszName;
  56. m_resultDataItem.nImage = IDBI_NODE_LOCAL_FILE_LOGGING;
  57. }
  58. //////////////////////////////////////////////////////////////////////////////
  59. /*++
  60. CLocalFileLoggingNode::~CLocalFileLoggingNode
  61. Destructor
  62. --*/
  63. //////////////////////////////////////////////////////////////////////////////
  64. CLocalFileLoggingNode::~CLocalFileLoggingNode() throw ()
  65. {
  66. ATLTRACE(_T("# --- CLocalFileLoggingNode::~CLocalFileLoggingNode\n"));
  67. }
  68. HRESULT CLocalFileLoggingNode::LoadCachedInfoFromSdo() throw ()
  69. {
  70. CComVariant spVariant;
  71. HRESULT hr = configSdo->GetProperty(
  72. PROPERTY_ACCOUNTING_LOG_FILE_DIRECTORY,
  73. &spVariant
  74. );
  75. if (SUCCEEDED(hr))
  76. {
  77. m_bstrDescription = V_BSTR(&spVariant);
  78. }
  79. return hr;
  80. }
  81. //////////////////////////////////////////////////////////////////////////////
  82. /*++
  83. CLocalFileLoggingNode::CreatePropertyPages
  84. See CSnapinNode::CreatePropertyPages (which this method overrides) for detailed info.
  85. --*/
  86. //////////////////////////////////////////////////////////////////////////////
  87. STDMETHODIMP CLocalFileLoggingNode::CreatePropertyPages (
  88. LPPROPERTYSHEETCALLBACK pPropertySheetCallback
  89. , LONG_PTR hNotificationHandle
  90. , IUnknown* pUnknown
  91. , DATA_OBJECT_TYPES type
  92. )
  93. {
  94. ATLTRACE(_T("# CLocalFileLoggingNode::CreatePropertyPages\n"));
  95. // Check for preconditions:
  96. _ASSERTE( pPropertySheetCallback != NULL );
  97. HRESULT hr;
  98. CLoggingMachineNode * pServerNode = GetServerRoot();
  99. _ASSERTE( pServerNode != NULL );
  100. hr = pServerNode->CheckConnectionToServer();
  101. if( FAILED( hr ) )
  102. {
  103. return hr;
  104. }
  105. TCHAR lpszTab1Name[IAS_MAX_STRING];
  106. TCHAR lpszTab2Name[IAS_MAX_STRING];
  107. int nLoadStringResult;
  108. // Load property page tab name from resource.
  109. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOCAL_FILE_LOGGING_PAGE1__TAB_NAME, lpszTab1Name, IAS_MAX_STRING );
  110. _ASSERT( nLoadStringResult > 0 );
  111. // This page will take care of deleting itself when it
  112. // receives the PSPCB_RELEASE message.
  113. // We specify TRUE for the bOwnsNotificationHandle parameter so that this page's destructor will be
  114. // responsible for freeing the notification handle. Only one page per sheet should do this.
  115. CLocalFileLoggingPage1 * pLocalFileLoggingPage1 = new CLocalFileLoggingPage1( hNotificationHandle, this, lpszTab1Name, TRUE );
  116. if( NULL == pLocalFileLoggingPage1 )
  117. {
  118. ATLTRACE(_T("# ***FAILED***: CLocalFileLoggingNode::CreatePropertyPages -- Couldn't create property pages\n"));
  119. return E_OUTOFMEMORY;
  120. }
  121. // Load property page tab name from resource.
  122. nLoadStringResult = LoadString( _Module.GetResourceInstance(), IDS_LOCAL_FILE_LOGGING_PAGE2__TAB_NAME, lpszTab2Name, IAS_MAX_STRING );
  123. _ASSERT( nLoadStringResult > 0 );
  124. // This page will take care of deleting itself when it
  125. // receives the PSPCB_RELEASE message.
  126. CLocalFileLoggingPage2 * pLocalFileLoggingPage2 = new CLocalFileLoggingPage2( hNotificationHandle, this, lpszTab2Name );
  127. if( NULL == pLocalFileLoggingPage2 )
  128. {
  129. ATLTRACE(_T("# ***FAILED***: CLocalFileLoggingNode::CreatePropertyPages -- Couldn't create property pages\n"));
  130. // Clean up the first page we created.
  131. delete pLocalFileLoggingPage1;
  132. return E_OUTOFMEMORY;
  133. }
  134. // Marshall the ISdo pointer so that the property page, which
  135. // runs in another thread, can unmarshall it and use it properly.
  136. hr = CoMarshalInterThreadInterfaceInStream(
  137. IID_ISdo //Reference to the identifier of the interface
  138. , configSdo //Pointer to the interface to be marshaled
  139. , &( pLocalFileLoggingPage1->m_pStreamSdoAccountingMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  140. );
  141. if( FAILED( hr ) )
  142. {
  143. delete pLocalFileLoggingPage1;
  144. delete pLocalFileLoggingPage2;
  145. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  146. return E_FAIL;
  147. }
  148. // Marshall the ISdo pointer so that the property page, which
  149. // runs in another thread, can unmarshall it and use it properly.
  150. hr = CoMarshalInterThreadInterfaceInStream(
  151. IID_ISdo //Reference to the identifier of the interface
  152. , configSdo //Pointer to the interface to be marshaled
  153. , &( pLocalFileLoggingPage2->m_pStreamSdoAccountingMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  154. );
  155. if( FAILED( hr ) )
  156. {
  157. delete pLocalFileLoggingPage1;
  158. delete pLocalFileLoggingPage2;
  159. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  160. return E_FAIL;
  161. }
  162. // Marshall the ISdo pointer so that the property page, which
  163. // runs in another thread, can unmarshall it and use it properly.
  164. hr = CoMarshalInterThreadInterfaceInStream(
  165. IID_ISdoServiceControl //Reference to the identifier of the interface
  166. , controlSdo //Pointer to the interface to be marshaled
  167. , &( pLocalFileLoggingPage1->m_pStreamSdoServiceControlMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  168. );
  169. if( FAILED( hr ) )
  170. {
  171. delete pLocalFileLoggingPage1;
  172. delete pLocalFileLoggingPage2;
  173. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  174. return E_FAIL;
  175. }
  176. // Marshall the ISdo pointer so that the property page, which
  177. // runs in another thread, can unmarshall it and use it properly.
  178. hr = CoMarshalInterThreadInterfaceInStream(
  179. IID_ISdoServiceControl //Reference to the identifier of the interface
  180. , controlSdo //Pointer to the interface to be marshaled
  181. , &( pLocalFileLoggingPage2->m_pStreamSdoServiceControlMarshal ) //Address of output variable that receives the IStream interface pointer for the marshaled interface
  182. );
  183. if( FAILED( hr ) )
  184. {
  185. delete pLocalFileLoggingPage1;
  186. delete pLocalFileLoggingPage2;
  187. ShowErrorDialog( NULL, IDS_ERROR__NO_SDO, NULL, hr, IDS_ERROR__LOGGING_TITLE, GetComponentData()->m_spConsole );
  188. return E_FAIL;
  189. }
  190. // Add the pages to the MMC property sheet.
  191. hr = pPropertySheetCallback->AddPage( pLocalFileLoggingPage1->Create() );
  192. _ASSERT( SUCCEEDED( hr ) );
  193. hr = pPropertySheetCallback->AddPage( pLocalFileLoggingPage2->Create() );
  194. _ASSERT( SUCCEEDED( hr ) );
  195. // Add a synchronization object which makes sure we only commit data
  196. // when all pages are OK with their data.
  197. CSynchronizer * pSynchronizer = new CSynchronizer();
  198. _ASSERTE( pSynchronizer != NULL );
  199. // Hand the sycnchronizer off to the pages.
  200. pLocalFileLoggingPage1->m_pSynchronizer = pSynchronizer;
  201. pSynchronizer->AddRef();
  202. pLocalFileLoggingPage2->m_pSynchronizer = pSynchronizer;
  203. pSynchronizer->AddRef();
  204. return hr;
  205. }
  206. //////////////////////////////////////////////////////////////////////////////
  207. /*++
  208. CLocalFileLoggingNode::QueryPagesFor
  209. See CSnapinNode::QueryPagesFor (which this method overrides) for detailed info.
  210. --*/
  211. //////////////////////////////////////////////////////////////////////////////
  212. STDMETHODIMP CLocalFileLoggingNode::QueryPagesFor ( DATA_OBJECT_TYPES type )
  213. {
  214. ATLTRACE(_T("# CLocalFileLoggingNode::QueryPagesFor\n"));
  215. // S_OK means we have pages to display
  216. return S_OK;
  217. }
  218. //////////////////////////////////////////////////////////////////////////////
  219. /*++
  220. CLocalFileLoggingNode::GetResultPaneColInfo
  221. See CSnapinNode::GetResultPaneColInfo (which this method overrides) for detailed info.
  222. --*/
  223. //////////////////////////////////////////////////////////////////////////////
  224. OLECHAR* CLocalFileLoggingNode::GetResultPaneColInfo(int nCol)
  225. {
  226. ATLTRACE(_T("# CLocalFileLoggingNode::GetResultPaneColInfo\n"));
  227. // Check for preconditions:
  228. // None.
  229. switch( nCol )
  230. {
  231. case 0:
  232. return m_bstrDisplayName;
  233. break;
  234. case 1:
  235. return m_bstrDescription;
  236. break;
  237. default:
  238. // ISSUE: error -- should we assert here?
  239. return NULL;
  240. break;
  241. }
  242. }
  243. //////////////////////////////////////////////////////////////////////////////
  244. /*++
  245. CLocalFileLoggingNode::SetVerbs
  246. See CSnapinNode::SetVerbs (which this method overrides) for detailed info.
  247. --*/
  248. //////////////////////////////////////////////////////////////////////////////
  249. HRESULT CLocalFileLoggingNode::SetVerbs( IConsoleVerb * pConsoleVerb )
  250. {
  251. ATLTRACE(_T("# CLocalFileLoggingNode::SetVerbs\n"));
  252. // Check for preconditions:
  253. _ASSERTE( pConsoleVerb != NULL );
  254. HRESULT hr = S_OK;
  255. // We want the user to be able to choose Properties on this node
  256. hr = pConsoleVerb->SetVerbState( MMC_VERB_PROPERTIES, ENABLED, TRUE );
  257. // We want Properties to be the default
  258. hr = pConsoleVerb->SetDefaultVerb( MMC_VERB_PROPERTIES );
  259. return hr;
  260. }
  261. //////////////////////////////////////////////////////////////////////////////
  262. /*++
  263. CLocalFileLoggingNode::GetComponentData
  264. This method returns our unique CComponentData object representing the scope
  265. pane of this snapin.
  266. It relies upon the fact that each node has a pointer to its parent,
  267. except for the root node, which instead has a member variable pointing
  268. to CComponentData.
  269. This would be a useful function to use if, for example, you need a reference
  270. to some IConsole but you weren't passed one. You can use GetComponentData
  271. and then use the IConsole pointer which is a member variable of our
  272. CComponentData object.
  273. --*/
  274. //////////////////////////////////////////////////////////////////////////////
  275. CLoggingComponentData * CLocalFileLoggingNode::GetComponentData( void )
  276. {
  277. ATLTRACE(_T("# CLocalFileLoggingNode::GetComponentData\n"));
  278. // Check for preconditions:
  279. _ASSERTE( m_pParentNode != NULL );
  280. return ((CLoggingMethodsNode *) m_pParentNode)->GetComponentData();
  281. }
  282. //////////////////////////////////////////////////////////////////////////////
  283. /*++
  284. CLocalFileLoggingNode::GetServerRoot
  285. This method returns the Server node under which this node can be found.
  286. It relies upon the fact that each node has a pointer to its parent,
  287. all the way up to the server node.
  288. This would be a useful function to use if, for example, you need a reference
  289. to some data specific to a server.
  290. --*/
  291. //////////////////////////////////////////////////////////////////////////////
  292. CLoggingMachineNode * CLocalFileLoggingNode::GetServerRoot( void )
  293. {
  294. ATLTRACE(_T("# CLocalFileLoggingNode::GetServerRoot\n"));
  295. // Check for preconditions:
  296. _ASSERTE( m_pParentNode != NULL );
  297. return ((CLoggingMethodsNode *) m_pParentNode)->GetServerRoot();
  298. }
  299. //////////////////////////////////////////////////////////////////////////////
  300. /*++
  301. CLocalFileLoggingNode::OnPropertyChange
  302. This is our own custom response to the MMCN_PROPERTY_CHANGE notification.
  303. MMC never actually sends this notification to our snapin with a specific lpDataObject,
  304. so it would never normally get routed to a particular node but we have arranged it
  305. so that our property pages can pass the appropriate CSnapInItem pointer as the param
  306. argument. In our CComponent::Notify override, we map the notification message to
  307. the appropriate node using the param argument.
  308. --*/
  309. //////////////////////////////////////////////////////////////////////////////
  310. HRESULT CLocalFileLoggingNode::OnPropertyChange(
  311. LPARAM arg
  312. , LPARAM param
  313. , IComponentData * pComponentData
  314. , IComponent * pComponent
  315. , DATA_OBJECT_TYPES type
  316. )
  317. {
  318. ATLTRACE(_T("# CLocalFileLoggingNode::OnPropertyChange\n"));
  319. // Check for preconditions:
  320. // None.
  321. return LoadCachedInfoFromSdo();
  322. }