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.

126 lines
4.4 KiB

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