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.

134 lines
4.8 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_CDROM.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_CDROM class
  7. Revision History:
  8. Ghim-Sim Chua (gschua) 04/27/99
  9. - Created
  10. Ghim-Sim Chua (gschua) 05/02/99
  11. - Modified code to use CopyProperty function
  12. - Use CComBSTR instead of USES_CONVERSION
  13. ********************************************************************/
  14. #include "pchealth.h"
  15. #include "PCH_CDROM.h"
  16. /////////////////////////////////////////////////////////////////////////////
  17. // tracing stuff
  18. #ifdef THIS_FILE
  19. #undef THIS_FILE
  20. #endif
  21. static char __szTraceSourceFile[] = __FILE__;
  22. #define THIS_FILE __szTraceSourceFile
  23. #define TRACE_ID DCID_CDROM
  24. CPCH_CDROM MyPCH_CDROMSet (PROVIDER_NAME_PCH_CDROM, PCH_NAMESPACE) ;
  25. // Property names
  26. //===============
  27. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  28. const static WCHAR* pChange = L"Change" ;
  29. const static WCHAR* pDataTransferIntegrity = L"DataTransferIntegrity" ;
  30. const static WCHAR* pDescription = L"Description" ;
  31. const static WCHAR* pDeviceID = L"DeviceID" ;
  32. const static WCHAR* pDriveLetter = L"DriveLetter" ;
  33. const static WCHAR* pManufacturer = L"Manufacturer" ;
  34. const static WCHAR* pSCSITargetID = L"SCSITargetID" ;
  35. const static WCHAR* pTransferRateKBS = L"TransferRateKBS" ;
  36. const static WCHAR* pVolumeName = L"VolumeName" ;
  37. /*****************************************************************************
  38. *
  39. * FUNCTION : CPCH_CDROM::EnumerateInstances
  40. *
  41. * DESCRIPTION : Returns all the instances of this class.
  42. *
  43. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  44. * A long that contains the flags described in
  45. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  46. * flags are handled by (and filtered out by) WinMgmt:
  47. * WBEM_FLAG_DEEP
  48. * WBEM_FLAG_SHALLOW
  49. * WBEM_FLAG_RETURN_IMMEDIATELY
  50. * WBEM_FLAG_FORWARD_ONLY
  51. * WBEM_FLAG_BIDIRECTIONAL
  52. *
  53. * RETURNS : WBEM_S_NO_ERROR if successful
  54. *
  55. * COMMENTS : TO DO: All instances on the machine should be returned here.
  56. * If there are no instances, return WBEM_S_NO_ERROR.
  57. * It is not an error to have no instances.
  58. *
  59. *****************************************************************************/
  60. HRESULT
  61. CPCH_CDROM::EnumerateInstances(
  62. MethodContext* pMethodContext,
  63. long lFlags
  64. )
  65. {
  66. TraceFunctEnter("CPCH_CDROM::EnumerateInstances");
  67. HRESULT hRes = WBEM_S_NO_ERROR;
  68. REFPTRCOLLECTION_POSITION posList;
  69. CComPtr<IEnumWbemClassObject> pEnumInst;
  70. IWbemClassObjectPtr pObj;
  71. ULONG ulRetVal;
  72. //
  73. // Get the date and time
  74. //
  75. SYSTEMTIME stUTCTime;
  76. GetSystemTime(&stUTCTime);
  77. //
  78. // Execute the query
  79. //
  80. hRes = ExecWQLQuery(&pEnumInst, CComBSTR("SELECT DeviceID, Drive, VolumeName, TransferRate, DriveIntegrity, Description, SCSITargetId, Manufacturer FROM Win32_CDROMDrive"));
  81. if (FAILED(hRes))
  82. goto END;
  83. //
  84. // enumerate the instances from win32_CodecFile
  85. //
  86. while (WBEM_S_NO_ERROR == pEnumInst->Next(WBEM_INFINITE, 1, &pObj, &ulRetVal))
  87. {
  88. // Create a new instance based on the passed-in MethodContext. If this fails,
  89. // we don't need to check for a null pointer because it throws an exception.
  90. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  91. CComVariant varValue;
  92. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  93. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  94. if (!pInstance->SetCHString(pChange, L"Snapshot"))
  95. ErrorTrace(TRACE_ID, "SetCHString on Change Field failed.");
  96. (void)CopyProperty(pObj, L"DriveIntegrity", pInstance, pDataTransferIntegrity);
  97. (void)CopyProperty(pObj, L"Description", pInstance, pDescription);
  98. (void)CopyProperty(pObj, L"DeviceID", pInstance, pDeviceID);
  99. (void)CopyProperty(pObj, L"Drive", pInstance, pDriveLetter);
  100. (void)CopyProperty(pObj, L"Manufacturer", pInstance, pManufacturer);
  101. (void)CopyProperty(pObj, L"SCSITargetId", pInstance, pSCSITargetID);
  102. (void)CopyProperty(pObj, L"TransferRate", pInstance, pTransferRateKBS);
  103. (void)CopyProperty(pObj, L"VolumeName", pInstance, pVolumeName);
  104. hRes = pInstance->Commit();
  105. if (FAILED(hRes))
  106. ErrorTrace(TRACE_ID, "Commit on Instance failed.");
  107. }
  108. END :
  109. TraceFunctLeave();
  110. return hRes ;
  111. }