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.

265 lines
4.4 KiB

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