Leaked source code of windows server 2003
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.

270 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1994-95 Microsoft Corporation
  3. Module Name:
  4. srvcol.cpp
  5. Abstract:
  6. Server 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(CServers, CCmdTarget)
  20. BEGIN_MESSAGE_MAP(CServers, CCmdTarget)
  21. //{{AFX_MSG_MAP(CServers)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. BEGIN_DISPATCH_MAP(CServers, CCmdTarget)
  26. //{{AFX_DISPATCH_MAP(CServers)
  27. DISP_PROPERTY_EX(CServers, "Application", GetApplication, SetNotSupported, VT_DISPATCH)
  28. DISP_PROPERTY_EX(CServers, "Parent", GetParent, SetNotSupported, VT_DISPATCH)
  29. DISP_PROPERTY_EX(CServers, "Count", GetCount, SetNotSupported, VT_I4)
  30. DISP_FUNCTION(CServers, "Item", GetItem, VT_DISPATCH, VTS_VARIANT)
  31. //}}AFX_DISPATCH_MAP
  32. END_DISPATCH_MAP()
  33. CServers::CServers(CCmdTarget* pParent, CObArray* pObArray)
  34. /*++
  35. Routine Description:
  36. Constructor for server 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(CDomain)));
  47. #endif // ENABLE_PARENT_CHECK
  48. ASSERT_VALID(pObArray);
  49. m_pParent = pParent;
  50. m_pObArray = pObArray;
  51. }
  52. CServers::~CServers()
  53. /*++
  54. Routine Description:
  55. Destructor for server collection object.
  56. Arguments:
  57. None.
  58. Return Values:
  59. None.
  60. --*/
  61. {
  62. //
  63. // Nothing to do here.
  64. //
  65. }
  66. void CServers::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 CServers::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 CServers::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 CServers::GetItem(const VARIANT FAR& index)
  105. /*++
  106. Routine Description:
  107. Retrieves specified server object from collection.
  108. Arguments:
  109. index - optional argument that may be a string (VT_BSTR)
  110. indicating the server name or a number (VT_I4) indicating
  111. the position within collection.
  112. Return Values:
  113. VT_DISPATCH or VT_EMPTY.
  114. --*/
  115. {
  116. ASSERT_VALID(m_pObArray);
  117. LPDISPATCH lpdispatch = NULL;
  118. CServer* pServer;
  119. INT_PTR iServer;
  120. VARIANT vServer;
  121. VariantInit(&vServer);
  122. iServer = m_pObArray->GetSize();
  123. if (NULL != iServer)
  124. {
  125. if (index.vt == VT_BSTR)
  126. {
  127. while (iServer--)
  128. {
  129. pServer = (CServer*)m_pObArray->GetAt(iServer);
  130. if (NULL != pServer)
  131. {
  132. ASSERT(pServer->IsKindOf(RUNTIME_CLASS(CServer)));
  133. if (!pServer->m_strName.CompareNoCase(index.bstrVal))
  134. {
  135. lpdispatch = pServer->GetIDispatch(TRUE);
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. else if (SUCCEEDED(VariantChangeType(&vServer, (VARIANT FAR *)&index, 0, VT_I4)))
  142. {
  143. if (((int)vServer.lVal >= 0) && ((int)vServer.lVal < iServer))
  144. {
  145. pServer = (CServer*)m_pObArray->GetAt((int)vServer.lVal);
  146. if (NULL != pServer)
  147. {
  148. ASSERT(pServer->IsKindOf(RUNTIME_CLASS(CServer)));
  149. lpdispatch = pServer->GetIDispatch(TRUE);
  150. }
  151. }
  152. }
  153. }
  154. return lpdispatch;
  155. }
  156. LPDISPATCH CServers::GetParent()
  157. /*++
  158. Routine Description:
  159. Returns the parent of the object.
  160. Arguments:
  161. None.
  162. Return Values:
  163. VT_DISPATCH.
  164. --*/
  165. {
  166. return m_pParent ? m_pParent->GetIDispatch(TRUE) : NULL;
  167. }