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.

195 lines
5.1 KiB

  1. // DataElement.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "DataElement.h"
  6. #include "EventManager.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDataElement
  14. IMPLEMENT_SERIAL(CDataElement, CHMObject, 1)
  15. CDataElement::CDataElement(BOOL bSetStateToEnabledOnOK)
  16. {
  17. EnableAutomation();
  18. // To keep the application running as long as an OLE automation
  19. // object is active, the constructor calls AfxOleLockApp.
  20. AfxOleLockApp();
  21. m_pRuleListener = NULL;
  22. m_sTypeName = IDS_STRING_MOF_DATAELEMENT;
  23. m_iType = IDM_GENERIC_WMI_INSTANCE;
  24. m_nState = HMS_NODATA;
  25. m_bSetStateToEnabledOnOK = bSetStateToEnabledOnOK; // v-marfin 62585 : Indicates if this is a 'new' data collector
  26. }
  27. CDataElement::~CDataElement()
  28. {
  29. if( m_pRuleListener )
  30. {
  31. delete m_pRuleListener;
  32. m_pRuleListener = NULL;
  33. }
  34. // TODO: RemoveStatistics
  35. // TODO: Destroy all events
  36. // To terminate the application when all objects created with
  37. // with OLE automation, the destructor calls AfxOleUnlockApp.
  38. AfxOleUnlockApp();
  39. }
  40. //****************************************************
  41. // 62585 : SetStateToEnabledOnOK
  42. //
  43. // This sets the boolean to indicate that the collector this
  44. // class represents is being created for the first time via
  45. // the New _> Data Collector menu item. The property pages
  46. // need to know this info since the new data collector is
  47. // defined as Disabled to begin with, so the page sets it
  48. // to Enabled when the user selects the OK button.
  49. //****************************************************
  50. void CDataElement::SetStateToEnabledOnOK(BOOL bSetStateToEnabledOnOK)
  51. {
  52. m_bSetStateToEnabledOnOK = bSetStateToEnabledOnOK;
  53. }
  54. void CDataElement::UpdateStatus()
  55. {
  56. TRACEX(_T("CDataElement::UpdateStatus\n"));
  57. CEventContainer* pContainer = NULL;
  58. EvtGetEventManager()->GetEventContainer(GetSystemName(),GetGuid(),pContainer);
  59. if( ! pContainer )
  60. {
  61. ASSERT(FALSE);
  62. return;
  63. }
  64. SetState(CEvent::GetStatus(pContainer->m_iState));
  65. for( int i = 0; i < GetScopeItemCount(); i++ )
  66. {
  67. CScopePaneItem* pItem = GetScopeItem(i);
  68. if( pItem )
  69. {
  70. CStringArray saNames;
  71. CString sValue;
  72. // Name of Data Element
  73. saNames.Add(GetName());
  74. // Status
  75. CString sStatus;
  76. CEvent::GetStatus(pContainer->m_iState,sStatus);
  77. saNames.Add(sStatus);
  78. // Type
  79. saNames.Add(GetUITypeName());
  80. // Guid
  81. saNames.Add(GetGuid());
  82. // Normal
  83. sValue.Format(_T("%d"),pContainer->m_iNumberNormals);
  84. saNames.Add(sValue);
  85. // Warning
  86. sValue.Format(_T("%d"),pContainer->m_iNumberWarnings);
  87. saNames.Add(sValue);
  88. // Critical
  89. sValue.Format(_T("%d"),pContainer->m_iNumberCriticals);
  90. saNames.Add(sValue);
  91. // Unknown
  92. sValue.Format(_T("%d"),pContainer->m_iNumberUnknowns);
  93. saNames.Add(sValue);
  94. // Last Message
  95. CString sLastMessage = pContainer->GetLastEventDTime();
  96. if( sLastMessage.IsEmpty() )
  97. {
  98. sLastMessage.LoadString(IDS_STRING_NONE);
  99. }
  100. saNames.Add(sLastMessage);
  101. // Comment
  102. saNames.Add(GetComment());
  103. pItem->SetDisplayNames(saNames);
  104. pItem->SetIconIndex(CEvent::GetStatus(pContainer->m_iState));
  105. pItem->SetOpenIconIndex(CEvent::GetStatus(pContainer->m_iState));
  106. pItem->SetItem();
  107. }
  108. }
  109. m_lNormalCount = pContainer->m_iNumberNormals;
  110. m_lWarningCount = pContainer->m_iNumberWarnings;
  111. m_lCriticalCount = pContainer->m_iNumberCriticals;
  112. m_lUnknownCount = pContainer->m_iNumberUnknowns;
  113. }
  114. void CDataElement::OnFinalRelease()
  115. {
  116. // When the last reference for an automation object is released
  117. // OnFinalRelease is called. The base class will automatically
  118. // deletes the object. Add additional cleanup required for your
  119. // object before calling the base class.
  120. CHMObject::OnFinalRelease();
  121. }
  122. BEGIN_MESSAGE_MAP(CDataElement, CHMObject)
  123. //{{AFX_MSG_MAP(CDataElement)
  124. // NOTE - the ClassWizard will add and remove mapping macros here.
  125. //}}AFX_MSG_MAP
  126. END_MESSAGE_MAP()
  127. BEGIN_DISPATCH_MAP(CDataElement, CHMObject)
  128. //{{AFX_DISPATCH_MAP(CDataElement)
  129. // NOTE - the ClassWizard will add and remove mapping macros here.
  130. //}}AFX_DISPATCH_MAP
  131. END_DISPATCH_MAP()
  132. // Note: we add support for IID_IDataElement to support typesafe binding
  133. // from VBA. This IID must match the GUID that is attached to the
  134. // dispinterface in the .ODL file.
  135. // {D9BF4FA5-F673-11D2-BDC4-0000F87A3912}
  136. static const IID IID_IDataElement =
  137. { 0xd9bf4fa5, 0xf673, 0x11d2, { 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  138. BEGIN_INTERFACE_MAP(CDataElement, CHMObject)
  139. INTERFACE_PART(CDataElement, IID_IDataElement, Dispatch)
  140. END_INTERFACE_MAP()
  141. // {D9BF4FA6-F673-11D2-BDC4-0000F87A3912}
  142. IMPLEMENT_OLECREATE_EX(CDataElement, "SnapIn.DataElement", 0xd9bf4fa6, 0xf673, 0x11d2, 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12)
  143. BOOL CDataElement::CDataElementFactory::UpdateRegistry(BOOL bRegister)
  144. {
  145. if (bRegister)
  146. return AfxOleRegisterServerClass(m_clsid, m_lpszProgID, m_lpszProgID, m_lpszProgID, OAT_DISPATCH_OBJECT);
  147. else
  148. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CDataElement message handlers