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.

241 lines
6.8 KiB

  1. /*
  2. - QOSINT.H
  3. -
  4. * Microsoft NetMeeting
  5. * Quality of Service DLL
  6. * Internal QoS header file
  7. *
  8. * Revision History:
  9. *
  10. * When Who What
  11. * -------- ------------------ ---------------------------------------
  12. * 10.24.96 Yoram Yaacovi Created
  13. *
  14. */
  15. #include <pshpack8.h> /* Assume 8 byte packing throughout */
  16. #ifdef DEBUG
  17. /*
  18. * Debug stuff
  19. */
  20. extern HDBGZONE ghDbgZoneQoS;
  21. #define ZONE_INIT (GETMASK(ghDbgZoneQoS) & 0x0001)
  22. #define ZONE_IQOS (GETMASK(ghDbgZoneQoS) & 0x0002)
  23. #define ZONE_THREAD (GETMASK(ghDbgZoneQoS) & 0x0004)
  24. #define ZONE_STRUCTURES (GETMASK(ghDbgZoneQoS) & 0x0008)
  25. #define ZONE_PARAMETERS (GETMASK(ghDbgZoneQoS) & 0x0010)
  26. int QoSDbgPrintf(LPCSTR lpszFormat, ...);
  27. // MACRO: DEBUGMSG(zone,message-to-print)
  28. // PURPOSE: If the zone is enabled, prints a message to the debug output
  29. // NOTE: in debug build - if the zone is turned on
  30. #define DEBUGMSG(z,s) ( (z) ? (QoSDbgPrintf s) : 0)
  31. // MACRO: DISPLAYQOSOBJECT()
  32. // PURPOSE: Displays the internal structures of the QoS object
  33. // NOTE: in debug build - if the zone is turned on
  34. #define DISPLAYQOSOBJECT() DisplayQoSObject()
  35. // MACRO: DISPLAYPARAMETERS(nFunctionID)
  36. // PURPOSE: Displays the parameters of a given function
  37. // NOTE: in debug build - if the zone is turned on
  38. #define DISPLAYPARAMETERS(fid, p1, p2, p3, p4, p5) \
  39. DisplayParameters(fid, (ULONG_PTR) p1, (ULONG_PTR) p2, (ULONG_PTR) p3, (ULONG_PTR) p4, (ULONG_PTR) p5)
  40. // MACRO: QOSDEBUGINIT
  41. // PURPOSE: Initializes the QoS debug zones, ONLY IF not initialized yet
  42. // NOTE:
  43. #define QOSDEBUGINIT() \
  44. if (!ghDbgZoneQoS) \
  45. DBGINIT(&ghDbgZoneQoS, _rgZonesQos);
  46. #define WAIT_ON_MUTEX_MSEC 20000
  47. #else // retail
  48. #define DISPLAYQOSOBJECT()
  49. #define DISPLAYPARAMETERS(fid, p1, p2, p3, p4, p5)
  50. #define DEBUGMSG(z,s)
  51. #define QOSDEBUGINIT()
  52. #define WAIT_ON_MUTEX_MSEC 5000
  53. #endif
  54. /*
  55. * Constants
  56. */
  57. // IDs for parameters display (debug use only)
  58. #define REQUEST_RESOURCES_ID 1
  59. #define SET_RESOURCES_ID 2
  60. #define RELEASE_RESOURCES_ID 3
  61. #define SET_CLIENTS_ID 4
  62. #define QOS_LOWEST_PRIORITY 10
  63. /*
  64. * Macros
  65. */
  66. #define COMPARE_GUIDS(a,b) RtlEqualMemory((a), (b), sizeof(GUID))
  67. #define ACQMUTEX(hMutex) \
  68. while (WaitForSingleObject(hMutex, WAIT_ON_MUTEX_MSEC) == WAIT_TIMEOUT) \
  69. { \
  70. ERRORMSG(("Thread 0x%x waits on mutex\n", GetCurrentThreadId())); \
  71. } \
  72. #define RELMUTEX(hMutex) ReleaseMutex(hMutex)
  73. /*
  74. * Data Structures
  75. */
  76. // internal resource request structure
  77. typedef struct _resourcerequestint
  78. {
  79. struct _resourcerequestint *fLink;
  80. RESOURCEREQUEST sResourceRequest;
  81. GUID guidClientGUID;
  82. LPFNQOSNOTIFY pfnQoSNotify;
  83. DWORD_PTR dwParam;
  84. } RESOURCEREQUESTINT, *LPRESOURCEREQUESTINT;
  85. // internal resource structure
  86. typedef struct _resourceint
  87. {
  88. struct _resourceint *fLink;
  89. RESOURCE resource;
  90. int nNowAvailUnits;
  91. RESOURCEREQUESTINT *pRequestList;
  92. } RESOURCEINT, *LPRESOURCEINT;
  93. // internal client structure
  94. typedef struct _clientint
  95. {
  96. struct _clientint *fLink;
  97. CLIENT client;
  98. RESOURCEREQUESTINT *pRequestList;
  99. } CLIENTINT, *LPCLIENTINT;
  100. class CQoS : public IQoS
  101. {
  102. public:
  103. // IUnknown methods
  104. STDMETHODIMP QueryInterface (REFIID riid, void **ppv);
  105. STDMETHODIMP_(ULONG) AddRef (void);
  106. STDMETHODIMP_(ULONG) Release (void);
  107. // IQoS methods
  108. STDMETHODIMP RequestResources (LPGUID lpStreamGUID,
  109. LPRESOURCEREQUESTLIST lpResourceRequestList,
  110. LPFNQOSNOTIFY lpfnQoSNotify,
  111. DWORD_PTR dwParam);
  112. STDMETHODIMP ReleaseResources (LPGUID lpStreamGUID,
  113. LPRESOURCEREQUESTLIST lpResourceRequestList);
  114. STDMETHODIMP GetResources (LPRESOURCELIST *lppResourceList);
  115. STDMETHODIMP SetResources (LPRESOURCELIST lpResourceList);
  116. STDMETHODIMP SetClients(LPCLIENTLIST lpClientList);
  117. STDMETHODIMP NotifyNow(void);
  118. STDMETHODIMP FreeBuffer(LPVOID lpBuffer);
  119. // IProps methods
  120. STDMETHODIMP SetProps (ULONG cValues,
  121. PPROPERTY pPropArray);
  122. STDMETHODIMP GetProps (PPROPTAGARRAY pPropTagArray,
  123. ULONG ulFlags,
  124. ULONG FAR *pcValues,
  125. PPROPERTY *ppPropArray);
  126. CQoS (void);
  127. ~CQoS (void);
  128. HRESULT Initialize(void);
  129. private:
  130. // Private functions
  131. HRESULT QoSCleanup(void);
  132. BOOL AnyRequests(void);
  133. HRESULT FindClientsForResource( DWORD dwResourceID,
  134. LPCLIENTINT pc,
  135. ULONG *puSamePriClients,
  136. ULONG *puLowerPriClients);
  137. HRESULT FreeListOfRequests(LPRESOURCEREQUESTINT *lppList);
  138. HRESULT StoreResourceRequest(LPGUID pClientGUID,
  139. LPRESOURCEREQUEST pResourceRequest,
  140. LPFNQOSNOTIFY pfnQoSNotify,
  141. DWORD_PTR dwParam,
  142. LPRESOURCEINT pResourceInt);
  143. HRESULT FreeResourceRequest(LPGUID pClientGUID,
  144. LPRESOURCEINT pResourceInt,
  145. int *pnUnits);
  146. HRESULT UpdateClientInfo ( LPGUID pClientGUID,
  147. LPFNQOSNOTIFY pfnQoSNotify);
  148. HRESULT UpdateRequestsForClient (LPGUID pClientGUID);
  149. HRESULT FindClient(LPGUID pClientGUID, LPCLIENTINT *ppClient);
  150. HRESULT StartQoSThread(void);
  151. HRESULT StopQoSThread(void);
  152. DWORD QoSThread(void);
  153. HRESULT NotifyQoSClient(void);
  154. // Debug display functions
  155. void DisplayQoSObject(void);
  156. void DisplayRequestListInt(LPRESOURCEREQUESTINT prr, BOOL fDisplay);
  157. void DisplayRequestList(LPRESOURCEREQUESTLIST prrl);
  158. void DisplayParameters(ULONG nFunctionID, ULONG_PTR P1, ULONG_PTR P2, ULONG_PTR P3, ULONG_PTR P4, ULONG_PTR P5);
  159. void DisplayResourceList(LPRESOURCELIST prl);
  160. void DisplayClientList(LPCLIENTLIST pcl);
  161. friend DWORD QoSThreadWrapper(CQoS *pQoS);
  162. // Variables
  163. int m_cRef;
  164. LPRESOURCEINT m_pResourceList;
  165. ULONG m_cResources;
  166. LPCLIENTINT m_pClientList;
  167. HANDLE m_evThreadExitSignal;
  168. HANDLE m_evImmediateNotify;
  169. HANDLE m_hThread; // handle of the QoS notify thread
  170. BOOL m_bQoSEnabled; // whether QoS is enabled or not
  171. BOOL m_bInNotify;
  172. ULONG m_nSkipHeartBeats; // how many heartbeats should the QoS notify thread skip
  173. HWND m_hWnd;
  174. ULONG m_nLeaveForNextPri; // percentage of the rsrc to leave for lower priority clients
  175. BOOL bWin9x; //Windows 9x (TRUE) or NT (FALSE)
  176. };
  177. /*
  178. * QoS Class factory
  179. */
  180. typedef HRESULT (STDAPICALLTYPE *PFNCREATE)(IUnknown *, REFIID, void **);
  181. class CClassFactory : public IClassFactory
  182. {
  183. public:
  184. //IUnknown members
  185. STDMETHODIMP QueryInterface(REFIID, void **);
  186. STDMETHODIMP_(ULONG) AddRef(void);
  187. STDMETHODIMP_(ULONG) Release(void);
  188. //IClassFactory members
  189. STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, void **);
  190. STDMETHODIMP LockServer(BOOL);
  191. CClassFactory(PFNCREATE);
  192. ~CClassFactory(void);
  193. protected:
  194. ULONG m_cRef;
  195. PFNCREATE m_pfnCreate;
  196. };
  197. /*
  198. * Globals
  199. */
  200. EXTERN_C HANDLE g_hQoSMutex;
  201. EXTERN_C class CQoS *g_pQoS;
  202. /*
  203. * Function prototypes
  204. */
  205. #include <poppack.h> /* End byte packing */
  206.