home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / provider.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  7.9 KB  |  187 lines

  1. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  2. //***************************************************************************
  3. //
  4. //  Copyright (c) 1997-1999 Microsoft Corporation
  5. //
  6. //  Provider.h
  7. //
  8. //  Purpose: declaration of Provider class
  9. //
  10. //***************************************************************************
  11.  
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15.  
  16. #ifndef _PROVIDER_H__
  17. #define _PROVIDER_H__
  18.  
  19. /////////////////////////////////////////////////////
  20. // INSTANCE Provider
  21. //
  22. // pure virtual base class for providers
  23. // holds instances
  24. // gathers information and instantiates instances
  25. /////////////////////////////////////////////////////
  26. class POLARITY Provider : public CThreadBase
  27. {
  28.     // CWbemProviderGlue needs to access some protected/private methods
  29.     // which we don't want to publish to just anyone.
  30.  
  31.     friend class CWbemProviderGlue;
  32.  
  33.     public:
  34.         Provider( LPCWSTR a_pszName, LPCWSTR a_pszNameSpace = NULL );
  35.         ~Provider();
  36.  
  37.     protected:
  38.         /* Override These Methods To Implement Your Provider */
  39.         
  40.         // This is the entrypoint for changes.
  41.         // You are handed a changed instance.
  42.         // If you can make the changes - do so.
  43.         // If you cannot return an appropriate error code (WBEM_E_XXXXXXX)
  44.         // base object returns WBEM_E_PROVIDER_NOT_CAPABLE
  45.         virtual HRESULT PutInstance(const CInstance& newInstance, long lFlags = 0L);
  46.  
  47.         // entrypoint to delete an instance
  48.         // examine the instance passed in, determine whether you can delete it
  49.         virtual HRESULT DeleteInstance(const CInstance& newInstance, long lFlags = 0L);
  50.  
  51.         // execute a method
  52.         virtual HRESULT ExecMethod(const CInstance& cInstance, 
  53.                                    const BSTR bstrMethodName, 
  54.                                    CInstance *pInParams, 
  55.                                    CInstance *pOutParams, 
  56.                                    long lFlags = 0L);
  57.  
  58.         // find and create all instances of your class
  59.         virtual HRESULT EnumerateInstances(MethodContext *pMethodContext, long lFlags = 0L);
  60.  
  61.         // you will be given an object with the key properties filled in
  62.         // you need to fill in all of the rest of the properties, or
  63.         // return WBEM_E_NOT_FOUND if the object doesn't exist.
  64.         virtual HRESULT GetObject(CInstance *pInstance, long lFlags = 0L);
  65.  
  66.         // You will be given an object with the key properties filled in.
  67.         // You can either fill in all the properties, or check the Query object
  68.         // to see what properties are required.  If you don't implement this method, the
  69.         // GetObject(CInstance, long) method will be called instead.
  70.         virtual HRESULT GetObject(CInstance *pInstance, long lFlags, CFrameworkQuery &Query);
  71.  
  72.         // If a provider wants to process queries, they should override this
  73.         virtual HRESULT ExecQuery(MethodContext *pMethodContext, 
  74.                                   CFrameworkQuery& cQuery, 
  75.                                   long lFlags = 0L);
  76.  
  77.         // flushes cache
  78.         // only override if you allocate memory that could be flushed
  79.         virtual void Flush(void);
  80.  
  81.         /* Helpers - Use These, Do Not Override */
  82.  
  83.         // allocate a new instance & return pointer to it
  84.         // the memory is your responsibility to Release()
  85.         // UNLESS you pass it off to Provider::Commit
  86.         CInstance *CreateNewInstance(MethodContext *pMethodContext);
  87.  
  88.         // used to send your new instance back to the framework
  89.         // set bCache to true to cache object 
  90.         // !! caching is NOT IMPLEMENTED in this release !!
  91.         // do not delete or release the pointer once committed.
  92.         HRESULT Commit(CInstance *pInstance, bool bCache = false);
  93.  
  94.         // Helper function for building a WBEM Object Path for a local Instance
  95.         bool GetLocalInstancePath( const CInstance *pInstance, CHString& strPath );
  96.  
  97.         //   Builds a full instance path from a relative path
  98.         CHString MakeLocalPath( const CHString &strRelPath );
  99.  
  100.         // Returns the computer name as a CHString.  Save yourself the os call,
  101.         // since we've got it hanging around anyway.
  102.         const CHString &GetLocalComputerName() {return s_strComputerName;}
  103.         const CHString &GetNamespace() {return m_strNameSpace;}
  104.  
  105.         // sets the CreationClassName property to the name of this provider
  106.         bool SetCreationClassName(CInstance *pInstance);
  107.  
  108.         // accesses the name of the provider
  109.         const CHString &GetProviderName() {return m_name;}
  110.  
  111.         // Flag validation constants
  112.         enum FlagDefs
  113.         {
  114.             EnumerationFlags = 0,
  115.             GetObjFlags = 0,
  116.             MethodFlags = 0,
  117.             DeletionFlags = 0,
  118.             PutInstanceFlags = (WBEM_FLAG_CREATE_ONLY | WBEM_FLAG_CREATE_OR_UPDATE | WBEM_FLAG_UPDATE_ONLY),
  119.             QueryFlags = 0
  120.         };
  121.  
  122.         // returns WBEM_E_UNSUPPORTED_PARAMETER or WBEM_S_NO_ERROR
  123.         HRESULT ValidateFlags(long lFlags, FlagDefs lAcceptableFlags);
  124.  
  125.         // you can override the following to support flags 
  126.         // above and beyond those listed in FlagDefs above
  127.         virtual HRESULT ValidateEnumerationFlags(long lFlags);
  128.         virtual HRESULT ValidateGetObjFlags(long lFlags);
  129.         virtual HRESULT ValidateMethodFlags(long lFlags);
  130.         virtual HRESULT ValidateQueryFlags(long lFlags);
  131.         virtual HRESULT ValidateDeletionFlags(long lFlags);
  132.         virtual HRESULT ValidatePutInstanceFlags(long lFlags);
  133.         
  134.     private:
  135.  
  136.         IWbemServices       *m_pIMosProvider;    // provides instances
  137.         CHString            m_name;             // name of this provider
  138.         CHString            m_strNameSpace;     // name of this provider's namespace
  139.         IWbemClassObject    *m_piClassObject;    // holds class object from which others are cloned.
  140.  
  141.         static CHString     s_strComputerName;  // Holds the computer name for building
  142.                                                 // instance paths.
  143.         
  144.         BOOL ValidateIMOSPointer( void );       // This function ensures that our IMOS
  145.                                                 // pointer is available, and is called
  146.                                                 // by the framework entrypoint functions
  147.  
  148.         /* Interfaces For Use by the Framework         */
  149.         HRESULT GetObject(  ParsedObjectPath *pParsedObjectPath, 
  150.                             MethodContext *pContext, long lFlags = 0L );
  151.  
  152.         HRESULT ExecuteQuery( MethodContext *pContext, 
  153.                               CFrameworkQuery &pQuery, 
  154.                               long lFlags = 0L);
  155.  
  156.         HRESULT CreateInstanceEnum( MethodContext *pContext, long lFlags = 0L );
  157.  
  158.         HRESULT PutInstance( IWbemClassObject __RPC_FAR *pInst,
  159.                              long lFlags,
  160.                              MethodContext *pContext );
  161.  
  162.         HRESULT DeleteInstance( ParsedObjectPath *pParsedObjectPath,
  163.                                 long lFlags,
  164.                                 MethodContext *pContext );
  165.  
  166.         HRESULT ExecMethod( ParsedObjectPath *pParsedObjectPath,
  167.                             BSTR bstrMethodName,
  168.                             long lFlags,
  169.                             CInstance *pInParams,
  170.                             CInstance *pOutParams,
  171.                             MethodContext *pContext );
  172.  
  173.         // Static helper function called by constructor to make sure the
  174.         // computer name variable is properly initialized.
  175.         static void WINAPI InitComputerName( void );
  176.  
  177.         // Sets an instance key from a parsed object path.
  178.         BOOL SetKeyFromParsedObjectPath( CInstance *pInstance, 
  179.                                          ParsedObjectPath *pParsedObjectPath );
  180.  
  181.         IWbemClassObject *GetClassObjectInterface(MethodContext *pMethodContext);
  182.  
  183. };
  184.  
  185. #endif
  186. #pragma option pop /*P_O_Pop*/
  187.