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.

173 lines
3.4 KiB

  1. /*++
  2. Copyright (C) 1997-1999 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. // first get the current profile index.
  20. HWPROFILEINFO HwProfileInfo;
  21. ASSERT(pDevice);
  22. m_pDevice = pDevice;
  23. // get the current profile index.
  24. if (!m_pDevice->m_pMachine->CmGetCurrentHwProfile(&m_CurHwProfile))
  25. return FALSE;
  26. // go through each profile and create a CHwProfile for it
  27. int Index = 0;
  28. CHwProfile* phwpf;
  29. while (m_pDevice->m_pMachine->CmGetHwProfileInfo(Index, &HwProfileInfo))
  30. {
  31. DWORD hwpfFlags;
  32. // get the hwprofile flags for this device
  33. // if failed, use the given ConfigFlags
  34. if (m_pDevice->m_pMachine->CmGetHwProfileFlags((
  35. LPTSTR)m_pDevice->GetDeviceID(),
  36. HwProfileInfo.HWPI_ulHWProfile,
  37. &hwpfFlags))
  38. {
  39. if (hwpfFlags & CSCONFIGFLAG_DO_NOT_CREATE)
  40. {
  41. // skip this profile
  42. Index++;
  43. continue;
  44. }
  45. }
  46. else
  47. {
  48. // flags have not been set for this profile yet.
  49. hwpfFlags = ConfigFlags;
  50. }
  51. ASSERT(CONFIGFLAG_DISABLED == CSCONFIGFLAG_DISABLED);
  52. hwpfFlags |= ConfigFlags;
  53. // rememeber current hw profile index
  54. if (m_CurHwProfile == HwProfileInfo.HWPI_ulHWProfile)
  55. m_CurHwProfileIndex = Index;
  56. phwpf = new CHwProfile(Index, &HwProfileInfo, pDevice, hwpfFlags);
  57. m_listProfile.AddTail(phwpf);
  58. Index++;
  59. }
  60. return TRUE;
  61. }
  62. CHwProfileList::~CHwProfileList()
  63. {
  64. if (!m_listProfile.IsEmpty())
  65. {
  66. POSITION pos = m_listProfile.GetHeadPosition();
  67. while (NULL != pos)
  68. {
  69. CHwProfile* pProfile = m_listProfile.GetNext(pos);
  70. delete pProfile;
  71. }
  72. m_listProfile.RemoveAll();
  73. }
  74. }
  75. BOOL
  76. CHwProfileList::GetFirst(
  77. CHwProfile** pphwpf,
  78. PVOID& Context
  79. )
  80. {
  81. ASSERT(pphwpf);
  82. if (!m_listProfile.IsEmpty())
  83. {
  84. POSITION pos = m_listProfile.GetHeadPosition();
  85. *pphwpf = m_listProfile.GetNext(pos);
  86. Context = pos;
  87. return TRUE;
  88. }
  89. Context = NULL;
  90. *pphwpf = NULL;
  91. return FALSE;
  92. }
  93. BOOL
  94. CHwProfileList::GetNext(
  95. CHwProfile** pphwpf,
  96. PVOID& Context
  97. )
  98. {
  99. ASSERT(pphwpf);
  100. POSITION pos = (POSITION)Context;
  101. if (NULL != pos)
  102. {
  103. *pphwpf = m_listProfile.GetNext(pos);
  104. Context = pos;
  105. return TRUE;
  106. }
  107. *pphwpf = NULL;
  108. return FALSE;
  109. }
  110. BOOL
  111. CHwProfileList::GetCurrentHwProfile(
  112. CHwProfile** pphwpf
  113. )
  114. {
  115. ASSERT(pphwpf);
  116. POSITION pos = m_listProfile.FindIndex(m_CurHwProfileIndex);
  117. *pphwpf = m_listProfile.GetAt(pos);
  118. return TRUE;
  119. }
  120. ULONG
  121. CHwProfileList::IndexToHwProfile(
  122. int HwProfileIndex
  123. )
  124. {
  125. if (HwProfileIndex >= m_listProfile.GetCount())
  126. return 0XFFFFFFFF;
  127. POSITION pos = m_listProfile.FindIndex(HwProfileIndex);
  128. CHwProfile* pHwProfile = m_listProfile.GetAt(pos);
  129. return pHwProfile->GetHwProfile();
  130. }
  131. CHwProfile::CHwProfile(
  132. int Index,
  133. PHWPROFILEINFO phwpfInfo,
  134. CDevice* pDevice,
  135. DWORD Flags
  136. )
  137. {
  138. m_Index = Index;
  139. m_hwpfInfo = *phwpfInfo;
  140. m_pDevice = pDevice;
  141. m_EnablePending = FALSE;
  142. m_DisablePending = FALSE;
  143. m_Flags = Flags;
  144. }