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.

180 lines
3.6 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation
  3. Module Name:
  4. hwprof.cpp
  5. Abstract:
  6. This module implements CHwProfileList and CHwProfile classes.
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #include "devmgr.h"
  12. #include "hwprof.h"
  13. BOOL
  14. CHwProfileList::Create(
  15. CDevice* pDevice,
  16. DWORD ConfigFlags
  17. )
  18. {
  19. //
  20. // First get the current profile index.
  21. //
  22. HWPROFILEINFO HwProfileInfo;
  23. ASSERT(pDevice);
  24. m_pDevice = pDevice;
  25. //
  26. // Get the current profile index.
  27. //
  28. if (!m_pDevice->m_pMachine->CmGetCurrentHwProfile(&m_CurHwProfile)) {
  29. return FALSE;
  30. }
  31. //
  32. // Go through each profile and create a CHwProfile for it
  33. //
  34. int Index = 0;
  35. CHwProfile* phwpf;
  36. while (m_pDevice->m_pMachine->CmGetHwProfileInfo(Index, &HwProfileInfo)) {
  37. DWORD hwpfFlags;
  38. //
  39. // Get the hwprofile flags for this device
  40. // if failed, use the given ConfigFlags
  41. //
  42. if (m_pDevice->m_pMachine->CmGetHwProfileFlags((
  43. LPTSTR)m_pDevice->GetDeviceID(),
  44. HwProfileInfo.HWPI_ulHWProfile,
  45. &hwpfFlags)) {
  46. if (hwpfFlags & CSCONFIGFLAG_DO_NOT_CREATE) {
  47. //
  48. // Skip this profile
  49. //
  50. Index++;
  51. continue;
  52. }
  53. } else {
  54. //
  55. // Flags have not been set for this profile yet.
  56. //
  57. hwpfFlags = ConfigFlags;
  58. }
  59. ASSERT(CONFIGFLAG_DISABLED == CSCONFIGFLAG_DISABLED);
  60. hwpfFlags |= ConfigFlags;
  61. //
  62. // Rememeber current hw profile index
  63. //
  64. if (m_CurHwProfile == HwProfileInfo.HWPI_ulHWProfile) {
  65. m_CurHwProfileIndex = Index;
  66. }
  67. phwpf = new CHwProfile(Index, &HwProfileInfo, pDevice, hwpfFlags);
  68. m_listProfile.AddTail(phwpf);
  69. Index++;
  70. }
  71. return TRUE;
  72. }
  73. CHwProfileList::~CHwProfileList()
  74. {
  75. if (!m_listProfile.IsEmpty()) {
  76. POSITION pos = m_listProfile.GetHeadPosition();
  77. while (NULL != pos) {
  78. CHwProfile* pProfile = m_listProfile.GetNext(pos);
  79. delete pProfile;
  80. }
  81. m_listProfile.RemoveAll();
  82. }
  83. }
  84. BOOL
  85. CHwProfileList::GetFirst(
  86. CHwProfile** pphwpf,
  87. PVOID& Context
  88. )
  89. {
  90. ASSERT(pphwpf);
  91. if (!m_listProfile.IsEmpty()) {
  92. POSITION pos = m_listProfile.GetHeadPosition();
  93. *pphwpf = m_listProfile.GetNext(pos);
  94. Context = pos;
  95. return TRUE;
  96. }
  97. Context = NULL;
  98. *pphwpf = NULL;
  99. return FALSE;
  100. }
  101. BOOL
  102. CHwProfileList::GetNext(
  103. CHwProfile** pphwpf,
  104. PVOID& Context
  105. )
  106. {
  107. ASSERT(pphwpf);
  108. POSITION pos = (POSITION)Context;
  109. if (NULL != pos) {
  110. *pphwpf = m_listProfile.GetNext(pos);
  111. Context = pos;
  112. return TRUE;
  113. }
  114. *pphwpf = NULL;
  115. return FALSE;
  116. }
  117. BOOL
  118. CHwProfileList::GetCurrentHwProfile(
  119. CHwProfile** pphwpf
  120. )
  121. {
  122. ASSERT(pphwpf);
  123. POSITION pos = m_listProfile.FindIndex(m_CurHwProfileIndex);
  124. *pphwpf = m_listProfile.GetAt(pos);
  125. return TRUE;
  126. }
  127. CHwProfile::CHwProfile(
  128. int Index,
  129. PHWPROFILEINFO phwpfInfo,
  130. CDevice* pDevice,
  131. DWORD Flags
  132. )
  133. {
  134. m_Index = Index;
  135. m_hwpfInfo = *phwpfInfo;
  136. m_pDevice = pDevice;
  137. m_EnablePending = FALSE;
  138. m_DisablePending = FALSE;
  139. m_Flags = Flags;
  140. }