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.

462 lines
9.6 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvSubS.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include <precomp.h>
  9. #include <wbemint.h>
  10. #include <HelperFuncs.h>
  11. #include "Guids.h"
  12. #include "Globals.h"
  13. #include "CGlobals.h"
  14. #include "ProvSubS.h"
  15. #include "ProvFact.h"
  16. #include "ProvAggr.h"
  17. #include "ProvLoad.h"
  18. #include "ProvWsv.h"
  19. #include "ProvObSk.h"
  20. #include "ProvCache.h"
  21. /******************************************************************************
  22. *
  23. * Name:
  24. *
  25. *
  26. * Description:
  27. *
  28. *
  29. *****************************************************************************/
  30. LONG CompareElement ( const HostCacheKey &a_Arg1 , const HostCacheKey &a_Arg2 )
  31. {
  32. return a_Arg1.Compare ( a_Arg2 ) ;
  33. }
  34. /******************************************************************************
  35. *
  36. * Name:
  37. *
  38. *
  39. * Description:
  40. *
  41. *
  42. *****************************************************************************/
  43. LONG CompareElement ( const BindingFactoryCacheKey &a_Arg1 , const BindingFactoryCacheKey &a_Arg2 )
  44. {
  45. return a_Arg1.Compare ( a_Arg2 ) ;
  46. }
  47. /******************************************************************************
  48. *
  49. * Name:
  50. *
  51. *
  52. * Description:
  53. *
  54. *
  55. *****************************************************************************/
  56. LONG CompareElement ( const ProviderCacheKey &a_Arg1 , const ProviderCacheKey &a_Arg2 )
  57. {
  58. return a_Arg1.Compare ( a_Arg2 ) ;
  59. }
  60. /******************************************************************************
  61. *
  62. * Name:
  63. *
  64. *
  65. * Description:
  66. *
  67. *
  68. *****************************************************************************/
  69. LONG CompareElement ( const GUID &a_Guid1 , const GUID &a_Guid2 )
  70. {
  71. return memcmp ( & a_Guid1, & a_Guid2 , sizeof ( GUID ) ) ;
  72. }
  73. /******************************************************************************
  74. *
  75. * Name:
  76. *
  77. *
  78. * Description:
  79. *
  80. *
  81. *****************************************************************************/
  82. LONG CompareElement ( const LONG &a_Arg1 , const LONG &a_Arg2 )
  83. {
  84. return a_Arg1 - a_Arg2 ;
  85. }
  86. /******************************************************************************
  87. *
  88. * Name:
  89. *
  90. *
  91. * Description:
  92. *
  93. *
  94. *****************************************************************************/
  95. HostController :: HostController ( WmiAllocator &a_Allocator ) : CWbemGlobal_IWmiHostController ( a_Allocator )
  96. {
  97. }
  98. /******************************************************************************
  99. *
  100. * Name:
  101. *
  102. *
  103. * Description:
  104. *
  105. *
  106. *****************************************************************************/
  107. WmiStatusCode HostController :: StrobeBegin ( const ULONG &a_Period )
  108. {
  109. ULONG t_Timeout = ProviderSubSystem_Globals :: GetStrobeThread ().GetTimeout () ;
  110. ProviderSubSystem_Globals :: GetStrobeThread ().SetTimeout ( t_Timeout < a_Period ? t_Timeout : a_Period ) ;
  111. return e_StatusCode_Success ;
  112. }
  113. /******************************************************************************
  114. *
  115. * Name:
  116. *
  117. *
  118. * Description:
  119. *
  120. *
  121. *****************************************************************************/
  122. RefresherManagerController :: RefresherManagerController ( WmiAllocator &a_Allocator ) : CWbemGlobal_IWbemRefresherMgrController ( a_Allocator )
  123. {
  124. }
  125. /******************************************************************************
  126. *
  127. * Name:
  128. *
  129. *
  130. * Description:
  131. *
  132. *
  133. *****************************************************************************/
  134. WmiStatusCode RefresherManagerController :: StrobeBegin ( const ULONG &a_Period )
  135. {
  136. ULONG t_Timeout = ProviderSubSystem_Globals :: GetStrobeThread ().GetTimeout () ;
  137. ProviderSubSystem_Globals :: GetStrobeThread ().SetTimeout ( t_Timeout < a_Period ? t_Timeout : a_Period ) ;
  138. return e_StatusCode_Success ;
  139. }
  140. /******************************************************************************
  141. *
  142. * Name:
  143. *
  144. *
  145. * Description:
  146. *
  147. *
  148. *****************************************************************************/
  149. ProviderController :: ProviderController (
  150. WmiAllocator &a_Allocator ,
  151. CWbemGlobal_HostedProviderController *a_Controller ,
  152. DWORD a_ProcessIdentifier
  153. ) : m_Container ( a_Allocator ) ,
  154. m_CriticalSection(NOTHROW_LOCK),
  155. HostedProviderContainerElement (
  156. a_Controller ,
  157. a_ProcessIdentifier
  158. )
  159. {
  160. }
  161. /******************************************************************************
  162. *
  163. * Name:
  164. *
  165. *
  166. * Description:
  167. *
  168. *
  169. *****************************************************************************/
  170. ProviderController :: ~ProviderController ()
  171. {
  172. }
  173. /******************************************************************************
  174. *
  175. * Name:
  176. *
  177. *
  178. * Description:
  179. *
  180. *
  181. *****************************************************************************/
  182. STDMETHODIMP_( ULONG ) ProviderController :: AddRef ()
  183. {
  184. return HostedProviderContainerElement :: AddRef () ;
  185. }
  186. /******************************************************************************
  187. *
  188. * Name:
  189. *
  190. *
  191. * Description:
  192. *
  193. *
  194. *****************************************************************************/
  195. STDMETHODIMP_( ULONG ) ProviderController :: Release ()
  196. {
  197. return HostedProviderContainerElement :: Release () ;
  198. }
  199. /******************************************************************************
  200. *
  201. * Name:
  202. *
  203. *
  204. * Description:
  205. *
  206. *
  207. *****************************************************************************/
  208. STDMETHODIMP ProviderController :: QueryInterface (
  209. REFIID iid ,
  210. LPVOID FAR *iplpv
  211. )
  212. {
  213. *iplpv = NULL ;
  214. if ( iid == IID_IUnknown )
  215. {
  216. *iplpv = ( LPVOID ) this ;
  217. }
  218. else if ( iid == IID_ProviderController )
  219. {
  220. *iplpv = ( LPVOID ) ( ProviderController * ) this ;
  221. }
  222. if ( *iplpv )
  223. {
  224. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  225. return ResultFromScode ( S_OK ) ;
  226. }
  227. else
  228. {
  229. return ResultFromScode ( E_NOINTERFACE ) ;
  230. }
  231. }
  232. /******************************************************************************
  233. *
  234. * Name:
  235. *
  236. *
  237. * Description:
  238. *
  239. *
  240. *****************************************************************************/
  241. WmiStatusCode ProviderController :: Initialize ()
  242. {
  243. WmiStatusCode t_StatusCode = m_Container.Initialize () ;
  244. if ( t_StatusCode == e_StatusCode_Success )
  245. {
  246. t_StatusCode = m_CriticalSection.valid() ? e_StatusCode_Success : e_StatusCode_OutOfMemory;
  247. }
  248. return t_StatusCode ;
  249. }
  250. /******************************************************************************
  251. *
  252. * Name:
  253. *
  254. *
  255. * Description:
  256. *
  257. *
  258. *****************************************************************************/
  259. WmiStatusCode ProviderController :: UnInitialize ()
  260. {
  261. WmiStatusCode t_StatusCode = m_Container.UnInitialize () ;
  262. return t_StatusCode ;
  263. }
  264. /******************************************************************************
  265. *
  266. * Name:
  267. *
  268. *
  269. * Description:
  270. *
  271. *
  272. *****************************************************************************/
  273. WmiStatusCode ProviderController :: Insert (
  274. CInterceptor_IWbemProvider *a_Element ,
  275. Container_Iterator &a_Iterator
  276. )
  277. {
  278. Lock () ;
  279. Container_Iterator t_Iterator ;
  280. WmiStatusCode t_StatusCode = m_Container.Insert ( a_Element , a_Element , t_Iterator ) ;
  281. if ( t_StatusCode == e_StatusCode_Success )
  282. {
  283. a_Element->NonCyclicAddRef () ;
  284. }
  285. UnLock () ;
  286. return t_StatusCode ;
  287. }
  288. /******************************************************************************
  289. *
  290. * Name:
  291. *
  292. *
  293. * Description:
  294. *
  295. *
  296. *****************************************************************************/
  297. WmiStatusCode ProviderController :: Delete (
  298. CInterceptor_IWbemProvider * const &a_Key
  299. )
  300. {
  301. Lock () ;
  302. WmiStatusCode t_StatusCode = m_Container.Delete ( a_Key ) ;
  303. UnLock () ;
  304. return t_StatusCode ;
  305. }
  306. /******************************************************************************
  307. *
  308. * Name:
  309. *
  310. *
  311. * Description:
  312. *
  313. *
  314. *****************************************************************************/
  315. WmiStatusCode ProviderController :: Find (
  316. CInterceptor_IWbemProvider * const &a_Key ,
  317. Container_Iterator &a_Iterator
  318. )
  319. {
  320. Lock () ;
  321. WmiStatusCode t_StatusCode = m_Container.Find ( a_Key , a_Iterator ) ;
  322. if ( t_StatusCode == e_StatusCode_Success )
  323. {
  324. a_Iterator.GetElement ()->NonCyclicAddRef ( ) ;
  325. }
  326. UnLock () ;
  327. return t_StatusCode ;
  328. }
  329. /******************************************************************************
  330. *
  331. * Name:
  332. *
  333. *
  334. * Description:
  335. *
  336. *
  337. *****************************************************************************/
  338. WmiStatusCode ProviderController :: Lock ()
  339. {
  340. if (!m_CriticalSection.valid())
  341. return e_StatusCode_OutOfMemory;
  342. while (!m_CriticalSection.acquire())
  343. Sleep(1000);
  344. return e_StatusCode_Success ;
  345. }
  346. /******************************************************************************
  347. *
  348. * Name:
  349. *
  350. *
  351. * Description:
  352. *
  353. *
  354. *****************************************************************************/
  355. WmiStatusCode ProviderController :: UnLock ()
  356. {
  357. m_CriticalSection.release();
  358. return e_StatusCode_Success ;
  359. }
  360. /******************************************************************************
  361. *
  362. * Name:
  363. *
  364. *
  365. * Description:
  366. *
  367. *
  368. *****************************************************************************/
  369. WmiStatusCode ProviderController :: Shutdown ()
  370. {
  371. Lock () ;
  372. Container_Iterator t_Iterator = m_Container.Root ();
  373. while ( ! t_Iterator.Null () )
  374. {
  375. m_Container.Delete ( t_Iterator.GetKey () ) ;
  376. t_Iterator = m_Container.Root () ;
  377. }
  378. UnLock () ;
  379. return e_StatusCode_Success ;
  380. }