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.

120 lines
4.2 KiB

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 1999 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: componentfactory.h
  6. //
  7. // Project: Chameleon
  8. //
  9. // Description: Component Factory Class
  10. //
  11. // Log:
  12. //
  13. // When Who What
  14. // ---- --- ----
  15. // 02/08/1999 TLP Initial Version
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef __INC_COMPONENT_FACTORY_H_
  19. #define __INC_COMPONENT_FACTORY_H_
  20. #include "propertybag.h"
  21. #pragma warning( disable : 4786 )
  22. #include <memory>
  23. using namespace std;
  24. //////////////////////////////////////////////////////////////////////////////
  25. // WBEM Object Factory Class
  26. template <class TypeClass, class TypeInterface>
  27. class CComponentFactoryImpl
  28. {
  29. public:
  30. CComponentFactoryImpl() { }
  31. ~CComponentFactoryImpl() { }
  32. //////////////////////////////////////////////////////////////////////////
  33. // Component Factory Function
  34. //
  35. // Inputs:
  36. //
  37. // pPropertyBag: Property bag containing the components
  38. // persistent state.
  39. //
  40. // Outputs:
  41. //
  42. // Pointer to the new component or NULL if the component could not
  43. // be created and initialized
  44. //
  45. //////////////////////////////////////////////////////////////////////////
  46. static IUnknown* WINAPI MakeComponent(
  47. /*[in]*/ PPROPERTYBAG pPropertyBag
  48. )
  49. {
  50. TypeInterface* pObj = NULL;
  51. // Objects create in this fashion require a default constructor
  52. auto_ptr< CComObjectNoLock<TypeClass> > pNewObj (new CComObjectNoLock<TypeClass>);
  53. // InternalInitialize() is used to initialize the new component
  54. if ( SUCCEEDED(pNewObj->InternalInitialize(pPropertyBag)) )
  55. {
  56. pObj = dynamic_cast<TypeInterface*>(pNewObj.release());
  57. }
  58. return pObj;
  59. }
  60. private:
  61. // No copy or assignment
  62. CComponentFactoryImpl(const CComponentFactoryImpl& rhs);
  63. CComponentFactoryImpl& operator = (const CComponentFactoryImpl& rhs);
  64. };
  65. //////////////////////////////////////////////////////////////////////////////
  66. // Component Factory Class Macros
  67. // (include in classes created by the factory)
  68. //////////////////////////////////////////////////////////////////////////////
  69. #define DECLARE_COMPONENT_FACTORY(TypeClass, TypeInterface) \
  70. static CComponentFactoryImpl<TypeClass, TypeInterface> m_Factory;
  71. //////////////////////////////////////////////////////////////////////////////
  72. // Global Component Factory Function Prototype
  73. //////////////////////////////////////////////////////////////////////////////
  74. IUnknown* MakeComponent(
  75. /*[in]*/ LPCWSTR pszClassId,
  76. /*[in]*/ PPROPERTYBAG pPropertyBag
  77. );
  78. //////////////////////////////////////////////////////////////////////////////
  79. // Component Factory Structure - ClassId to Factory Function Mapping
  80. // (used by global component factory function implementation)
  81. //////////////////////////////////////////////////////////////////////////////
  82. typedef IUnknown* (WINAPI *PFNCOMPONENTFACTORY)(
  83. /*[in]*/ PPROPERTYBAG pPropertyBag
  84. );
  85. //////////////////////////////////////////////////////////////////////////////
  86. typedef struct _COMPONENT_FACTORY_INFO
  87. {
  88. LPCWSTR pszClassId;
  89. PFNCOMPONENTFACTORY pfnFactory;
  90. } COMPONENT_FACTORY_INFO, *PCOMPONENT_FACTORY_INFO;
  91. //////////////////////////////////////////////////////////////////////////////
  92. // Component Factory Map Macros
  93. //////////////////////////////////////////////////////////////////////////////
  94. #define BEGIN_COMPONENT_FACTORY_MAP(x) COMPONENT_FACTORY_INFO x[] = {
  95. #define DEFINE_COMPONENT_FACTORY_ENTRY(szClassId, Class) { szClassId, Class::m_Factory.MakeComponent },
  96. #define END_COMPONENT_FACTORY_MAP() { NULL, NULL } };
  97. #endif // __INC_COMPONENT_FACTORY_H_