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.

326 lines
8.2 KiB

  1. /*++
  2. Copyright (C) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. COMOBJ.H
  5. Abstract:
  6. This file defines the classes related to class representation
  7. of mofcomp objects.
  8. History:
  9. 9/16/98 a-davj Created
  10. --*/
  11. #ifndef __COMOBJ__H_
  12. #define __COMOBJ__H_
  13. //***************************************************************************
  14. //
  15. // CLASS NAME:
  16. //
  17. // CGenFactory
  18. //
  19. // DESCRIPTION:
  20. //
  21. // Class factory template.
  22. //
  23. //***************************************************************************
  24. typedef LPVOID * PPVOID;
  25. void ObjectCreated();
  26. void ObjectDestroyed();
  27. template<class TObj>
  28. class CGenFactory : public IClassFactory
  29. {
  30. protected:
  31. long m_cRef;
  32. public:
  33. CGenFactory(void)
  34. {
  35. m_cRef=0L;
  36. ObjectCreated();
  37. return;
  38. };
  39. ~CGenFactory(void)
  40. {
  41. ObjectDestroyed();
  42. return;
  43. }
  44. //IUnknown members
  45. STDMETHODIMP QueryInterface(REFIID riid, PPVOID ppv)
  46. {
  47. *ppv=NULL;
  48. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  49. *ppv=this;
  50. if (NULL!=*ppv)
  51. {
  52. AddRef();
  53. return NOERROR;
  54. }
  55. return ResultFromScode(E_NOINTERFACE);
  56. };
  57. STDMETHODIMP_(ULONG) AddRef(void)
  58. {
  59. return ++m_cRef;
  60. };
  61. STDMETHODIMP_(ULONG) Release(void)
  62. {
  63. long lRet = InterlockedDecrement(&m_cRef);
  64. if (0 ==lRet)
  65. delete this;
  66. return lRet;
  67. };
  68. //IClassFactory members
  69. STDMETHODIMP CreateInstance(IN LPUNKNOWN pUnkOuter, IN REFIID riid, OUT PPVOID ppvObj)
  70. {
  71. HRESULT hr;
  72. *ppvObj=NULL;
  73. hr=E_OUTOFMEMORY;
  74. // This object doesnt support aggregation.
  75. if (NULL!=pUnkOuter)
  76. return CLASS_E_NOAGGREGATION;
  77. //Create the object passing function to notify on destruction.
  78. TObj * pObj = new TObj();
  79. if (NULL==pObj)
  80. return hr;
  81. // Setup the class all empty, etc.
  82. hr=pObj->QueryInterface(riid, ppvObj);
  83. pObj->Release();
  84. return hr;
  85. };
  86. STDMETHODIMP LockServer(BOOL fLock)
  87. {
  88. if (fLock)
  89. InterlockedIncrement((long *)&g_cLock);
  90. else
  91. InterlockedDecrement((long *)&g_cLock);
  92. return NOERROR;
  93. };
  94. };
  95. //***************************************************************************
  96. //
  97. // CLASS NAME:
  98. //
  99. // CMofComp
  100. //
  101. // DESCRIPTION:
  102. //
  103. // Supports mofcomp functions for clients.
  104. //
  105. //***************************************************************************
  106. class CMofComp : IMofCompiler
  107. {
  108. protected:
  109. long m_cRef;
  110. public:
  111. CMofComp(void)
  112. {
  113. m_cRef=1L;
  114. ObjectCreated();
  115. return;
  116. };
  117. ~CMofComp(void)
  118. {
  119. ObjectDestroyed();
  120. return;
  121. }
  122. //IUnknown members
  123. STDMETHODIMP QueryInterface(REFIID riid, PPVOID ppv)
  124. {
  125. *ppv=NULL;
  126. if (IID_IUnknown==riid || IID_IMofCompiler==riid)
  127. *ppv=this;
  128. if (NULL!=*ppv)
  129. {
  130. AddRef();
  131. return NOERROR;
  132. }
  133. return E_NOINTERFACE;
  134. };
  135. STDMETHODIMP_(ULONG) AddRef(void)
  136. {
  137. return ++m_cRef;
  138. };
  139. STDMETHODIMP_(ULONG) Release(void)
  140. {
  141. long lRef = InterlockedDecrement(&m_cRef);
  142. if (0L == lRef)
  143. delete this;
  144. return lRef;
  145. };
  146. // IMofCompiler functions
  147. HRESULT STDMETHODCALLTYPE CompileFile(
  148. /* [in] */ LPWSTR FileName,
  149. /* [in] */ LPWSTR ServerAndNamespace,
  150. /* [in] */ LPWSTR User,
  151. /* [in] */ LPWSTR Authority,
  152. /* [in] */ LPWSTR Password,
  153. /* [in] */ LONG lOptionFlags,
  154. /* [in] */ LONG lClassFlags,
  155. /* [in] */ LONG lInstanceFlags,
  156. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo);
  157. HRESULT STDMETHODCALLTYPE CompileBuffer(
  158. /* [in] */ long BuffSize,
  159. /* [size_is][in] */ BYTE __RPC_FAR *pBuffer,
  160. /* [in] */ LPWSTR ServerAndNamespace,
  161. /* [in] */ LPWSTR User,
  162. /* [in] */ LPWSTR Authority,
  163. /* [in] */ LPWSTR Password,
  164. /* [in] */ LONG lOptionFlags,
  165. /* [in] */ LONG lClassFlags,
  166. /* [in] */ LONG lInstanceFlags,
  167. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo);
  168. HRESULT STDMETHODCALLTYPE CreateBMOF(
  169. /* [in] */ LPWSTR TextFileName,
  170. /* [in] */ LPWSTR BMOFFileName,
  171. /* [in] */ LPWSTR ServerAndNamespace,
  172. /* [in] */ LONG lOptionFlags,
  173. /* [in] */ LONG lClassFlags,
  174. /* [in] */ LONG lInstanceFlags,
  175. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo);
  176. };
  177. //***************************************************************************
  178. //
  179. // CLASS NAME:
  180. //
  181. // CWinmgmtMofComp
  182. //
  183. // DESCRIPTION:
  184. //
  185. // Provides mofcomp functions for internal use.
  186. //
  187. //***************************************************************************
  188. class CWinmgmtMofComp : IWinmgmtMofCompiler
  189. {
  190. protected:
  191. long m_cRef;
  192. public:
  193. CWinmgmtMofComp(void)
  194. {
  195. m_cRef=1L;
  196. ObjectCreated();
  197. return;
  198. };
  199. ~CWinmgmtMofComp(void)
  200. {
  201. ObjectDestroyed();
  202. return;
  203. }
  204. //IUnknown members
  205. STDMETHODIMP QueryInterface(REFIID riid, PPVOID ppv)
  206. {
  207. *ppv=NULL;
  208. if (IID_IUnknown==riid || IID_IWinmgmtMofCompiler==riid)
  209. *ppv=this;
  210. if (NULL!=*ppv)
  211. {
  212. AddRef();
  213. return NOERROR;
  214. }
  215. return E_NOINTERFACE;
  216. };
  217. STDMETHODIMP_(ULONG) AddRef(void)
  218. {
  219. return ++m_cRef;
  220. };
  221. STDMETHODIMP_(ULONG) Release(void)
  222. {
  223. long lRef = InterlockedDecrement(&m_cRef);
  224. if (0L == lRef)
  225. delete this;
  226. return lRef;
  227. };
  228. // IWinmgmtMofCompiler functions
  229. HRESULT STDMETHODCALLTYPE WinmgmtCompileFile(
  230. /* [in] */ LPWSTR FileName,
  231. /* [in] */ LPWSTR ServerAndNamespace,
  232. /* [in] */ LONG lOptionFlags,
  233. /* [in] */ LONG lClassFlags,
  234. /* [in] */ LONG lInstanceFlags,
  235. /* [in] */ IWbemServices __RPC_FAR *pOverride,
  236. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  237. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo);
  238. HRESULT STDMETHODCALLTYPE WinmgmtCompileBuffer(
  239. /* [in] */ long BuffSize,
  240. /* [size_is][in] */ BYTE __RPC_FAR *pBuffer,
  241. /* [in] */ LONG lOptionFlags,
  242. /* [in] */ LONG lClassFlags,
  243. /* [in] */ LONG lInstanceFlags,
  244. /* [in] */ IWbemServices __RPC_FAR *pOverride,
  245. /* [in] */ IWbemContext __RPC_FAR *pCtx,
  246. /* [out][in] */ WBEM_COMPILE_STATUS_INFO __RPC_FAR *pInfo);
  247. };
  248. class CMofCompOOP : public CWinmgmtMofComp
  249. {
  250. public:
  251. STDMETHODIMP QueryInterface(REFIID riid, PPVOID ppv)
  252. {
  253. *ppv=NULL;
  254. if (IID_IUnknown==riid)
  255. *ppv=this;
  256. else if (IID_IWinmgmtMofCompiler == riid)
  257. *ppv=this;
  258. else if (IID_IWinmgmtMofCompilerOOP == riid)
  259. *ppv=this;
  260. if (NULL != *ppv)
  261. {
  262. AddRef();
  263. return NOERROR;
  264. }
  265. return E_NOINTERFACE;
  266. };
  267. };
  268. #endif