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.

219 lines
5.3 KiB

  1. // System.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "System.h"
  6. #include "HMSystem.h"
  7. #include "SystemGroupScopeItem.h"
  8. #include "EventManager.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CSystem
  16. IMPLEMENT_SERIAL(CSystem, CHMObject, 1)
  17. CSystem::CSystem()
  18. {
  19. EnableAutomation();
  20. // To keep the application running as long as an OLE automation
  21. // object is active, the constructor calls AfxOleLockApp.
  22. AfxOleLockApp();
  23. m_pDGListener = NULL;
  24. m_pCreationListener = NULL;
  25. m_pDeletionListener = NULL;
  26. m_pSListener = NULL;
  27. m_sTypeName = IDS_STRING_MOF_SYSTEM;
  28. m_nState = HMS_NODATA;
  29. m_lTotalActiveSinkCount = 0;
  30. SetGuid(_T("@"));
  31. }
  32. CSystem::~CSystem()
  33. {
  34. if( m_pDGListener )
  35. {
  36. delete m_pDGListener;
  37. m_pDGListener = NULL;
  38. }
  39. if( m_pCreationListener )
  40. {
  41. delete m_pCreationListener;
  42. m_pCreationListener = NULL;
  43. }
  44. if( m_pDeletionListener )
  45. {
  46. delete m_pDeletionListener;
  47. m_pDeletionListener = NULL;
  48. }
  49. if( m_pSListener )
  50. {
  51. delete m_pSListener;
  52. m_pSListener = NULL;
  53. }
  54. EvtGetEventManager()->RemoveSystemContainer(GetSystemName());
  55. // To terminate the application when all objects created with
  56. // with OLE automation, the destructor calls AfxOleUnlockApp.
  57. AfxOleUnlockApp();
  58. }
  59. void CSystem::UpdateStatus()
  60. {
  61. TRACEX(_T("CSystem::UpdateStatus\n"));
  62. CEventContainer* pContainer = NULL;
  63. EvtGetEventManager()->GetEventContainer(GetSystemName(),GetGuid(),pContainer);
  64. if( ! pContainer )
  65. {
  66. return;
  67. }
  68. SetState(CEvent::GetStatus(pContainer->m_iState));
  69. for( int i = 0; i < GetScopeItemCount(); i++ )
  70. {
  71. CHMScopeItem* pItem = (CHMScopeItem*)GetScopeItem(i);
  72. if( pItem )
  73. {
  74. CStringArray saNames;
  75. CString sValue;
  76. // Name of system
  77. saNames.Add(GetSystemName());
  78. // Status
  79. CString sStatus;
  80. CEvent::GetStatus(pContainer->m_iState,sStatus);
  81. saNames.Add(sStatus);
  82. CString sDomain;
  83. CString sProcessor;
  84. CString sInfo;
  85. // GetComputerSystemInfo(sDomain,sProcessor); // v-marfin 62501
  86. if (!GetComputerSystemInfo(sDomain,sProcessor))
  87. {
  88. continue;
  89. }
  90. GetOperatingSystemInfo(sInfo);
  91. // Domain
  92. saNames.Add(sDomain);
  93. // OS
  94. saNames.Add(sInfo);
  95. GetWMIVersion(sInfo);
  96. // WMI Version
  97. saNames.Add(sInfo);
  98. // Normal
  99. sValue.Format(_T("%d"),pContainer->m_iNumberNormals);
  100. saNames.Add(sValue);
  101. // Warning
  102. sValue.Format(_T("%d"),pContainer->m_iNumberWarnings);
  103. saNames.Add(sValue);
  104. // Critical
  105. sValue.Format(_T("%d"),pContainer->m_iNumberCriticals);
  106. saNames.Add(sValue);
  107. // Unknown
  108. sValue.Format(_T("%d"),pContainer->m_iNumberUnknowns);
  109. saNames.Add(sValue);
  110. // Last Message
  111. CString sLastMessage = pContainer->GetLastEventDTime();
  112. if( sLastMessage.IsEmpty() )
  113. {
  114. sLastMessage.LoadString(IDS_STRING_NONE);
  115. }
  116. saNames.Add(sLastMessage);
  117. // Comment
  118. saNames.Add(GetComment());
  119. pItem->SetDisplayNames(saNames);
  120. pItem->SetIconIndex(CEvent::GetStatus(pContainer->m_iState));
  121. pItem->SetOpenIconIndex(CEvent::GetStatus(pContainer->m_iState));
  122. pItem->SetItem();
  123. CHMScopeItem* pParentItem = (CHMScopeItem*)pItem->GetParent();
  124. if( pParentItem )
  125. {
  126. pParentItem->OnChangeChildState(CEvent::GetStatus(pContainer->m_iState));
  127. }
  128. }
  129. }
  130. m_lNormalCount = pContainer->m_iNumberNormals;
  131. m_lWarningCount = pContainer->m_iNumberWarnings;
  132. m_lCriticalCount = pContainer->m_iNumberCriticals;
  133. m_lUnknownCount = pContainer->m_iNumberUnknowns;
  134. }
  135. void CSystem::OnFinalRelease()
  136. {
  137. // When the last reference for an automation object is released
  138. // OnFinalRelease is called. The base class will automatically
  139. // deletes the object. Add additional cleanup required for your
  140. // object before calling the base class.
  141. CHMObject::OnFinalRelease();
  142. }
  143. BEGIN_MESSAGE_MAP(CSystem, CHMObject)
  144. //{{AFX_MSG_MAP(CSystem)
  145. // NOTE - the ClassWizard will add and remove mapping macros here.
  146. //}}AFX_MSG_MAP
  147. END_MESSAGE_MAP()
  148. BEGIN_DISPATCH_MAP(CSystem, CHMObject)
  149. //{{AFX_DISPATCH_MAP(CSystem)
  150. // NOTE - the ClassWizard will add and remove mapping macros here.
  151. //}}AFX_DISPATCH_MAP
  152. END_DISPATCH_MAP()
  153. // Note: we add support for IID_ISystem to support typesafe binding
  154. // from VBA. This IID must match the GUID that is attached to the
  155. // dispinterface in the .ODL file.
  156. // {D9BF4FA0-F673-11D2-BDC4-0000F87A3912}
  157. static const IID IID_ISystem =
  158. { 0xd9bf4fa0, 0xf673, 0x11d2, { 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  159. BEGIN_INTERFACE_MAP(CSystem, CHMObject)
  160. INTERFACE_PART(CSystem, IID_ISystem, Dispatch)
  161. END_INTERFACE_MAP()
  162. // {84C4D41D-BB8F-11D2-BD78-0000F87A3912}
  163. IMPLEMENT_OLECREATE_EX(CSystem, "SnapIn.System", 0x84c4d41d, 0xbb8f, 0x11d2, 0xbd, 0x78, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12)
  164. BOOL CSystem::CSystemFactory::UpdateRegistry(BOOL bRegister)
  165. {
  166. if (bRegister)
  167. return AfxOleRegisterServerClass(m_clsid, m_lpszProgID, m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
  168. else
  169. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CSystem message handlers