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.

171 lines
4.1 KiB

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