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.

176 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Abstract:
  4. @doc
  5. @module Query.hxx | Declarations used by the Software Snapshot Provider interface
  6. @end
  7. Author:
  8. Adi Oltean [aoltean] 09/15/1999
  9. Revision History:
  10. Name Date Comments
  11. aoltean 09/23/1999 Created.
  12. --*/
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Includes
  15. #include "stdafx.hxx"
  16. #include <winnt.h>
  17. #include "swprv.hxx"
  18. // Generated MIDL header
  19. #include "vss.h"
  20. #include "vscoordint.h"
  21. #include "vsswprv.h"
  22. #include "vsprov.h"
  23. #include "resource.h"
  24. #include "vs_inc.hxx"
  25. #include "ichannel.hxx"
  26. #include "copy.hxx"
  27. #include "pointer.hxx"
  28. #include "enum.hxx"
  29. #include "qsnap.hxx"
  30. #include "provider.hxx"
  31. #include "snapshot.hxx"
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Implementation
  34. STDMETHODIMP CVsTestProvider::Query(
  35. IN VSS_ID QueriedObjectId,
  36. IN VSS_OBJECT_TYPE eQueriedObjectType,
  37. IN VSS_OBJECT_TYPE eReturnedObjectsType,
  38. IN LONG lMask,
  39. OUT IVssEnumObject**ppEnum
  40. )
  41. {
  42. CVssFunctionTracer ft( VSSDBG_SWPRV, L"CVsTestProvider::Query" );
  43. try
  44. {
  45. // Initialize [out] arguments
  46. VssZeroOutPtr( ppEnum );
  47. ft.Trace( VSSDBG_SWPRV, L"Parameters: QueriedObjectId = " WSTR_GUID_FMT
  48. L"eQueriedObjectType = %d. eReturnedObjectsType = %d, lPropertiesMask = 0x%08lx, ppEnum = %p",
  49. GUID_PRINTF_ARG( QueriedObjectId ),
  50. eQueriedObjectType,
  51. eReturnedObjectsType,
  52. lMask,
  53. ppEnum);
  54. // Argument validation
  55. BS_ASSERT(ppEnum);
  56. if (ppEnum == NULL)
  57. ft.Throw( VSSDBG_SWPRV, E_INVALIDARG, L"NULL ppEnum");
  58. // Create the collection object. Initial reference count is 0.
  59. VSS_OBJECT_PROP_Array* pArray = new VSS_OBJECT_PROP_Array;
  60. if (pArray == NULL)
  61. ft.Throw( VSSDBG_SWPRV, E_OUTOFMEMORY, L"Memory allocation error.");
  62. // Get the pointer to the IUnknown interface.
  63. // The only purpose of this is to use a smart ptr to destroy correctly the array on error.
  64. // Now pArray's reference count becomes 1 (because of the smart pointer).
  65. CComPtr<IUnknown> pArrayItf = static_cast<IUnknown*>(pArray);
  66. BS_ASSERT(pArrayItf);
  67. // Establish the filtering
  68. CVssQueuedSnapshot::VSS_QUERY_TYPE eQueryType = CVssQueuedSnapshot::VSS_FIND_UNKNOWN;
  69. switch(eQueriedObjectType)
  70. {
  71. case VSS_OBJECT_SNAPSHOT_SET:
  72. eQueryType = CVssQueuedSnapshot::VSS_FIND_BY_SNAPSHOT_SET_ID;
  73. break;
  74. case VSS_OBJECT_SNAPSHOT:
  75. eQueryType = CVssQueuedSnapshot::VSS_FIND_BY_SNAPSHOT_ID;
  76. break;
  77. case VSS_OBJECT_VOLUME:
  78. eQueryType = CVssQueuedSnapshot::VSS_FIND_BY_VOLUME;
  79. break;
  80. case VSS_OBJECT_NONE:
  81. eQueryType = CVssQueuedSnapshot::VSS_FIND_ALL;
  82. break;
  83. default:
  84. ft.Throw( VSSDBG_SWPRV, E_INVALIDARG, L"Incompatible types %d/%d",
  85. eQueriedObjectType, eReturnedObjectsType);
  86. }
  87. // Fill now the collection
  88. switch(eReturnedObjectsType)
  89. {
  90. case VSS_OBJECT_SNAPSHOT_SET:
  91. case VSS_OBJECT_SNAPSHOT:
  92. case VSS_OBJECT_VOLUME:
  93. CVssQueuedSnapshot::EnumerateSnasphots(ft,
  94. eQueryType,
  95. eReturnedObjectsType,
  96. lMask,
  97. QueriedObjectId,
  98. pArray);
  99. break;
  100. default:
  101. ft.Throw( VSSDBG_SWPRV, E_INVALIDARG, L"Incompatible types %d/%d",
  102. eQueriedObjectType, eReturnedObjectsType);
  103. }
  104. // Create the enumerator object. Beware that its reference count will be zero.
  105. CComObject<CVssEnumFromArray>* pEnumObject = NULL;
  106. ft.hr = CComObject<CVssEnumFromArray>::CreateInstance(&pEnumObject);
  107. if (ft.HrFailed())
  108. ft.Throw( VSSDBG_SWPRV, E_OUTOFMEMORY,
  109. L"Cannot create enumerator instance. [0x%08lx]", ft.hr);
  110. BS_ASSERT(pEnumObject);
  111. // Get the pointer to the IVssEnumObject interface.
  112. // Now pEnumObject's reference count becomes 1 (because of the smart pointer).
  113. // So if a throw occurs the enumerator object will be safely destroyed by the smart ptr.
  114. CComPtr<IUnknown> pUnknown = pEnumObject->GetUnknown();
  115. BS_ASSERT(pUnknown);
  116. // Initialize the enumerator object.
  117. // The array's reference count becomes now 2, because IEnumOnSTLImpl::m_spUnk is also a smart ptr.
  118. BS_ASSERT(pArray);
  119. ft.hr = pEnumObject->Init(pArrayItf, *pArray);
  120. if (ft.HrFailed())
  121. ft.Throw( VSSDBG_SWPRV, E_UNEXPECTED,
  122. L"Cannot initialize enumerator instance. [0x%08lx]", ft.hr);
  123. // Initialize the enumerator object.
  124. // The enumerator reference count becomes now 2.
  125. ft.hr = pUnknown->SafeQI(IVssEnumObject, ppEnum);
  126. if ( ft.HrFailed() )
  127. ft.Throw( VSSDBG_SWPRV, E_UNEXPECTED,
  128. L"Error querying the IVssEnumObject interface. hr = 0x%08lx", ft.hr);
  129. BS_ASSERT(*ppEnum);
  130. BS_ASSERT( !ft.HrFailed() );
  131. ft.hr = (pArray->GetSize() != 0)? S_OK: S_FALSE;
  132. }
  133. VSS_STANDARD_CATCH(ft)
  134. return ft.hr;
  135. }