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.

184 lines
8.0 KiB

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