WbemGlue.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:20k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  4. //
  5. //  WBEMGLUE.H
  6. //
  7. //  Purpose: Implementation of WBEM Glue classes
  8. //
  9. //***************************************************************************
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #ifndef _WbemGlue_H_Included
  14. #define _WbemGlue_H_Included
  15. #undef PURE
  16. #define PURE {return (ULONG)E_NOTIMPL;}
  17. typedef LPVOID *PPVOID;
  18. #include <wbemidl.h>
  19. #include <map>
  20. #include <set>
  21. #include <provider.h>
  22. #define DEFAULT_NAMESPACE       L"Root\CimV2"
  23. typedef std::map<CHString, LPVOID> STRING2LPVOID;
  24. typedef std::map<LPCVOID, PLONG> PTR2PLONG;
  25. typedef std::set<LPVOID> PROVIDERPTRS;
  26. class CWbemGlueFactory;
  27. class CWbemGlueImpersonation;
  28. class POLARITY CWbemProviderGlue : public IWbemServices, public IWbemProviderInit
  29. {
  30. friend class CWbemGlueImpersonation;
  31. public:
  32.     // Public Static functions
  33.     // these are for use by implementors of Framework based providers
  34.     static HRESULT WINAPI GetAllInstances( LPCWSTR pszClassName, 
  35.                                            TRefPointerCollection<CInstance> *pList, 
  36.                                            LPCWSTR pszNamespace, 
  37.                                            MethodContext *pMethodContext );
  38.     static HRESULT WINAPI GetAllInstancesAsynch( LPCWSTR pszClassName, 
  39.                                                  Provider *pRequester, 
  40.                                                  LPProviderInstanceCallback pCallback, 
  41.                                                  LPCWSTR pszNamespace, 
  42.                                                  MethodContext *pMethodContext, 
  43.                                                  void *pUserData );
  44.     static HRESULT WINAPI GetAllDerivedInstancesAsynch( LPCWSTR pszBaseClassName, 
  45.                                                         Provider *pRequester, 
  46.                                                         LPProviderInstanceCallback pCallback, 
  47.                                                         LPCWSTR pszNamespace, 
  48.                                                         MethodContext *pMethodContext, 
  49.                                                         void *pUserData );
  50.     static HRESULT WINAPI GetAllDerivedInstances( LPCWSTR pszBaseClassName, 
  51.                                                   TRefPointerCollection<CInstance> *pList, 
  52.                                                   MethodContext *pMethodContext, 
  53. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  54.                                                   LPCWSTR pszNamespace = NULL);
  55. #else
  56.                                                   LPCWSTR pszNamespace);
  57. #endif
  58.     static HRESULT WINAPI GetInstanceByPath( LPCWSTR pszObjectPath, 
  59.                                              CInstance **ppInstance, 
  60. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  61.                                              MethodContext *pMethodContext = NULL );
  62. #else
  63.                                              MethodContext *pMethodContext);
  64. #endif
  65.     static HRESULT WINAPI GetInstanceKeysByPath( LPCWSTR pszInstancePath,
  66.                                                  CInstance **ppInstance,
  67.                                                  MethodContext *pMethodContext);
  68.     static HRESULT WINAPI GetInstancePropertiesByPath( LPCWSTR pszInstancePath,
  69.                                                  CInstance **ppInstance,
  70.                                                  MethodContext *pMethodContext,
  71.                                                  CHStringArray &csaProperties);
  72.     static HRESULT WINAPI GetInstancesByQuery( LPCWSTR query, 
  73.                                                TRefPointerCollection<CInstance> *pList, 
  74.                                                MethodContext *pMethodContext,  
  75. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  76.                                                LPCWSTR pszNamespace = NULL);
  77. #else
  78.                                                LPCWSTR pszNamespace);
  79. #endif
  80.     static HRESULT WINAPI GetInstancesByQueryAsynch( LPCWSTR query, 
  81.                                                      Provider *pRequester, 
  82.                                                      LPProviderInstanceCallback pCallback, 
  83.                                                      LPCWSTR pszNamespace, 
  84.                                                      MethodContext *pMethodContext, 
  85.                                                      void *pUserData );
  86. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  87.     // This version of GetEmptyInstance is deprecated.  Use the next one.
  88.     static HRESULT WINAPI GetEmptyInstance( LPCWSTR pszClassName, 
  89.                                             CInstance **ppInstance, 
  90.                                             LPCWSTR pszNamespace = NULL);
  91. #endif
  92.     static HRESULT WINAPI GetEmptyInstance( MethodContext *pMethodContext, 
  93.                                             LPCWSTR pszClassName, 
  94.                                             CInstance **ppInstance, 
  95. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  96.                                             LPCWSTR pszNamespace = NULL);
  97. #else
  98.                                             LPCWSTR pszNamespace);
  99. #endif
  100.     // Both of these FillInstance calls are deprecated.  Use GetInstanceByPath, or the even
  101.     // more performant functions GetInstanceKeysByPath or GetInstancePropertiesByPath.
  102. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  103.     static HRESULT WINAPI FillInstance( CInstance *pInstance, 
  104.                                         LPCWSTR pszNamespace = NULL );
  105.     static HRESULT WINAPI FillInstance( MethodContext *pMethodContext, 
  106.                                         CInstance *pInstance );
  107. #endif
  108.     // determine whether one class is derived from another
  109.     static bool  WINAPI IsDerivedFrom( LPCWSTR pszBaseClassName, 
  110.                                        LPCWSTR pszDerivedClassName, 
  111.                                        MethodContext *pMethodContext, 
  112. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  113.                                        LPCWSTR pszNamespace = NULL );
  114. #else
  115.                                        LPCWSTR pszNamespace);
  116. #endif
  117.     // logging in and out of framework
  118.     // each framework based DLL must log in and out with these functions
  119.      // Deprecated in favor of the version that takes a PLONG.
  120. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  121.     static BOOL WINAPI FrameworkLoginDLL(LPCWSTR name);
  122.     static BOOL WINAPI FrameworkLogoffDLL(LPCWSTR name);
  123. #endif
  124.     // You must pass the *same* PLONG to all three of FrameworkLoginDLL, 
  125.     // FrameworkLogoffDLL, and the CWbemGlueFactory constructor.
  126.     static BOOL WINAPI FrameworkLoginDLL(LPCWSTR name, PLONG plRefCount);
  127.     static BOOL WINAPI FrameworkLogoffDLL(LPCWSTR name, PLONG plRefCount);
  128.     static bool WINAPI SetStatusObject(MethodContext *pContext, LPCWSTR pNamespace, 
  129.                                         LPCWSTR pDescription, HRESULT hr, 
  130.                                         const SAFEARRAY *pPrivilegesNotHeld = NULL,
  131.                                         const SAFEARRAY *pPrivilegesRequired = NULL);
  132.     ////////////////////////////////////////////////////////////////////////////////////
  133.     // note: the following public functions are necessary to allow COM communication  //
  134.     //       with CIMOM.  Provider Implementors will not need to call these.          //
  135.     ////////////////////////////////////////////////////////////////////////////////////
  136. #ifndef NO_BASEINTERFACE_FUNCS
  137.     /* IUnknown methods */
  138.     STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR *ppvObj) ;
  139.     STDMETHOD_(ULONG, AddRef)(THIS) ;
  140.     STDMETHOD_(ULONG, Release)(THIS) ;
  141. #endif
  142.     
  143.    virtual HRESULT STDMETHODCALLTYPE Initialize( 
  144.             /* [in] */ LPWSTR pszUser,
  145.             /* [in] */ LONG lFlags,
  146.             /* [in] */ LPWSTR pszNamespace,
  147.             /* [in] */ LPWSTR pszLocale,
  148.             /* [in] */ IWbemServices __RPC_FAR *pNamespace,
  149.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  150.             /* [in] */ IWbemProviderInitSink __RPC_FAR *pInitSink
  151.     );
  152.     STDMETHOD(CreateInstanceEnumAsync)(THIS_
  153.             /* [in] */ const BSTR Class,
  154.             /* [in] */ long lFlags,
  155.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  156.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  157.     );
  158.     
  159.     STDMETHOD(GetObjectAsync)( THIS_
  160.             const BSTR ObjectPath, 
  161.             long lFlags, 
  162.             IWbemContext __RPC_FAR *pCtx, 
  163.             IWbemObjectSink __RPC_FAR *pResponseHandler
  164.     );
  165.     
  166.     STDMETHOD(ExecQueryAsync)(THIS_
  167.             /* [in] */ const BSTR QueryLanguage,
  168.             /* [in] */ const BSTR Query,
  169.             /* [in] */ long lFlags,
  170.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  171.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  172.     );
  173.     
  174.     STDMETHOD(PutInstanceAsync)( THIS_
  175.             /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  176.             /* [in] */ long lFlags,
  177.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  178.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  179.     );
  180.     
  181.     STDMETHOD(DeleteInstanceAsync)(
  182.             /* [in] */ const BSTR ObjectPath,
  183.             /* [in] */ long lFlags,
  184.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  185.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  186.     );
  187.     STDMETHOD(ExecMethodAsync)( const BSTR, 
  188.                                 const BSTR, 
  189.                                 long, 
  190.                                 IWbemContext*, 
  191.                                 IWbemClassObject*,
  192.                                 IWbemObjectSink*
  193.     );
  194.  // Unsupported service methods
  195.  // ===========================
  196.     STDMETHOD(OpenNamespace)(THIS_
  197.             const BSTR Namespace, 
  198.             long lFlags,  
  199.             IWbemContext __RPC_FAR *pCtx,
  200.             IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace, 
  201.             IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult
  202.     )
  203.         { return E_NOTIMPL; }
  204.     
  205.     STDMETHOD(PutClass)(IWbemClassObject __RPC_FAR *pObject, 
  206.                         long lFlags, 
  207.                         IWbemContext __RPC_FAR *pCtx, 
  208.                         IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  209.     )
  210.          {return E_NOTIMPL;}
  211.     STDMETHOD(PutClassAsync)( 
  212.             /* [in] */ IWbemClassObject __RPC_FAR *pObject,
  213.             /* [in] */ long lFlags,
  214.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  215.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  216.     )
  217.          {return E_NOTIMPL;}
  218.     STDMETHOD(DeleteClass)(  
  219.             /* [in] */ const BSTR Class,
  220.             /* [in] */ long lFlags,
  221.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  222.             /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  223.     )
  224.          {return E_NOTIMPL;}
  225.     STDMETHOD(DeleteClassAsync)( 
  226.             /* [in] */ const BSTR Class,
  227.             /* [in] */ long lFlags,
  228.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  229.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  230.     )
  231.          {return E_NOTIMPL;}
  232.     STDMETHOD(CreateClassEnum)(
  233.             /* [in] */ const BSTR Superclass,
  234.             /* [in] */ long lFlags,
  235.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  236.             /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  237.     )
  238.          {return E_NOTIMPL;}
  239.     STDMETHOD(CreateClassEnumAsync)(
  240.             /* [in] */ const BSTR Superclass,
  241.             /* [in] */ long lFlags,
  242.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  243.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  244.     )
  245.          {return E_NOTIMPL;}
  246.     STDMETHOD(PutInstance)(
  247.             /* [in] */ IWbemClassObject __RPC_FAR *pInst,
  248.             /* [in] */ long lFlags,
  249.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  250.             /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  251.     )
  252.          {return E_NOTIMPL;}
  253.     STDMETHOD(DeleteInstance)(
  254.             /* [in] */ const BSTR ObjectPath,
  255.             /* [in] */ long lFlags,
  256.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  257.             /* [unique][in][out] */ IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  258.     )
  259.          {return E_NOTIMPL;}
  260.     STDMETHOD(CancelAsyncRequest)(THIS_ long lAsyncRequestHandle
  261.     )
  262.          {return E_NOTIMPL;}
  263.     STDMETHOD(CancelAsyncCall)(IWbemObjectSink __RPC_FAR *pSink
  264.     )
  265.          {return E_NOTIMPL;}
  266.     STDMETHOD(CreateInstanceEnum)(
  267.             /* [in] */ const BSTR Class,
  268.             /* [in] */ long lFlags,
  269.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  270.             /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  271.     )
  272.          {return E_NOTIMPL;}
  273.   
  274.     STDMETHOD(ExecQuery)(
  275.             /* [in] */ const BSTR QueryLanguage,
  276.             /* [in] */ const BSTR Query,
  277.             /* [in] */ long lFlags,
  278.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  279.             /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  280.     )
  281.          {return E_NOTIMPL;}
  282.     STDMETHOD(QueryObjectSink)(long lFlags, 
  283.                                IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler
  284.     )
  285.          {return E_NOTIMPL;}
  286.     STDMETHOD(GetObject)( const BSTR ObjectPath, 
  287.                           long lFlags, 
  288.                           IWbemContext __RPC_FAR *pCtx, 
  289.                           IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject, 
  290.                           IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  291.     )
  292.          {return E_NOTIMPL;}
  293.     STDMETHOD(ExecNotificationQuery)( 
  294.             /* [in] */ const BSTR QueryLanguage,
  295.             /* [in] */ const BSTR Query,
  296.             /* [in] */ long lFlags,
  297.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  298.             /* [out] */ IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  299.     )
  300.        {return E_NOTIMPL;}
  301.         
  302.         
  303.     STDMETHOD(ExecNotificationQueryAsync)( 
  304.             /* [in] */ const BSTR QueryLanguage,
  305.             /* [in] */ const BSTR Query,
  306.             /* [in] */ long lFlags,
  307.             /* [in] */ IWbemContext __RPC_FAR *pCtx,
  308.             /* [in] */ IWbemObjectSink __RPC_FAR *pResponseHandler
  309.     )
  310.        {return E_NOTIMPL;}
  311.         
  312.     STDMETHOD(ExecMethod)(const BSTR, 
  313.                           const BSTR, 
  314.                           long, 
  315.                           IWbemContext*, 
  316.                           IWbemClassObject*,
  317.                           IWbemClassObject**, 
  318.                           IWbemCallResult**
  319.     )
  320.        {return E_NOTIMPL;}
  321.     CWbemProviderGlue();
  322.     CWbemProviderGlue(PLONG pCount);
  323.     ~CWbemProviderGlue(); // Destructor
  324.     // used by the provider base class - you probably will never need to call this directly
  325.     static IWbemServices *WINAPI GetNamespaceConnection( LPCWSTR NameSpace );
  326.     static IWbemServices *WINAPI GetNamespaceConnection( LPCWSTR NameSpace, MethodContext *pMethodContext );
  327.     // each provider class must log in and out with these in their constructors and destructors
  328.     // this is done for you in the Provider base class
  329.     static void WINAPI FrameworkLogin( LPCWSTR a_pszName, 
  330.                                        Provider *a_pProvider, 
  331.                                        LPCWSTR a_pszNameSpace );
  332.     static void WINAPI FrameworkLogoff( LPCWSTR a_pszName, 
  333.                                         LPCWSTR a_pszNameSpace );
  334.     static void WINAPI IncrementObjectCount(void);
  335.     static LONG WINAPI DecrementObjectCount(void);
  336.     static DWORD WINAPI GetOSMajorVersion() { return s_dwMajorVersion; }
  337.     static DWORD WINAPI GetPlatform() { return s_dwPlatform; }
  338.     static LPCWSTR WINAPI GetCSDVersion() { return s_wstrCSDVersion; }
  339.  private:
  340.     IWbemServices *WINAPI InternalGetNamespaceConnection( LPCWSTR NameSpace );
  341.     static HRESULT WINAPI GetInstanceFromCIMOM( LPCWSTR pszObjectPath,
  342.                                         LPCWSTR pszNameSpace,
  343.                                         MethodContext *pMethodContext,
  344.                                         CInstance **ppInstance );   
  345.     void FlushAll(void);
  346.     static Provider *WINAPI SearchMapForProvider( LPCWSTR a_pszProviderName, 
  347.                                                   LPCWSTR a_pszNamespace );
  348.     static Provider *WINAPI AddProviderToMap( LPCWSTR a_pszProviderName, 
  349.                                               LPCWSTR a_strNamespace, 
  350.                                               Provider *a_pProvider );
  351.     static void WINAPI LockProviderMap( void );
  352.     static void WINAPI UnlockProviderMap( void );
  353.     static void WINAPI LockFactoryMap( void );
  354.     static void WINAPI UnlockFactoryMap( void );
  355.     static IWbemClassObject *WINAPI GetStatusObject( MethodContext *pContext, 
  356.                                                      LPCWSTR pNamespace);
  357.     static void WINAPI Init( void );
  358.     static void WINAPI UnInit( void );
  359.     static void WINAPI GetComputerName( CHString& strComputerName );
  360.     
  361.     static HRESULT WINAPI CheckImpersonationLevel();
  362.     HRESULT PreProcessPutInstanceParms(IWbemClassObject __RPC_FAR *pInstIn, 
  363.                                        IWbemClassObject __RPC_FAR **pInstOut, 
  364.                                        IWbemContext __RPC_FAR *pCtx);    
  365.     HRESULT NullOutUnsetProperties(IWbemClassObject __RPC_FAR *pInstIn, 
  366.                                    IWbemClassObject __RPC_FAR **pInstOut, 
  367.                                    const VARIANT& vValue);
  368.     void AddFlushPtr(LPVOID pVoid);
  369.     long    m_lRefCount; 
  370.     CHString    m_strNamespace;
  371.     IWbemServices *m_pServices;
  372.     static long s_lObjects; // number of objects out there - class factories & WbemGlues
  373.     PLONG m_pCount;
  374.     PROVIDERPTRS m_FlushPtrs;
  375.     CCritSec         m_csFlushPtrs;
  376.     static STRING2LPVOID    s_providersmap;
  377.     static CCritSec s_csProviderMap;
  378.     static CCritSec m_csStatusObject;
  379.     static BOOL s_bInitted;
  380.     static DWORD s_dwPlatform;
  381.     static DWORD s_dwMajorVersion;
  382.     static WCHAR s_wstrCSDVersion[128];
  383.     static IWbemClassObject *m_pStatusObject;
  384.     static PTR2PLONG        s_factorymap;
  385.     static CCritSec         s_csFactoryMap;
  386. protected:
  387.     friend CWbemGlueFactory;
  388.     static LONG IncrementMapCount(const CWbemGlueFactory *pGlue);
  389.     static LONG IncrementMapCount(PLONG pCount);
  390.     static LONG DecrementMapCount(const CWbemGlueFactory *pGlue);
  391.     static LONG DecrementMapCount(PLONG pCount);
  392.     static PLONG GetMapCountPtr(const CWbemGlueFactory *pGlue);
  393.     static VOID AddToFactoryMap(const CWbemGlueFactory *pGlue, PLONG pdwRefCount);
  394.     static VOID RemoveFromFactoryMap(const CWbemGlueFactory *pGlue);
  395. };
  396. inline void CWbemProviderGlue::LockProviderMap( void )
  397. {
  398.     EnterCriticalSection( &s_csProviderMap );
  399. }
  400. inline void CWbemProviderGlue::UnlockProviderMap( void )
  401. {
  402.     LeaveCriticalSection( &s_csProviderMap );
  403. }
  404. inline void CWbemProviderGlue::LockFactoryMap( void )
  405. {
  406.     EnterCriticalSection( &s_csFactoryMap );
  407. }
  408. inline void CWbemProviderGlue::UnlockFactoryMap( void )
  409. {
  410.     LeaveCriticalSection( &s_csFactoryMap );
  411. }
  412. class POLARITY CWbemGlueFactory : public IClassFactory
  413. {
  414.  protected:
  415.     long m_lRefCount;
  416.  public:
  417.      // Deprecated in favor of the constructor that takes a PLONG.  This
  418.      // must be the same PLONG that is passed to FrameworkLoginDLL &
  419.      // FrameworkLogoffDLL.
  420. #ifdef FRAMEWORK_ALLOW_DEPRECATED
  421.         CWbemGlueFactory(void);
  422. #endif
  423.         CWbemGlueFactory(PLONG plRefCount);
  424.         ~CWbemGlueFactory(void);
  425.         //IUnknown members
  426.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  427.         STDMETHODIMP_(ULONG) AddRef(void);
  428.         STDMETHODIMP_(ULONG) Release(void);
  429.         //IClassFactory members
  430.         STDMETHODIMP         CreateInstance(LPUNKNOWN, REFIID, PPVOID);
  431.         STDMETHODIMP         LockServer(BOOL);
  432.     };
  433. typedef CWbemGlueFactory *PCWbemGlueFactory;
  434. #endif