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.

194 lines
3.9 KiB

  1. //
  2. // Microsoft
  3. //
  4. // CollectionAdapter.h
  5. #pragma once
  6. #include "ScopeCriticalSection.h"
  7. #include "AdapterInfo.h"
  8. #include "PrimaryControlChannel.h"
  9. #include <list>
  10. #include <algorithm>
  11. //
  12. // Adapters
  13. //
  14. typedef std::list<IAdapterInfo*> LISTOF_ADAPTERS;
  15. //
  16. //
  17. //
  18. class CCollectionAdapters
  19. {
  20. //
  21. // Properties
  22. //
  23. public:
  24. CComAutoCriticalSection m_AutoCS;
  25. LISTOF_ADAPTERS m_ListOfAdapters;
  26. //
  27. // Methods
  28. //
  29. public:
  30. //
  31. // standard destructor
  32. //
  33. ~CCollectionAdapters();
  34. //
  35. // Add a new Adapter (Thread safe)
  36. //
  37. HRESULT
  38. Add(
  39. IN IAdapterInfo* pAdapterToAdd
  40. );
  41. //
  42. // This version of Add will actualy create the new IAdapterInfo before adding it to the collection
  43. // return the newly created IAdapterInfo or NULL is faild
  44. //
  45. IAdapterInfo*
  46. Add(
  47. IN ULONG nCookie,
  48. IN short nType
  49. );
  50. //
  51. // Remove a adapter from the list (Thead safe)
  52. // by removing a adapter it will also kill all associated ControlChannel
  53. //
  54. HRESULT
  55. Remove(
  56. IN IAdapterInfo* pAdapterToRemove
  57. );
  58. //
  59. // This version od Remove will remove the IAdapterInfo base on the given index
  60. //
  61. HRESULT
  62. Remove(
  63. IN ULONG nCookie
  64. );
  65. //
  66. // Remove all the adapter from the collection
  67. //
  68. HRESULT
  69. RemoveAll();
  70. //
  71. // Return an IAdapterInfo the caller is responsable of releasing the interface
  72. //
  73. HRESULT
  74. GetAdapterInfo(
  75. IN ULONG nCookie,
  76. OUT IAdapterInfo** ppAdapterInfo
  77. );
  78. //
  79. // Bind the given addresses with the given index representing the AdapterInfo
  80. //
  81. HRESULT
  82. SetAddresses(
  83. IN ULONG nCookie,
  84. IN ULONG nAdapterIndex,
  85. IN ULONG nAddressCount,
  86. IN DWORD anAddress[]
  87. );
  88. HRESULT
  89. ApplyPrimaryChannel(
  90. CPrimaryControlChannel* pChannelToActivate
  91. );
  92. HRESULT
  93. AdapterUpdatePrimaryChannel(
  94. ULONG nCookie,
  95. CPrimaryControlChannel *pChannel
  96. );
  97. private:
  98. //
  99. // Will return the IAdapterInfo* of for the given Cookie or NULL if not found
  100. //
  101. IAdapterInfo*
  102. FindUsingCookie(
  103. ULONG nCookie
  104. )
  105. {
  106. for ( LISTOF_ADAPTERS::iterator theIterator = m_ListOfAdapters.begin();
  107. theIterator != m_ListOfAdapters.end();
  108. theIterator++
  109. )
  110. {
  111. CAdapterInfo* pAdapterInfo = (CAdapterInfo*)(*theIterator);
  112. if ( pAdapterInfo->m_nCookie == nCookie )
  113. return *theIterator;
  114. }
  115. return NULL;
  116. }
  117. //
  118. // Will return the IAdapterInfo* of given the AdapterIndex or NULL if not found
  119. //
  120. IAdapterInfo*
  121. FindUsingAdapterIndex(
  122. ULONG nAdapterIndex
  123. )
  124. {
  125. MYTRACE_ENTER("FindUsingAdapterIndex");
  126. MYTRACE("Looking for adapter %d", nAdapterIndex);
  127. for ( LISTOF_ADAPTERS::iterator theIterator = m_ListOfAdapters.begin();
  128. theIterator != m_ListOfAdapters.end();
  129. theIterator++
  130. )
  131. {
  132. CAdapterInfo* pAdapterInfo = (CAdapterInfo*)(*theIterator);
  133. MYTRACE("ADAPTER index %d", pAdapterInfo->m_nAdapterIndex);
  134. if ( pAdapterInfo->m_nAdapterIndex == nAdapterIndex )
  135. return *theIterator;
  136. }
  137. return NULL;
  138. }
  139. //
  140. // Return true if the AdapterInfo is part of the collection
  141. //
  142. inline bool
  143. FindUsingInterface(
  144. IAdapterInfo* pAdapterToFind
  145. )
  146. {
  147. LISTOF_ADAPTERS::iterator theIterator = std::find(
  148. m_ListOfAdapters.begin(),
  149. m_ListOfAdapters.end(),
  150. pAdapterToFind
  151. );
  152. return *theIterator ? true : false;
  153. }
  154. };