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.

171 lines
4.3 KiB

  1. #pragma once
  2. #include "nmbase.h"
  3. #include "nmres.h"
  4. #include "nceh.h"
  5. //
  6. // The queue item structure. The device instance id of the queue item
  7. // will follow the actual structure (i.e. string start =
  8. // beginning of structure + size of structure.)
  9. //
  10. struct NCQUEUE_ITEM
  11. {
  12. DWORD cbSize;
  13. NC_INSTALL_TYPE eType;
  14. GUID ClassGuid;
  15. GUID InstanceGuid;
  16. DWORD dwCharacter;
  17. DWORD dwDeipFlags;
  18. union
  19. {
  20. DWORD cchPnpId;
  21. PWSTR pszPnpId;
  22. };
  23. union
  24. {
  25. DWORD cchInfId;
  26. PWSTR pszInfId;
  27. };
  28. };
  29. class ATL_NO_VTABLE CInstallQueue :
  30. public CComObjectRootEx <CComMultiThreadModel>,
  31. public CComCoClass <CInstallQueue, &CLSID_InstallQueue>,
  32. public INetInstallQueue
  33. {
  34. public:
  35. CInstallQueue() throw (SE_Exception);
  36. VOID FinalRelease ();
  37. DECLARE_CLASSFACTORY_DEFERRED_SINGLETON(CInstallQueue)
  38. DECLARE_REGISTRY_RESOURCEID(IDR_INSTALLQUEUE)
  39. BEGIN_COM_MAP(CInstallQueue)
  40. COM_INTERFACE_ENTRY(INetInstallQueue)
  41. END_COM_MAP()
  42. // INetInstallQueue
  43. STDMETHOD (AddItem) (
  44. IN const NIQ_INFO* pInfo);
  45. STDMETHOD (ProcessItems) ()
  46. {
  47. return HrQueueWorkItem();
  48. };
  49. VOID Close();
  50. HRESULT HrOpen();
  51. HRESULT HrGetNextItem(NCQUEUE_ITEM** ppncqi);
  52. HRESULT HrRefresh();
  53. VOID MarkCurrentItemForDeletion();
  54. protected:
  55. CRITICAL_SECTION m_csReadLock;
  56. CRITICAL_SECTION m_csWriteLock;
  57. DWORD m_dwNextAvailableIndex;
  58. HKEY m_hkey;
  59. INT m_nCurrentIndex;
  60. DWORD m_cItems;
  61. PWSTR* m_aszItems;
  62. DWORD m_cItemsToDelete;
  63. PWSTR* m_aszItemsToDelete;
  64. BOOL m_fQueueIsOpen;
  65. DWORD DwSizeOfItem(NCQUEUE_ITEM* pncqi);
  66. VOID DeleteMarkedItems();
  67. BOOL FIsQueueIndexInRange();
  68. VOID FreeAszItems();
  69. HRESULT HrAddItem(
  70. const NIQ_INFO* pInfo);
  71. NCQUEUE_ITEM* PncqiCreateItem(
  72. const NIQ_INFO* pInfo);
  73. VOID SetNextAvailableIndex();
  74. VOID SetItemStringPtrs(NCQUEUE_ITEM* pncqi);
  75. HRESULT HrQueueWorkItem();
  76. };
  77. //+---------------------------------------------------------------------------
  78. //
  79. // Function: DwSizeOfItem
  80. //
  81. // Purpose: Determines the size (in bytes) of the entire NCQUEUE_ITEM
  82. // structure. This includes the string (and the NULL terminator)
  83. // appended to the end of the structure.
  84. //
  85. // Arguments:
  86. // ncqi [in] The queue item.
  87. //
  88. // Returns: DWORD. The size in bytes.
  89. //
  90. // Author: billbe 25 Aug 1998
  91. //
  92. // Notes:
  93. //
  94. inline DWORD
  95. CInstallQueue::DwSizeOfItem (NCQUEUE_ITEM* pncqi)
  96. {
  97. AssertH(pncqi);
  98. PWSTR pszDeviceInstanceId = (PWSTR)((BYTE*)pncqi + pncqi->cbSize);
  99. DWORD cbDeviceInstanceId = CbOfSzAndTerm (pszDeviceInstanceId);
  100. PWSTR pszInfId = (PWSTR)((BYTE*)pszDeviceInstanceId + cbDeviceInstanceId);
  101. return pncqi->cbSize + cbDeviceInstanceId + CbOfSzAndTerm (pszInfId);
  102. };
  103. //+---------------------------------------------------------------------------
  104. //
  105. // Function: SetItemStringPtrs
  106. //
  107. // Purpose: Sets the pszwDeviceInstanceId member of the NCQUEUE_ITEM
  108. // structure to the correct location of the device id string.
  109. //
  110. // Arguments:
  111. // pncqi [inout] The queue item.
  112. //
  113. // Returns: nothing
  114. //
  115. // Author: billbe 25 Aug 1998
  116. //
  117. // Notes:
  118. //
  119. inline VOID
  120. CInstallQueue::SetItemStringPtrs (
  121. NCQUEUE_ITEM* pncqi)
  122. {
  123. AssertH(pncqi);
  124. pncqi->pszPnpId = (PWSTR)((BYTE*)pncqi + pncqi->cbSize);
  125. DWORD cbPnpId = CbOfSzAndTerm (pncqi->pszPnpId);
  126. pncqi->pszInfId = (PWSTR)((BYTE*)pncqi->pszPnpId + cbPnpId);
  127. };
  128. inline BOOL
  129. CInstallQueue::FIsQueueIndexInRange()
  130. {
  131. return (m_nCurrentIndex >= 0) && (m_nCurrentIndex < (INT)m_cItems);
  132. }
  133. inline void
  134. CInstallQueue::FreeAszItems()
  135. {
  136. for (DWORD dw = 0; dw < m_cItems; ++dw)
  137. {
  138. MemFree(m_aszItems[dw]);
  139. }
  140. MemFree(m_aszItems);
  141. m_aszItems = NULL;
  142. m_cItems = 0;
  143. }
  144. VOID
  145. WaitForInstallQueueToExit();