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.

515 lines
13 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. ilogging.cpp
  5. Abstract:
  6. Internal implementation for the logging subfolder.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Darwin Ouyang (t-darouy) 30-Sept-1997
  11. --*/
  12. #include "StdAfx.h"
  13. #include "inode.h" // base class
  14. #include "iroot.h" // iroot
  15. #include "ilogging.h" // logging folder
  16. #include "ilogcat.h" // log category item
  17. #include "faxsnapin.h" // snapin
  18. #include "faxdataobj.h" // dataobject
  19. #include "faxstrt.h" // string table
  20. #pragma hdrstop
  21. extern CStringTable * GlobalStringTable;
  22. // Generated with uuidgen. Each node must have a GUID associated with it.
  23. // This one is for the logging subfolder.
  24. const GUID GUID_LoggingNode = /* 03d8fbd8-3e9e-11d1-9075-00a0c90ab504 */
  25. {
  26. 0x03d8fbd8,
  27. 0x3e9e,
  28. 0x11d1,
  29. {0x90, 0x75, 0x00, 0xa0, 0xc9, 0x0a, 0xb5, 0x04}
  30. };
  31. ////////////////////////////////////////////////////////////////////////////////////////////////////
  32. ////////////////////////////////////////////////////////////////////////////////////////////////////
  33. ////////////////////////////////////////////////////////////////////////////////////////////////////
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////
  35. //
  36. //
  37. // Constructor and destructor
  38. //
  39. //
  40. CInternalLogging::CInternalLogging(
  41. CInternalNode * pParent,
  42. CFaxComponentData * pCompData )
  43. : CInternalNode( pParent, pCompData )
  44. /*++
  45. Routine Description:
  46. Constructor
  47. Arguments:
  48. pParent - pointer to parent node, in this case unused
  49. pCompData - pointer to IComponentData implementation for snapin global data
  50. Return Value:
  51. None.
  52. --*/
  53. {
  54. faxHandle = m_pCompData->m_FaxHandle;
  55. assert( faxHandle != NULL );
  56. }
  57. CInternalLogging::~CInternalLogging()
  58. /*++
  59. Routine Description:
  60. Destructor
  61. Arguments:
  62. None.
  63. Return Value:
  64. None.
  65. --*/
  66. {
  67. }
  68. ////////////////////////////////////////////////////////////////////////////////////////////////////
  69. ////////////////////////////////////////////////////////////////////////////////////////////////////
  70. ////////////////////////////////////////////////////////////////////////////////////////////////////
  71. ////////////////////////////////////////////////////////////////////////////////////////////////////
  72. //
  73. //
  74. // Mandatory CInternalNode implementations.
  75. //
  76. //
  77. const GUID *
  78. CInternalLogging::GetNodeGUID()
  79. /*++
  80. Routine Description:
  81. Returns the node's associated GUID.
  82. Arguments:
  83. None.
  84. Return Value:
  85. A const pointer to a binary GUID.
  86. --*/
  87. {
  88. // DebugPrint(( TEXT("Trace: CInternalLogging::GetNodeGUID") ));
  89. return &GUID_LoggingNode;
  90. }
  91. const LPTSTR
  92. CInternalLogging::GetNodeDisplayName()
  93. /*++
  94. Routine Description:
  95. Returns a const TSTR pointer to the node's display name.
  96. Arguments:
  97. None.
  98. Return Value:
  99. A const pointer to a TSTR.
  100. --*/
  101. {
  102. // DebugPrint(( TEXT("Trace: CInternalLogging::GetNodeDisplayName") ));
  103. return ::GlobalStringTable->GetString( IDS_LOGGINGNODENAME );
  104. }
  105. const LPTSTR
  106. CInternalLogging::GetNodeDescription()
  107. /*++
  108. Routine Description:
  109. Returns a const TSTR pointer to the node's display description.
  110. Arguments:
  111. None.
  112. Return Value:
  113. A const pointer to a TSTR.
  114. --*/
  115. {
  116. // DebugPrint(( TEXT("Trace: CInternalLogging::GetNodeDisplayName") ));
  117. return ::GlobalStringTable->GetString( IDS_LOGGING_FOLDER_DESC_ROOT );
  118. }
  119. const LONG_PTR
  120. CInternalLogging::GetCookie()
  121. /*++
  122. Routine Description:
  123. Returns the cookie for this node.
  124. Arguments:
  125. None.
  126. Return Value:
  127. A const long containing the cookie for the pointer,
  128. in this case, (long)this.
  129. --*/
  130. {
  131. // DebugPrint(( TEXT("Trace: CInternalLogging::GetCookie") ));
  132. DebugPrint(( TEXT("Logging Node Cookie: 0x%p"), this ));
  133. return (LONG_PTR)this; // status node's cookie is the node id.
  134. }
  135. ////////////////////////////////////////////////////////////////////////////////////////////////////
  136. ////////////////////////////////////////////////////////////////////////////////////////////////////
  137. ////////////////////////////////////////////////////////////////////////////////////////////////////
  138. ////////////////////////////////////////////////////////////////////////////////////////////////////
  139. //
  140. //
  141. // Internal Event Handlers
  142. //
  143. //
  144. HRESULT
  145. CInternalLogging::ResultOnShow(
  146. IN CFaxComponent* pComp,
  147. IN CFaxDataObject * lpDataObject,
  148. IN LPARAM arg,
  149. IN LPARAM param)
  150. /*++
  151. Routine Description:
  152. Event handler for the MMCN_SHOW message for the logging node.
  153. Arguments:
  154. pComp - a pointer to the instance of IComponentData which this root node is associated with.
  155. lpDataObject - a pointer to the data object containing context information for this node.
  156. pdo - a pointer to the data object associated with this node
  157. arg, param - the arguements of the message
  158. Return Value:
  159. HRESULT which indicates SUCCEEDED() or FAILED()
  160. --*/
  161. {
  162. DebugPrint(( TEXT("Trace: CInternalLogging::ResultOnShow") ));
  163. HRESULT hr = S_OK;
  164. unsigned int count;
  165. int iResult;
  166. BOOL bResult = FALSE;
  167. LPHEADERCTRL pIHeaderCtrl;
  168. if( m_pCompData->QueryRpcError() ) {
  169. return E_UNEXPECTED;
  170. }
  171. if( arg == TRUE ) { // need to display result pane
  172. do {
  173. // get resultdata pointer
  174. pIResultData = pComp->m_pResultData;
  175. assert( pIResultData );
  176. if( pIResultData == NULL ) {
  177. hr = E_UNEXPECTED;
  178. break;
  179. }
  180. // insert the icons into the image list
  181. hr = pComp->InsertIconsIntoImageList();
  182. assert( SUCCEEDED( hr ) );
  183. if( FAILED( hr ) ) {
  184. break;
  185. }
  186. // set headers
  187. pIHeaderCtrl = pComp->m_pHeaderCtrl;
  188. hr = pIHeaderCtrl->InsertColumn( 0,
  189. ::GlobalStringTable->GetString( IDS_LOG_CATEGORY ),
  190. LVCFMT_LEFT,
  191. MMCLV_AUTO );
  192. if( FAILED( hr ) ) {
  193. break;
  194. }
  195. hr = pIHeaderCtrl->InsertColumn( 1,
  196. ::GlobalStringTable->GetString( IDS_LOG_LEVEL ),
  197. LVCFMT_LEFT,
  198. MMCLV_AUTO );
  199. if( FAILED( hr ) ) {
  200. break;
  201. }
  202. // get fax info
  203. try {
  204. bResult = FaxGetLoggingCategories( faxHandle, &pComp->pCategories, &pComp->numCategories );
  205. } catch( ... ) {
  206. }
  207. if( !bResult ) {
  208. if (GetLastError() == ERROR_ACCESS_DENIED) {
  209. ::GlobalStringTable->SystemErrorMsg(ERROR_ACCESS_DENIED);
  210. } else {
  211. m_pCompData->NotifyRpcError( TRUE );
  212. hr = m_pCompData->m_pConsole->MessageBox(::GlobalStringTable->GetString( IDS_FAX_RETR_CAT_FAIL ),
  213. ::GlobalStringTable->GetString( IDS_ERR_TITLE ),
  214. MB_OK,
  215. &iResult);
  216. }
  217. hr = E_UNEXPECTED;
  218. break;
  219. }
  220. pComp->pLogPArray = new pCInternalLogCat[pComp->numCategories];
  221. assert(pComp->pLogPArray != NULL);
  222. if (!pComp->pLogPArray) {
  223. hr = E_OUTOFMEMORY;
  224. break;
  225. }
  226. ZeroMemory( (void*)pComp->pLogPArray, sizeof( pCInternalLogCat ) * pComp->numCategories);
  227. for( count = 0; count < pComp->numCategories; count++ ) {
  228. hr = InsertItem( &pComp->pLogPArray[count], &(pComp->pCategories[count]) );
  229. if( !SUCCEEDED( hr ) ) {
  230. break;
  231. }
  232. }
  233. } while( 0 );
  234. } else {
  235. // we're leaving the result pane
  236. // so we need to delete my result pane
  237. FaxFreeBuffer( (PVOID)pComp->pCategories );
  238. pComp->pCategories = NULL;
  239. for( count = 0; count < pComp->numCategories; count++ ) {
  240. if( pComp->pLogPArray ) {
  241. if (pComp->pLogPArray[count] != NULL ) {
  242. delete pComp->pLogPArray[count];
  243. pComp->pLogPArray[count] = NULL;
  244. }
  245. }
  246. }
  247. }
  248. return hr;
  249. }
  250. HRESULT
  251. CInternalLogging::ResultOnDelete(
  252. IN CFaxComponent* pComp,
  253. IN CFaxDataObject * lpDataObject,
  254. IN LPARAM arg, LPARAM param)
  255. /*++
  256. Routine Description:
  257. Event handler for the MMCN_DELETE message for the logging node.
  258. Arguments:
  259. pComp - a pointer to the instance of IComponentData which this root node is associated with.
  260. lpDataObject - a pointer to the data object containing context information for this node.
  261. pdo - a pointer to the data object associated with this node
  262. arg, param - the arguements of the message
  263. Return Value:
  264. HRESULT which indicates SUCCEEDED() or FAILED()
  265. --*/
  266. {
  267. unsigned int count;
  268. for( count = 0; count < pComp->numCategories; count++ ) {
  269. if( pComp->pLogPArray[count] != NULL ) {
  270. delete pComp->pLogPArray[count];
  271. pComp->pLogPArray[count] = NULL;
  272. }
  273. }
  274. delete pComp->pLogPArray;
  275. pComp->pLogPArray = NULL;
  276. return S_OK;
  277. }
  278. ////////////////////////////////////////////////////////////////////////////////////////////////////
  279. ////////////////////////////////////////////////////////////////////////////////////////////////////
  280. ////////////////////////////////////////////////////////////////////////////////////////////////////
  281. ////////////////////////////////////////////////////////////////////////////////////////////////////
  282. //
  283. //
  284. // Internal Functions
  285. //
  286. //
  287. HRESULT
  288. CInternalLogging::CommitChanges(
  289. CFaxComponent * pComp )
  290. /*++
  291. Routine Description:
  292. This function writes changes made in the subnodes out to the
  293. target fax service.
  294. Arguments:
  295. pComp - a pointer to the instance of IComponent associated with the event.
  296. Return Value:
  297. HRESULT which indicates SUCCEEDED() or FAILED()
  298. --*/
  299. {
  300. BOOL result = FALSE;
  301. if( m_pCompData->QueryRpcError() ) {
  302. return E_UNEXPECTED;
  303. }
  304. try {
  305. result = FaxSetLoggingCategories( faxHandle, pComp->pCategories, pComp->numCategories );
  306. } catch( ... ) {
  307. m_pCompData->NotifyRpcError( TRUE );
  308. }
  309. if( result == FALSE || m_pCompData->QueryRpcError() == TRUE ) {
  310. if (GetLastError() != ERROR_ACCESS_DENIED) {
  311. m_pCompData->NotifyRpcError( TRUE );
  312. assert(FALSE);
  313. }
  314. ::GlobalStringTable->SystemErrorMsg( GetLastError() );
  315. // clean up the result pane
  316. assert( pComp != NULL );
  317. pComp->m_pResultData->DeleteAllRsltItems();
  318. if(pComp->pLogPArray != NULL ) {
  319. for( DWORD count = 0; count < pComp->numCategories; count++ ) {
  320. if( pComp->pLogPArray[count] != NULL ) {
  321. delete pComp->pLogPArray[count];
  322. pComp->pLogPArray[count] = NULL;
  323. }
  324. }
  325. delete pComp->pLogPArray;
  326. pComp->pLogPArray = NULL;
  327. }
  328. assert( FALSE );
  329. return E_UNEXPECTED;
  330. }
  331. return S_OK;
  332. }
  333. ////////////////////////////////////////////////////////////////////////////////////////////////////
  334. ////////////////////////////////////////////////////////////////////////////////////////////////////
  335. ////////////////////////////////////////////////////////////////////////////////////////////////////
  336. ////////////////////////////////////////////////////////////////////////////////////////////////////
  337. //
  338. //
  339. // Utility Functions
  340. //
  341. //
  342. HRESULT
  343. CInternalLogging::InsertItem(
  344. IN CInternalLogCat ** pLogCat,
  345. IN PFAX_LOG_CATEGORY Category )
  346. /*++
  347. Routine Description:
  348. Wrapper that inserts an item into the result view pane given some information.
  349. Arguments:
  350. pLogCat - the instance of CInternalLogCat to insert
  351. Category - the information associated with that log category.
  352. Return Value:
  353. HRESULT which indicates SUCCEEDED() or FAILED()
  354. --*/
  355. {
  356. RESULTDATAITEM rdi;
  357. HRESULT hr = S_OK;
  358. if (!pLogCat) {
  359. return(E_POINTER);
  360. }
  361. *pLogCat = new CInternalLogCat( this, m_pCompData );
  362. assert(*pLogCat != NULL);
  363. if (!*pLogCat) {
  364. return(E_OUTOFMEMORY);
  365. }
  366. (*pLogCat)->SetLogCategory( Category );
  367. ZeroMemory( &rdi, sizeof( RESULTDATAITEM ) );
  368. rdi.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  369. rdi.nCol = 0;
  370. rdi.bScopeItem = FALSE;
  371. rdi.lParam = (*pLogCat)->GetCookie();
  372. rdi.nImage = (*pLogCat)->GetNodeDisplayImage();
  373. rdi.str = MMC_CALLBACK;
  374. hr = pIResultData->InsertItem( &rdi );
  375. assert( SUCCEEDED( hr ) );
  376. (*pLogCat)->SetItemID( rdi.itemID );
  377. return hr;
  378. }