home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 May / MICD_2000_05.iso / CBuilder5 / INSTALL / DATA1.CAB / Program_Built_Files / Include / wbemglue.h < prev    next >
C/C++ Source or Header  |  2000-02-01  |  18KB  |  469 lines

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