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.

286 lines
6.4 KiB

  1. // HMObject.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "HMObject.h"
  6. #include "EventManager.h"
  7. #include "System.h"
  8. #include "ActionPolicy.h" // 59492b
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. // static members for refreshing the events
  15. int CHMObject::m_iRefreshType = 0;
  16. int CHMObject::m_iEventCount = 50;
  17. int CHMObject::m_iTimeValue = 1;
  18. TimeUnit CHMObject::m_Units = Hours;
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CHMObject
  21. IMPLEMENT_SERIAL(CHMObject, CCmdTarget, 1)
  22. CHMObject::CHMObject()
  23. {
  24. EnableAutomation();
  25. m_nState = HMS_NODATA;
  26. m_lNameSuffix = 0L;
  27. SYSTEMTIME st;
  28. GetSystemTime(&st);
  29. // adjust to the local time zone
  30. TIME_ZONE_INFORMATION tzi;
  31. SYSTEMTIME stLocal;
  32. GetTimeZoneInformation(&tzi);
  33. SystemTimeToTzSpecificLocalTime(&tzi,&st,&stLocal);
  34. m_CreateDateTime = stLocal;
  35. m_ModifiedDateTime = stLocal;
  36. m_lActiveSinkCount = 0L;
  37. m_lNormalCount = 0;
  38. m_lUnknownCount = 0;
  39. m_lWarningCount = 0;
  40. m_lCriticalCount = 0;
  41. }
  42. CHMObject::~CHMObject()
  43. {
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Event Members
  47. /////////////////////////////////////////////////////////////////////////////
  48. void CHMObject::AddContainer(const CString& sParentGuid, const CString& sGuid, CHMObject* pObject)
  49. {
  50. if( sGuid == _T("@") )
  51. {
  52. EvtGetEventManager()->AddSystemContainer(sParentGuid,pObject->GetSystemName(),pObject);
  53. }
  54. else
  55. {
  56. if( pObject->IsKindOf(RUNTIME_CLASS(CDataElement)) )
  57. {
  58. EvtGetEventManager()->AddContainer(GetSystemName(),sParentGuid,sGuid,pObject,RUNTIME_CLASS(CDataPointEventContainer));
  59. }
  60. else
  61. {
  62. EvtGetEventManager()->AddContainer(GetSystemName(),sParentGuid,sGuid,pObject);
  63. }
  64. }
  65. }
  66. void CHMObject::ClearEvents()
  67. {
  68. for( int i = 0; i < GetChildCount(); i++ )
  69. {
  70. CHMObject* pChild = GetChild(i);
  71. if( pChild )
  72. {
  73. pChild->ClearEvents();
  74. }
  75. }
  76. if( GetChildCount() == 0 )
  77. {
  78. CEventContainer* pContainer = NULL;
  79. EvtGetEventManager()->GetEventContainer(GetSystemName(),GetGuid(),pContainer);
  80. if( ! pContainer )
  81. {
  82. ASSERT(FALSE);
  83. return;
  84. }
  85. // delete each event by status guid
  86. CStringArray saStatusGuidsToDelete;
  87. for( i = 0; i < pContainer->GetEventCount(); i++ )
  88. {
  89. CEvent* pEvent = pContainer->GetEvent(i);
  90. saStatusGuidsToDelete.Add(pEvent->m_sStatusGuid);
  91. }
  92. for( i = 0; i < saStatusGuidsToDelete.GetSize(); i++ )
  93. {
  94. EvtGetEventManager()->DeleteEvents(GetSystemName(),saStatusGuidsToDelete[i]);
  95. }
  96. }
  97. }
  98. void CHMObject::DestroyChild(int iIndex, bool bDeleteClassObject /*= false*/)
  99. {
  100. TRACEX(_T("CHMObject::DestroyChild\n"));
  101. TRACEARGn(iIndex);
  102. TRACEARGn(bDeleteClassObject);
  103. CHMObject* pObject = m_Children[iIndex];
  104. if( ! GfxCheckObjPtr(pObject,CHMObject) )
  105. {
  106. return;
  107. }
  108. // destroy the events for the child
  109. CEventContainer* pContainer = NULL;
  110. EvtGetEventManager()->GetEventContainer(pObject->GetSystemName(),pObject->GetGuid(),pContainer);
  111. if( pContainer )
  112. {
  113. pContainer->SetObjectPtr(NULL);
  114. }
  115. m_Children.RemoveAt(iIndex);
  116. if( bDeleteClassObject )
  117. {
  118. pObject->DeleteClassObject();
  119. }
  120. for( int i = pObject->GetScopeItemCount()-1; i >= 0; i-- )
  121. {
  122. CScopePaneItem* pChild = pObject->GetScopeItem(i);
  123. pObject->RemoveScopeItem(i);
  124. if( pChild )
  125. {
  126. CScopePaneItem* pParent = pChild->GetParent();
  127. if( pParent )
  128. {
  129. pParent->DestroyChild(pChild);
  130. }
  131. }
  132. }
  133. delete pObject;
  134. }
  135. void CHMObject::UpdateStatus()
  136. {
  137. TRACEX(_T("CHMObject::UpdateStatus\n"));
  138. // set the state as appropriate
  139. CEventContainer* pContainer = NULL;
  140. EvtGetEventManager()->GetEventContainer(GetSystemName(),GetGuid(),pContainer);
  141. if( ! pContainer )
  142. {
  143. return;
  144. }
  145. SetState(CEvent::GetStatus(pContainer->m_iState),true);
  146. m_lNormalCount = pContainer->m_iNumberNormals;
  147. m_lWarningCount = pContainer->m_iNumberWarnings;
  148. m_lCriticalCount = pContainer->m_iNumberCriticals;
  149. m_lUnknownCount = pContainer->m_iNumberUnknowns;
  150. }
  151. void CHMObject::IncrementActiveSinkCount()
  152. {
  153. TRACEX(_T("CHMObject::IncrementActiveSinkCount\n"));
  154. m_lActiveSinkCount++;
  155. CHealthmonScopePane* pHMPane = (CHealthmonScopePane*)GetScopePane();
  156. if( ! pHMPane )
  157. {
  158. return;
  159. }
  160. CSystem* pSystem = pHMPane->GetSystem(GetSystemName());
  161. if( ! pSystem )
  162. {
  163. return;
  164. }
  165. pSystem->m_lTotalActiveSinkCount++;
  166. }
  167. void CHMObject::DecrementActiveSinkCount()
  168. {
  169. TRACEX(_T("CHMObject::DecrementActiveSinkCount\n"));
  170. m_lActiveSinkCount--;
  171. if( m_lActiveSinkCount == 0L )
  172. {
  173. UpdateStatus();
  174. }
  175. CHealthmonScopePane* pHMPane = (CHealthmonScopePane*)GetScopePane();
  176. if( ! pHMPane )
  177. {
  178. return;
  179. }
  180. CSystem* pSystem = pHMPane->GetSystem(GetSystemName());
  181. if( ! pSystem )
  182. {
  183. return;
  184. }
  185. pSystem->m_lTotalActiveSinkCount--;
  186. if( pSystem->m_lTotalActiveSinkCount == 0 )
  187. {
  188. EvtGetEventManager()->ActivateSystemEventListener(GetSystemName());
  189. }
  190. }
  191. void CHMObject::OnFinalRelease()
  192. {
  193. // When the last reference for an automation object is released
  194. // OnFinalRelease is called. The base class will automatically
  195. // deletes the object. Add additional cleanup required for your
  196. // object before calling the base class.
  197. CCmdTarget::OnFinalRelease();
  198. }
  199. BEGIN_MESSAGE_MAP(CHMObject, CCmdTarget)
  200. //{{AFX_MSG_MAP(CHMObject)
  201. // NOTE - the ClassWizard will add and remove mapping macros here.
  202. //}}AFX_MSG_MAP
  203. END_MESSAGE_MAP()
  204. BEGIN_DISPATCH_MAP(CHMObject, CCmdTarget)
  205. //{{AFX_DISPATCH_MAP(CHMObject)
  206. // NOTE - the ClassWizard will add and remove mapping macros here.
  207. //}}AFX_DISPATCH_MAP
  208. END_DISPATCH_MAP()
  209. // Note: we add support for IID_IHMObject to support typesafe binding
  210. // from VBA. This IID must match the GUID that is attached to the
  211. // dispinterface in the .ODL file.
  212. // {D9BF4F9A-F673-11D2-BDC4-0000F87A3912}
  213. static const IID IID_IHMObject =
  214. { 0xd9bf4f9a, 0xf673, 0x11d2, { 0xbd, 0xc4, 0x0, 0x0, 0xf8, 0x7a, 0x39, 0x12 } };
  215. BEGIN_INTERFACE_MAP(CHMObject, CCmdTarget)
  216. INTERFACE_PART(CHMObject, IID_IHMObject, Dispatch)
  217. END_INTERFACE_MAP()
  218. /////////////////////////////////////////////////////////////////////////////
  219. // CHMObject message handlers
  220. // 59492b
  221. // This will determine whether the object is the "Actions" item in the tree control
  222. //*********************************************************************************
  223. // IsActionsItem
  224. //*********************************************************************************
  225. BOOL CHMObject::IsActionsItem()
  226. {
  227. if (this->IsKindOf(RUNTIME_CLASS(CActionPolicy)))
  228. return TRUE;
  229. else
  230. return FALSE;
  231. }