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.

174 lines
6.2 KiB

  1. // GenericClass.h: interface for the CGenericClass class.
  2. // Copyright (c)1997-1999 Microsoft Corporation
  3. //
  4. //////////////////////////////////////////////////////////////////////
  5. #if !defined(AFX_GENERICCLASS_H__BD7570F7_9F0E_4C6B_B525_E078691B6D0E__INCLUDED_)
  6. #define AFX_GENERICCLASS_H__BD7570F7_9F0E_4C6B_B525_E078691B6D0E__INCLUDED_
  7. #if _MSC_VER >= 1000
  8. #pragma once
  9. #endif // _MSC_VER >= 1000
  10. #include <ntsecapi.h>
  11. #include <secedit.h>
  12. //#include "sceprov.h"
  13. const AREA_INFORMATION AreaBogus = 0x80000000L;
  14. //
  15. // forward declarations of the classes used in the parameters of the functions
  16. //
  17. class CScePropertyMgr;
  18. class CSceStore;
  19. /*
  20. Class description
  21. Naming:
  22. CGenericClass. This is the base class implementation for for all SCE's WMI classes.
  23. Base class:
  24. None
  25. Purpose of class:
  26. (1) defines the interface for CRequestObject class to respond to all WMI access to our
  27. provider. Our provider architecture is pretty much a delegation the WMI request to
  28. CRequestObject, where the request is translated into a particular class's function
  29. call. The CRequestObject uses the WMI class name information to create the
  30. appropriate C++ classes who all share this CGenericClass's interface (the set of
  31. virtual functions defined in this class). So this class pretty much is what
  32. CRequestObject uses to fulfill the the provider's request.
  33. Design:
  34. (1) To satisfy PutInstance request, it has a PutInst pure virtual function.
  35. (2) To satisfy GetInstance/QueryInstance/DeleteInstance/EnumerateInstance request,
  36. it has a CreateObject pure virtual function. The parameter atAction tells apart
  37. what is truly being requested. This was closely tied to the legacy INF persistence
  38. model where every Get/Query/Del/Enum action is really being done in the same
  39. fashion. Since it works, we opt to keep it this way for the time being.
  40. (3) To facilitate a uniform clean up, it has a CleanUp virtual function.
  41. (4) To satisfy ExecMethod request for those classes that support method execution, it
  42. has a ExecMethod function.
  43. (5) To ease the creation of a blank instance that can be used to fill in properties,
  44. We have a function SpawnAnInstance. m_srpClassForSpawning is the object pointer
  45. that can be used repeatedly to spawn. This will have a performance gain for cases
  46. where a lot number of instances needs to be spawned.
  47. (6) We cache the namespace this object belongs to by m_srpNamespace.
  48. (7) We cache the IWbemContext pointer by m_srpCtx. WMI is not clear about this pointer
  49. yet. But it says that we should expect WMI to require this pointer in many of their
  50. API's (which currently can happily take a NULL).
  51. (8) We cache all parsed information into m_srpKeyChain. Since all WMI request comes into
  52. our provider in the form of some text that must be interpreted, we must have parsed
  53. WMI requests before the request is translated into a per-class function call. All
  54. these parsing results are encapulated by ISceKeyChain.
  55. Use:
  56. (1) Derive your class from this class.
  57. (2) Implement those pure virtual functions.
  58. (3) If you have a particular need for clean up, override the CleanUp function and at the end
  59. of your override, call the base class version as well.
  60. (4) If you need to implement method execution, override ExecMethod function to your desire.
  61. Don't forget to register a method for the WMI class inside the MOF file (see Sce_Operation)
  62. for example.
  63. (5) In CRequestObject::CreateClass, put an entry for your class.
  64. Once you have done all the above steps, you have implemented all necessary steps for a new
  65. WMI class for this provider. Don't forget to update your MOF and compile the mof file.
  66. */
  67. class CGenericClass
  68. {
  69. public:
  70. CGenericClass (
  71. ISceKeyChain *pKeyChain,
  72. IWbemServices *pNamespace,
  73. IWbemContext *pCtx = NULL
  74. );
  75. virtual ~CGenericClass();
  76. //
  77. // Pure virtual. sub-class must implement this function to be concreate.
  78. //
  79. virtual HRESULT PutInst (
  80. IWbemClassObject *pInst,
  81. IWbemObjectSink *pHandler,
  82. IWbemContext *pCtx
  83. ) = 0;
  84. //
  85. // Pure virtual. sub-class must implement this function to be concreate.
  86. //
  87. virtual HRESULT CreateObject (
  88. IWbemObjectSink *pHandler,
  89. ACTIONTYPE atAction
  90. ) = 0;
  91. //
  92. // virtual. sub-class may override this function to be support method execution.
  93. //
  94. virtual HRESULT ExecMethod (
  95. BSTR bstrPath,
  96. BSTR bstrMethod,
  97. bool bIsInstance,
  98. IWbemClassObject *pInParams,
  99. IWbemObjectSink *pHandler,
  100. IWbemContext *pCtx
  101. )
  102. {
  103. return WBEM_E_NOT_SUPPORTED;
  104. }
  105. virtual void CleanUp ();
  106. protected:
  107. HRESULT SpawnAnInstance (
  108. IWbemClassObject **pObj
  109. );
  110. CComPtr<IWbemServices> m_srpNamespace;
  111. CComPtr<IWbemClassObject> m_srpClassForSpawning;
  112. CComPtr<IWbemContext> m_srpCtx;
  113. CComPtr<ISceKeyChain> m_srpKeyChain;
  114. };
  115. //
  116. // Translate SCE status into DOS errors
  117. //
  118. DWORD
  119. ProvSceStatusToDosError(
  120. IN SCESTATUS SceStatus
  121. );
  122. //
  123. // Translate DOS errors into HRESULT
  124. //
  125. HRESULT
  126. ProvDosErrorToWbemError(
  127. IN DWORD rc
  128. );
  129. #endif // !defined(AFX_GENERICCLASS_H__F370C612_D96E_11D1_8B5D_00A0C9954921__INCLUDED_)