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.

291 lines
7.1 KiB

  1. // File: confqos.cpp
  2. #include "precomp.h"
  3. #include <nacguids.h>
  4. #include <initguid.h>
  5. #include <datguids.h>
  6. #include <common.h>
  7. #include <nmqos.h>
  8. #include "confqos.h"
  9. /***************************************************************************
  10. Name : CQoS
  11. Purpose :
  12. Parameters: NONE
  13. Returns : HRESULT
  14. Comment :
  15. ***************************************************************************/
  16. CQoS::CQoS() :
  17. m_pIQoS(NULL)
  18. {
  19. }
  20. /***************************************************************************
  21. Name : ~CQoS
  22. Purpose : Releases the Quality of Service objects and frees the DLL
  23. Parameters: NONE
  24. Returns : HRESULT
  25. Comment :
  26. ***************************************************************************/
  27. CQoS::~CQoS()
  28. {
  29. // release the object
  30. if (m_pIQoS)
  31. {
  32. m_pIQoS->Release();
  33. }
  34. }
  35. /***************************************************************************
  36. Name : Initialize
  37. Purpose : Loads the QoS DLL and instantiates a QoS object
  38. Parameters: hWnd - handle to the window/dialog which called us
  39. Returns : HRESULT
  40. Comment :
  41. ***************************************************************************/
  42. HRESULT CQoS::Initialize(void)
  43. {
  44. HRESULT hr = S_OK;
  45. // create the QoS object and get the IQoS interface
  46. // CoInitialize is called in conf.cpp
  47. hr = CoCreateInstance( CLSID_QoS,
  48. NULL,
  49. CLSCTX_INPROC_SERVER,
  50. IID_IQoS,
  51. (void **) &m_pIQoS);
  52. if (FAILED(hr))
  53. {
  54. WARNING_OUT(("CQoS: Could not obtain an IQoS interface, hr=0x%08lX", hr));
  55. }
  56. else
  57. {
  58. SetClients();
  59. // Tell the QoS about available resources. Since the wizard will
  60. // provide the bandwidth info, we'll have to call SetResources
  61. // again later with the bandwidth, but we need to call it here
  62. // to make the CPU info available to the wizard
  63. SetResources(BW_288KBS_BITS);
  64. }
  65. return hr;
  66. }
  67. /***************************************************************************
  68. Name : CQoS::SetResources
  69. Purpose : Sets the initial available resources on the QoS module,
  70. i.e. configures the QoS module to how much is
  71. available from each resource.
  72. Parameters: nBandWidth - Maximum connection speed
  73. Returns : HRESULT
  74. Comment : The QoS module may select to override these settings
  75. ***************************************************************************/
  76. HRESULT CQoS::SetResources(int nBandWidth)
  77. {
  78. LPRESOURCELIST prl = NULL;
  79. HRESULT hr = S_OK;
  80. const int cResources = 3;
  81. ASSERT(m_pIQoS);
  82. DbgMsg(iZONE_API, "CQoS: SetResources(Bandwidth = %d)", nBandWidth);
  83. // allocate space for the resource list (which already includes
  84. // space for one resource), plus (cResources-1) more resources
  85. prl = (LPRESOURCELIST) MemAlloc(sizeof(RESOURCELIST) +
  86. (cResources-1)*sizeof(RESOURCE));
  87. if (NULL == prl)
  88. {
  89. ERROR_OUT(("CQoS: SetResources - MemAlloc failed"));
  90. }
  91. else
  92. {
  93. ZeroMemory(prl, sizeof(RESOURCELIST) + (cResources-1)*sizeof(RESOURCE));
  94. // fill in the resource list
  95. prl->cResources = cResources;
  96. prl->aResources[0].resourceID = RESOURCE_OUTGOING_BANDWIDTH;
  97. prl->aResources[0].nUnits = nBandWidth;
  98. prl->aResources[1].resourceID = RESOURCE_INCOMING_BANDWIDTH;
  99. prl->aResources[1].nUnits = nBandWidth;
  100. prl->aResources[2].resourceID = RESOURCE_CPU_CYCLES;
  101. prl->aResources[2].nUnits = MSECS_PER_SEC;
  102. // set the resources on the QoS object
  103. hr = m_pIQoS->SetResources(prl);
  104. if (FAILED(hr))
  105. {
  106. ERROR_OUT(("CQoS: SetResources: Fail, hr=0x%x", hr));
  107. }
  108. MemFree(prl);
  109. }
  110. return hr;
  111. }
  112. /***************************************************************************
  113. Name : CQoS::SetBandwidth
  114. Purpose : Sets the initial available resources on the QoS module,
  115. i.e. configures the QoS module to how much is
  116. available from each resource.
  117. Parameters:
  118. Returns : HRESULT
  119. Comment : The QoS module may select to override these settings
  120. ***************************************************************************/
  121. HRESULT CQoS::SetBandwidth(UINT uBandwidth)
  122. {
  123. return SetResources(uBandwidth);
  124. }
  125. /***************************************************************************
  126. Name : CQoS::GetCPULimit
  127. Purpose : Gets the total allowed CPU percentage use from QoS
  128. Parameters:
  129. Returns : How much of the CPU can be used, in percents. 0 means failure
  130. Comment :
  131. ***************************************************************************/
  132. ULONG CQoS::GetCPULimit()
  133. {
  134. LPRESOURCELIST pResourceList=NULL;
  135. ULONG ulCPUPercents=0;
  136. ULONG i;
  137. HRESULT hr = NOERROR;
  138. ASSERT(m_pIQoS);
  139. // get a list of all resources from QoS
  140. hr = m_pIQoS->GetResources(&pResourceList);
  141. if (FAILED(hr) || (NULL == pResourceList))
  142. {
  143. ERROR_OUT(("GetQoSCPULimit: GetResources failed"));
  144. }
  145. else
  146. {
  147. // find the CPU resource
  148. for (i=0; i < pResourceList->cResources; i++)
  149. {
  150. if (pResourceList->aResources[i].resourceID == RESOURCE_CPU_CYCLES)
  151. {
  152. // QoS keeps the CPU units as the number of ms in a sec that the
  153. // CPU can be used. Need to divide by 10 to get percents
  154. ulCPUPercents = pResourceList->aResources[i].nUnits / 10;
  155. break;
  156. }
  157. }
  158. m_pIQoS->FreeBuffer(pResourceList);
  159. }
  160. return ulCPUPercents;
  161. }
  162. /***************************************************************************
  163. Name : CQoS::SetClients
  164. Purpose : Set the priorities of requesting clients so that the QoS module
  165. will know who should get more resources
  166. Parameters: None
  167. Returns : HRESULT
  168. Comment :
  169. ***************************************************************************/
  170. HRESULT CQoS::SetClients(void)
  171. {
  172. LPCLIENTLIST pcl = NULL;
  173. ULONG i;
  174. HRESULT hr = S_OK;
  175. ULONG cClients = 3; // audio, video and data
  176. ASSERT(m_pIQoS);
  177. // allocate space for the client list (which already includes
  178. // space for one client), plus (cClients-1) more clients
  179. pcl = (LPCLIENTLIST) MemAlloc(sizeof(CLIENTLIST) +
  180. (cClients-1)*sizeof(CLIENT));
  181. if (NULL == pcl)
  182. {
  183. ERROR_OUT(("CQoS: SetClient - MemAlloc failed"));
  184. }
  185. else
  186. {
  187. ZeroMemory(pcl, sizeof(CLIENTLIST) +
  188. (cClients-1)*sizeof(CLIENT));
  189. // fill in the resource list
  190. pcl->cClients = cClients;
  191. i=0;
  192. // Audio
  193. pcl->aClients[i].guidClientGUID = MEDIA_TYPE_H323AUDIO;
  194. pcl->aClients[i].wszName[0] = L'A'; // A=Audio
  195. pcl->aClients[i++].priority = 1;
  196. // Data
  197. pcl->aClients[i].guidClientGUID = MEDIA_TYPE_T120DATA;
  198. pcl->aClients[i].wszName[0] = L'D'; // D=Data
  199. pcl->aClients[i++].priority = 2;
  200. // Audio
  201. pcl->aClients[i].guidClientGUID = MEDIA_TYPE_H323VIDEO;
  202. pcl->aClients[i].wszName[0] = L'V'; // V=Video
  203. pcl->aClients[i++].priority = 3;
  204. // the rest of the fields are not important and were set to 0 above
  205. // set the clients info on the QoS module
  206. hr = m_pIQoS->SetClients(pcl);
  207. if (FAILED(hr))
  208. {
  209. ERROR_OUT(("CQoS: SetClients: Fail, hr=0x%x", hr));
  210. }
  211. MemFree(pcl);
  212. }
  213. return hr;
  214. }