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.

380 lines
7.3 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvFact.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include "PreComp.h"
  9. #include <wbemint.h>
  10. #include <NCObjApi.h>
  11. #include "Globals.h"
  12. #include "CGlobals.h"
  13. #include "ProvLoad.h"
  14. #include "ProvRegInfo.h"
  15. #include "ProvObSk.h"
  16. #include "ProvInSk.h"
  17. #include "StaThread.h"
  18. #include "StaTask.h"
  19. /******************************************************************************
  20. *
  21. * Name:
  22. *
  23. *
  24. * Description:
  25. *
  26. *
  27. *****************************************************************************/
  28. StaTask_Create :: StaTask_Create (
  29. WmiAllocator &a_Allocator ,
  30. CServerObject_StaThread &a_Thread ,
  31. LPCWSTR a_Scope ,
  32. LPCWSTR a_Namespace
  33. ) : WmiTask < ULONG > ( a_Allocator ) ,
  34. m_Thread ( a_Thread ) ,
  35. m_Scope ( NULL ) ,
  36. m_Namespace ( NULL ) ,
  37. m_ContextStream ( NULL ) ,
  38. m_RepositoryStream ( NULL ) ,
  39. m_ProviderStream ( NULL )
  40. {
  41. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_StaTask_Create_ObjectsInProgress ) ;
  42. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  43. }
  44. /******************************************************************************
  45. *
  46. * Name:
  47. *
  48. *
  49. * Description:
  50. *
  51. *
  52. *****************************************************************************/
  53. StaTask_Create :: ~StaTask_Create ()
  54. {
  55. if ( m_Namespace )
  56. {
  57. delete [] m_Namespace ;
  58. }
  59. if ( m_Scope )
  60. {
  61. delete [] m_Scope ;
  62. }
  63. if ( m_ContextStream )
  64. {
  65. m_ContextStream->Release () ;
  66. }
  67. if ( m_RepositoryStream )
  68. {
  69. m_RepositoryStream->Release () ;
  70. }
  71. if ( m_ProviderStream )
  72. {
  73. m_ProviderStream->Release () ;
  74. }
  75. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_StaTask_Create_ObjectsInProgress ) ;
  76. ProviderSubSystem_Globals :: Decrement_Global_Object_Count () ;
  77. }
  78. /******************************************************************************
  79. *
  80. * Name:
  81. *
  82. *
  83. * Description:
  84. *
  85. *
  86. *****************************************************************************/
  87. HRESULT StaTask_Create :: MarshalContext (
  88. IWbemContext *a_Context ,
  89. IWbemServices *a_Repository
  90. )
  91. {
  92. HRESULT t_Result = S_OK ;
  93. /*
  94. * Marshal interfaces here, so that we can pass an STA proxy.
  95. */
  96. if ( a_Context )
  97. {
  98. t_Result = CoMarshalInterThreadInterfaceInStream (
  99. IID_IWbemContext ,
  100. a_Context ,
  101. & m_ContextStream
  102. ) ;
  103. }
  104. if ( SUCCEEDED ( t_Result ) )
  105. {
  106. if ( a_Repository )
  107. {
  108. t_Result = CoMarshalInterThreadInterfaceInStream (
  109. IID_IWbemServices ,
  110. a_Repository ,
  111. & m_RepositoryStream
  112. ) ;
  113. }
  114. }
  115. return t_Result ;
  116. }
  117. /******************************************************************************
  118. *
  119. * Name:
  120. *
  121. *
  122. * Description:
  123. *
  124. *
  125. *****************************************************************************/
  126. HRESULT StaTask_Create :: UnMarshalContext ()
  127. {
  128. HRESULT t_Result = S_OK ;
  129. IWbemContext *t_Context = NULL ;
  130. IWbemServices *t_Repository = NULL ;
  131. if ( m_ContextStream )
  132. {
  133. t_Result = CoGetInterfaceAndReleaseStream (
  134. m_ContextStream ,
  135. IID_IWbemContext ,
  136. ( void ** ) & t_Context
  137. ) ;
  138. m_ContextStream = NULL ;
  139. }
  140. if ( SUCCEEDED ( t_Result ) )
  141. {
  142. if ( m_RepositoryStream )
  143. {
  144. t_Result = CoGetInterfaceAndReleaseStream (
  145. m_RepositoryStream ,
  146. IID_IWbemServices ,
  147. ( void ** ) & t_Repository
  148. ) ;
  149. m_RepositoryStream = NULL ;
  150. }
  151. }
  152. if ( t_Context )
  153. {
  154. m_Thread.SetContext ( t_Context ) ;
  155. t_Context->Release () ;
  156. }
  157. if ( t_Repository )
  158. {
  159. m_Thread.SetRepository ( t_Repository ) ;
  160. t_Repository->Release () ;
  161. }
  162. return t_Result ;
  163. }
  164. /******************************************************************************
  165. *
  166. * Name:
  167. *
  168. *
  169. * Description:
  170. *
  171. *
  172. *****************************************************************************/
  173. HRESULT StaTask_Create :: MarshalOutgoing (
  174. IUnknown *a_ProviderService
  175. )
  176. {
  177. HRESULT t_Result = S_OK ;
  178. /*
  179. * Marshal interfaces here, so that we can pass an STA proxy.
  180. */
  181. if ( a_ProviderService )
  182. {
  183. t_Result = CoMarshalInterThreadInterfaceInStream (
  184. IID_IUnknown ,
  185. a_ProviderService ,
  186. & m_ProviderStream
  187. ) ;
  188. }
  189. return t_Result ;
  190. }
  191. /******************************************************************************
  192. *
  193. * Name:
  194. *
  195. *
  196. * Description:
  197. *
  198. *
  199. *****************************************************************************/
  200. HRESULT StaTask_Create :: UnMarshalOutgoing ()
  201. {
  202. HRESULT t_Result = S_OK ;
  203. IUnknown *t_ProviderService = NULL ;
  204. if ( m_ProviderStream )
  205. {
  206. t_Result = CoGetInterfaceAndReleaseStream (
  207. m_ProviderStream ,
  208. IID_IUnknown ,
  209. ( void ** ) &t_ProviderService
  210. ) ;
  211. m_ProviderStream = NULL ;
  212. if ( SUCCEEDED ( t_Result ) )
  213. {
  214. m_Thread.SetProviderService ( t_ProviderService ) ;
  215. t_ProviderService->Release () ;
  216. }
  217. }
  218. return t_Result ;
  219. }
  220. /******************************************************************************
  221. *
  222. * Name:
  223. *
  224. *
  225. * Description:
  226. *
  227. *
  228. *****************************************************************************/
  229. WmiStatusCode StaTask_Create :: Process ( WmiThread <ULONG > &a_Thread )
  230. {
  231. m_Result = S_OK ;
  232. wchar_t t_TransactionIdentifier [ sizeof ( L"{00000000-0000-0000-0000-000000000000}" ) ] ;
  233. if ( m_Thread.Direct_GetTransactionIdentifier () )
  234. {
  235. StringFromGUID2 ( *m_Thread.Direct_GetTransactionIdentifier () , t_TransactionIdentifier , sizeof ( t_TransactionIdentifier ) / sizeof ( wchar_t ) );
  236. }
  237. IUnknown *t_ProviderInterface = NULL ;
  238. m_Result = UnMarshalContext () ;
  239. if ( SUCCEEDED ( m_Result ) )
  240. {
  241. wchar_t *t_NamespacePath = NULL ;
  242. m_Result = ProviderSubSystem_Common_Globals :: GetNamespacePath (
  243. m_Thread.Direct_GetNamespacePath () ,
  244. t_NamespacePath
  245. ) ;
  246. if ( SUCCEEDED ( m_Result ) )
  247. {
  248. CServerObject_ProviderRegistrationV1 *t_Registration = new CServerObject_ProviderRegistrationV1 ;
  249. if ( t_Registration )
  250. {
  251. t_Registration->AddRef () ;
  252. m_Result = t_Registration->SetContext (
  253. m_Thread.Direct_GetContext () ,
  254. m_Thread.Direct_GetNamespacePath () ,
  255. m_Thread.Direct_GetRepository ()
  256. ) ;
  257. if ( SUCCEEDED ( m_Result ) )
  258. {
  259. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_ObjectCacheTimeout ) ;
  260. m_Result = t_Registration->Load (
  261. e_All ,
  262. NULL ,
  263. m_Thread.Direct_GetProviderName ()
  264. ) ;
  265. if ( SUCCEEDED ( m_Result ) )
  266. {
  267. m_Result = CServerObject_RawFactory :: CreateServerSide (
  268. *t_Registration ,
  269. NULL ,
  270. NULL ,
  271. NULL ,
  272. t_NamespacePath ,
  273. & t_ProviderInterface
  274. ) ;
  275. if ( SUCCEEDED ( m_Result ) )
  276. {
  277. IUnknown *t_ProviderService = NULL ;
  278. m_Result = t_ProviderInterface->QueryInterface ( IID_IUnknown , ( void ** ) & t_ProviderService ) ;
  279. if ( SUCCEEDED ( m_Result ) )
  280. {
  281. MarshalOutgoing ( t_ProviderService ) ;
  282. t_ProviderService->Release () ;
  283. }
  284. t_ProviderInterface->Release () ;
  285. }
  286. }
  287. }
  288. t_Registration->Release () ;
  289. }
  290. delete [] t_NamespacePath ;
  291. }
  292. else
  293. {
  294. m_Result = WBEM_E_OUT_OF_MEMORY ;
  295. }
  296. }
  297. Complete () ;
  298. return e_StatusCode_Success ;
  299. }