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.

132 lines
4.5 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. PCH_PrintJob.CPP
  5. Abstract:
  6. WBEM provider class implementation for PCH_PrintJob 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_PrintJob.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_PRINTJOB
  24. CPCH_PrintJob MyPCH_PrintJobSet (PROVIDER_NAME_PCH_PRINTJOB, PCH_NAMESPACE) ;
  25. // Property names
  26. //===============
  27. const static WCHAR* pTimeStamp = L"TimeStamp" ;
  28. const static WCHAR* pChange = L"Change" ;
  29. const static WCHAR* pName = L"Name" ;
  30. const static WCHAR* pPagesPrinted = L"PagesPrinted" ;
  31. const static WCHAR* pSize = L"Size" ;
  32. const static WCHAR* pStatus = L"Status" ;
  33. const static WCHAR* pTimeSubmitted = L"TimeSubmitted" ;
  34. /*****************************************************************************
  35. *
  36. * FUNCTION : CPCH_PrintJob::EnumerateInstances
  37. *
  38. * DESCRIPTION : Returns all the instances of this class.
  39. *
  40. * INPUTS : A pointer to the MethodContext for communication with WinMgmt.
  41. * A long that contains the flags described in
  42. * IWbemServices::CreateInstanceEnumAsync. Note that the following
  43. * flags are handled by (and filtered out by) WinMgmt:
  44. * WBEM_FLAG_DEEP
  45. * WBEM_FLAG_SHALLOW
  46. * WBEM_FLAG_RETURN_IMMEDIATELY
  47. * WBEM_FLAG_FORWARD_ONLY
  48. * WBEM_FLAG_BIDIRECTIONAL
  49. *
  50. * RETURNS : WBEM_S_NO_ERROR if successful
  51. *
  52. * COMMENTS : TO DO: All instances on the machine should be returned here.
  53. * If there are no instances, return WBEM_S_NO_ERROR.
  54. * It is not an error to have no instances.
  55. *
  56. *****************************************************************************/
  57. HRESULT CPCH_PrintJob::EnumerateInstances(
  58. MethodContext* pMethodContext,
  59. long lFlags
  60. )
  61. {
  62. TraceFunctEnter("CPCH_PrintJob::EnumerateInstances");
  63. HRESULT hRes = WBEM_S_NO_ERROR;
  64. REFPTRCOLLECTION_POSITION posList;
  65. CComPtr<IEnumWbemClassObject> pEnumInst;
  66. IWbemClassObjectPtr pObj; // BUGBUG : WMI asserts if we use CComPtr
  67. ULONG ulRetVal;
  68. //
  69. // Get the date and time
  70. //
  71. SYSTEMTIME stUTCTime;
  72. GetSystemTime(&stUTCTime);
  73. //
  74. // Execute the query
  75. //
  76. // To fix Bug : 100551 , we need to read "jobstatus" instead of "status".
  77. hRes = ExecWQLQuery(&pEnumInst, CComBSTR("select Name, Size, JobStatus, TimeSubmitted, PagesPrinted from Win32_printJob"));
  78. if (FAILED(hRes))
  79. goto END;
  80. //
  81. // enumerate the instances from win32_CodecFile
  82. //
  83. while(WBEM_S_NO_ERROR == pEnumInst->Next(WBEM_INFINITE, 1, &pObj, &ulRetVal))
  84. {
  85. // Create a new instance based on the passed-in MethodContext
  86. CInstancePtr pInstance(CreateNewInstance(pMethodContext), false);
  87. CComVariant varValue;
  88. if (!pInstance->SetDateTime(pTimeStamp, WBEMTime(stUTCTime)))
  89. ErrorTrace(TRACE_ID, "SetDateTime on Timestamp Field failed.");
  90. if (!pInstance->SetCHString(pChange, L"Snapshot"))
  91. ErrorTrace(TRACE_ID, "SetCHString on Change Field failed.");
  92. (void)CopyProperty(pObj, L"Name", pInstance, pName);
  93. (void)CopyProperty(pObj, L"PagesPrinted", pInstance, pPagesPrinted);
  94. (void)CopyProperty(pObj, L"Size", pInstance, pSize);
  95. (void)CopyProperty(pObj, L"JobStatus", pInstance, pStatus);
  96. (void)CopyProperty(pObj, L"TimeSubmitted", pInstance, pTimeSubmitted);
  97. hRes = pInstance->Commit();
  98. if (FAILED(hRes))
  99. {
  100. // Could not Set the Change Property
  101. // Continue anyway
  102. ErrorTrace(TRACE_ID, "Set Variant on Name Field failed.");
  103. }
  104. }
  105. END :
  106. TraceFunctLeave();
  107. return hRes ;
  108. }