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.

357 lines
8.5 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // CLASSFAC.CPP
  6. //
  7. // rajesh 2/25/2000 Created.
  8. //
  9. // Contains the class factory for 2 components - CWmiToXml and CXml2Wmi
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include <wbemidl.h>
  14. #include <wbemint.h>
  15. #include <genlex.h>
  16. #include <opathlex.h>
  17. #include <objpath.h>
  18. #include "maindll.h"
  19. #include "classfac.h"
  20. #include "wmiconv.h"
  21. #include "wmi2xml.h"
  22. //***************************************************************************
  23. //
  24. // CWmiToXmlFactory::CWmiToXmlFactory
  25. //
  26. // DESCRIPTION:
  27. //
  28. // Constructor
  29. //
  30. //***************************************************************************
  31. CWmiToXmlFactory::CWmiToXmlFactory()
  32. {
  33. m_cRef=0L;
  34. InterlockedIncrement(&g_cObj);
  35. return;
  36. }
  37. //***************************************************************************
  38. //
  39. // CWmiToXmlFactory::~CWmiToXmlFactory
  40. //
  41. // DESCRIPTION:
  42. //
  43. // Destructor
  44. //
  45. //***************************************************************************
  46. CWmiToXmlFactory::~CWmiToXmlFactory(void)
  47. {
  48. InterlockedDecrement(&g_cObj);
  49. return;
  50. }
  51. //***************************************************************************
  52. //
  53. // CWmiToXmlFactory::QueryInterface
  54. // CWmiToXmlFactory::AddRef
  55. // CWmiToXmlFactory::Release
  56. //
  57. // Purpose: Standard Ole routines needed for all interfaces
  58. //
  59. //***************************************************************************
  60. STDMETHODIMP CWmiToXmlFactory::QueryInterface(REFIID riid
  61. , LPVOID *ppv)
  62. {
  63. *ppv=NULL;
  64. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  65. *ppv=this;
  66. if (NULL!=*ppv)
  67. {
  68. ((LPUNKNOWN)*ppv)->AddRef();
  69. return NOERROR;
  70. }
  71. return ResultFromScode(E_NOINTERFACE);
  72. }
  73. STDMETHODIMP_(ULONG) CWmiToXmlFactory::AddRef(void)
  74. {
  75. long l = InterlockedIncrement(&m_cRef);
  76. return l;
  77. }
  78. STDMETHODIMP_(ULONG) CWmiToXmlFactory::Release(void)
  79. {
  80. long l = InterlockedDecrement(&m_cRef);
  81. if (0L!=l)
  82. return l;
  83. delete this;
  84. return 0L;
  85. }
  86. //***************************************************************************
  87. //
  88. // SCODE CWmiToXmlFactory::CreateInstance
  89. //
  90. // Description:
  91. //
  92. // Instantiates a Translator object returning an interface pointer.
  93. //
  94. // Parameters:
  95. //
  96. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  97. // being used in an aggregation.
  98. // riid REFIID identifying the interface the caller
  99. // desires to have for the new object.
  100. // ppvObj PPVOID in which to store the desired
  101. // interface pointer for the new object.
  102. //
  103. // Return Value:
  104. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  105. // if we cannot support the requested interface.
  106. //***************************************************************************
  107. STDMETHODIMP CWmiToXmlFactory::CreateInstance (
  108. IN LPUNKNOWN pUnkOuter,
  109. IN REFIID riid,
  110. OUT PPVOID ppvObj
  111. )
  112. {
  113. IUnknown * pObj;
  114. HRESULT hr;
  115. *ppvObj=NULL;
  116. // This object doesnt support aggregation.
  117. if (NULL!=pUnkOuter)
  118. return ResultFromScode(CLASS_E_NOAGGREGATION);
  119. pObj = new CWmiToXml;
  120. if (NULL == pObj)
  121. return ResultFromScode(E_OUTOFMEMORY);;
  122. hr = pObj->QueryInterface(riid, ppvObj);
  123. //Kill the object if initial creation or Init failed.
  124. if ( FAILED(hr) )
  125. delete pObj;
  126. return hr;
  127. }
  128. //***************************************************************************
  129. //
  130. // SCODE CWmiToXmlFactory::LockServer
  131. //
  132. // Description:
  133. //
  134. // Increments or decrements the lock count of the DLL. If the
  135. // lock count goes to zero and there are no objects, the DLL
  136. // is allowed to unload. See DllCanUnloadNow.
  137. //
  138. // Parameters:
  139. //
  140. // fLock BOOL specifying whether to increment or
  141. // decrement the lock count.
  142. //
  143. // Return Value:
  144. //
  145. // HRESULT NOERROR always.
  146. //***************************************************************************
  147. STDMETHODIMP CWmiToXmlFactory::LockServer(IN BOOL fLock)
  148. {
  149. if (fLock)
  150. InterlockedIncrement((long *)&g_cLock);
  151. else
  152. InterlockedDecrement((long *)&g_cLock);
  153. return NOERROR;
  154. }
  155. /* Conversion to Text to Wbem Object has been cut from the WHistler Feature List and hence commented out
  156. // ***************************************************************************
  157. //
  158. // CWmiToXmlFactory::CWmiToXmlFactory
  159. //
  160. // DESCRIPTION:
  161. //
  162. // Constructor
  163. //
  164. // ***************************************************************************
  165. CXmlToWmiFactory::CXmlToWmiFactory()
  166. {
  167. m_cRef=0L;
  168. InterlockedIncrement(&g_cObj);
  169. // Make sure Globals are initialized
  170. // The corresponding call ReleaseDLLResources() call
  171. // is made in DllCanUnloadNow()
  172. AllocateDLLResources();
  173. return;
  174. }
  175. // ***************************************************************************
  176. //
  177. // CWmiToXmlFactory::~CWmiToXmlFactory
  178. //
  179. // DESCRIPTION:
  180. //
  181. // Destructor
  182. //
  183. // ***************************************************************************
  184. CXmlToWmiFactory::~CXmlToWmiFactory(void)
  185. {
  186. InterlockedDecrement(&g_cObj);
  187. return;
  188. }
  189. // ***************************************************************************
  190. //
  191. // CWmiToXmlFactory::QueryInterface
  192. // CWmiToXmlFactory::AddRef
  193. // CWmiToXmlFactory::Release
  194. //
  195. // Purpose: Standard Ole routines needed for all interfaces
  196. //
  197. // ***************************************************************************
  198. STDMETHODIMP CXmlToWmiFactory::QueryInterface(REFIID riid
  199. , LPVOID *ppv)
  200. {
  201. *ppv=NULL;
  202. if (IID_IUnknown==riid || IID_IClassFactory==riid)
  203. *ppv=this;
  204. if (NULL!=*ppv)
  205. {
  206. ((LPUNKNOWN)*ppv)->AddRef();
  207. return NOERROR;
  208. }
  209. return ResultFromScode(E_NOINTERFACE);
  210. }
  211. STDMETHODIMP_(ULONG) CXmlToWmiFactory::AddRef(void)
  212. {
  213. long l = InterlockedIncrement(&m_cRef);
  214. return l;
  215. }
  216. STDMETHODIMP_(ULONG) CXmlToWmiFactory::Release(void)
  217. {
  218. long l = InterlockedDecrement(&m_cRef);
  219. if (0L!=l)
  220. return l;
  221. delete this;
  222. return 0L;
  223. }
  224. // ***************************************************************************
  225. //
  226. // SCODE CWmiToXmlFactory::CreateInstance
  227. //
  228. // Description:
  229. //
  230. // Instantiates a Translator object returning an interface pointer.
  231. //
  232. // Parameters:
  233. //
  234. // pUnkOuter LPUNKNOWN to the controlling IUnknown if we are
  235. // being used in an aggregation.
  236. // riid REFIID identifying the interface the caller
  237. // desires to have for the new object.
  238. // ppvObj PPVOID in which to store the desired
  239. // interface pointer for the new object.
  240. //
  241. // Return Value:
  242. // HRESULT NOERROR if successful, otherwise E_NOINTERFACE
  243. // if we cannot support the requested interface.
  244. // ***************************************************************************
  245. STDMETHODIMP CXmlToWmiFactory::CreateInstance (
  246. IN LPUNKNOWN pUnkOuter,
  247. IN REFIID riid,
  248. OUT PPVOID ppvObj
  249. )
  250. {
  251. IUnknown * pObj;
  252. HRESULT hr;
  253. *ppvObj=NULL;
  254. // This object doesnt support aggregation.
  255. if (NULL!=pUnkOuter)
  256. return ResultFromScode(CLASS_E_NOAGGREGATION);
  257. pObj = new CXml2Wmi;
  258. if (NULL == pObj)
  259. return ResultFromScode(E_OUTOFMEMORY);;
  260. hr = pObj->QueryInterface(riid, ppvObj);
  261. //Kill the object if initial creation or Init failed.
  262. if ( FAILED(hr) )
  263. delete pObj;
  264. return hr;
  265. }
  266. // ***************************************************************************
  267. //
  268. // SCODE CWmiToXmlFactory::LockServer
  269. //
  270. // Description:
  271. //
  272. // Increments or decrements the lock count of the DLL. If the
  273. // lock count goes to zero and there are no objects, the DLL
  274. // is allowed to unload. See DllCanUnloadNow.
  275. //
  276. // Parameters:
  277. //
  278. // fLock BOOL specifying whether to increment or
  279. // decrement the lock count.
  280. //
  281. // Return Value:
  282. //
  283. // HRESULT NOERROR always.
  284. // ***************************************************************************
  285. STDMETHODIMP CXmlToWmiFactory::LockServer(IN BOOL fLock)
  286. {
  287. if (fLock)
  288. InterlockedIncrement((long *)&g_cLock);
  289. else
  290. InterlockedDecrement((long *)&g_cLock);
  291. return NOERROR;
  292. }
  293. */