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.

267 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. stacol.cpp
  5. Abstract:
  6. Statistic collection object implementation.
  7. Author:
  8. Don Ryan (donryan) 04-Jan-1995
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #include "stdafx.h"
  14. #include "llsmgr.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char BASED_CODE THIS_FILE[] = __FILE__;
  18. #endif
  19. IMPLEMENT_DYNCREATE(CStatistics, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CStatistics, CCmdTarget)
  21. //{{AFX_MSG_MAP(CStatistics)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CStatistics, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CStatistics)
  27. DISP_PROPERTY_EX(CStatistics, "Count", GetCount, SetNotSupported, VT_I4)
  28. DISP_PROPERTY_EX(CStatistics, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CStatistics, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  30. DISP_FUNCTION(CStatistics, "Item", GetItem, VT_DISPATCH, VTS_VARIANT)
  31. //}}AFX_DISPATCH_MAP
  32. END_DISPATCH_MAP()
  33. CStatistics::CStatistics(CCmdTarget* pParent, CObArray* pObArray)
  34. /*++
  35. Routine Description:
  36. Constructor for statistic collection object.
  37. Arguments:
  38. pParent - creator of object.
  39. pObArray - object list to enumerate.
  40. Return Values:
  41. None.
  42. --*/
  43. {
  44. EnableAutomation();
  45. #ifdef ENABLE_PARENT_CHECK
  46. ASSERT(pParent &&
  47. (pParent->IsKindOf(RUNTIME_CLASS(CUser)) ||
  48. pParent->IsKindOf(RUNTIME_CLASS(CProduct))));
  49. #endif // ENABLE_PARENT_CHECK
  50. ASSERT_VALID(pObArray);
  51. m_pParent = pParent;
  52. m_pObArray = pObArray;
  53. }
  54. CStatistics::~CStatistics()
  55. /*++
  56. Routine Description:
  57. Destructor for statistic collection object.
  58. Arguments:
  59. None.
  60. Return Values:
  61. None.
  62. --*/
  63. {
  64. //
  65. // Nothing to do here.
  66. //
  67. }
  68. void CStatistics::OnFinalRelease()
  69. /*++
  70. Routine Description:
  71. When the last reference for an automation object is released
  72. OnFinalRelease is called. This implementation deletes object.
  73. Arguments:
  74. None.
  75. Return Values:
  76. None.
  77. --*/
  78. {
  79. delete this;
  80. }
  81. LPDISPATCH CStatistics::GetApplication()
  82. /*++
  83. Routine Description:
  84. Returns the application object.
  85. Arguments:
  86. None.
  87. Return Values:
  88. VT_DISPATCH.
  89. --*/
  90. {
  91. return theApp.GetAppIDispatch();
  92. }
  93. long CStatistics::GetCount()
  94. /*++
  95. Routine Description:
  96. Returns number of items in collection.
  97. Arguments:
  98. None.
  99. Return Values:
  100. VT_I4.
  101. --*/
  102. {
  103. ASSERT_VALID(m_pObArray);
  104. return (long) m_pObArray->GetSize();
  105. }
  106. LPDISPATCH CStatistics::GetItem(const VARIANT FAR& index)
  107. /*++
  108. Routine Description:
  109. Retrieves specified statistic object from collection.
  110. Arguments:
  111. index - optional argument that may be a string (VT_BSTR)
  112. indicating a entry name or a number (VT_I4) indicating the
  113. position within collection.
  114. Return Values:
  115. VT_DISPATCH.
  116. --*/
  117. {
  118. ASSERT_VALID(m_pObArray);
  119. LPDISPATCH lpdispatch = NULL;
  120. CStatistic* pStatistic;
  121. INT_PTR iStatistic;
  122. VARIANT vStatistic;
  123. VariantInit(&vStatistic);
  124. if (iStatistic = m_pObArray->GetSize())
  125. {
  126. if (index.vt == VT_BSTR)
  127. {
  128. while (iStatistic--)
  129. {
  130. if (pStatistic = (CStatistic*)m_pObArray->GetAt(iStatistic))
  131. {
  132. ASSERT(pStatistic->IsKindOf(RUNTIME_CLASS(CStatistic)));
  133. if (!pStatistic->m_strEntry.CompareNoCase(index.bstrVal))
  134. {
  135. lpdispatch = pStatistic->GetIDispatch(TRUE);
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. else if (SUCCEEDED(VariantChangeType(&vStatistic, (VARIANT FAR *)&index, 0, VT_I4)))
  142. {
  143. if (((int)vStatistic.lVal >= 0) && ((int)vStatistic.lVal < iStatistic))
  144. {
  145. if (pStatistic = (CStatistic*)m_pObArray->GetAt((int)vStatistic.lVal))
  146. {
  147. ASSERT(pStatistic->IsKindOf(RUNTIME_CLASS(CStatistic)));
  148. lpdispatch = pStatistic->GetIDispatch(TRUE);
  149. }
  150. }
  151. }
  152. }
  153. return lpdispatch;
  154. }
  155. LPDISPATCH CStatistics::GetParent()
  156. /*++
  157. Routine Description:
  158. Returns the parent of the object.
  159. Arguments:
  160. None.
  161. Return Values:
  162. VT_DISPATCH.
  163. --*/
  164. {
  165. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  166. }