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.

834 lines
19 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: FrmUtils.hxx
  7. //
  8. // Contents: Framework parameter utility classes
  9. //
  10. // History: 14-Jan-1998 KyleP Added header
  11. //
  12. //----------------------------------------------------------------------------
  13. #pragma once
  14. #include <ciintf.h>
  15. #include <driveinf.hxx>
  16. class PDeSerStream;
  17. class PSerStream;
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Class: CCiFrameworkParams
  21. //
  22. // Purpose: A wrapper around the administrative parameters interface
  23. // for the frame work.
  24. //
  25. // History: 12-05-96 srikants Created
  26. // 19-10-98 sundara added IS_ENUM_ALLOWED
  27. //
  28. // Notes:
  29. //
  30. //----------------------------------------------------------------------------
  31. class CCiFrameworkParams
  32. {
  33. public:
  34. CCiFrameworkParams( ICiAdminParams * pCiAdminParams = 0 )
  35. : _pCiAdminParams(pCiAdminParams)
  36. {
  37. if ( _pCiAdminParams )
  38. _pCiAdminParams->AddRef();
  39. }
  40. ~CCiFrameworkParams()
  41. {
  42. if ( _pCiAdminParams )
  43. _pCiAdminParams->Release();
  44. }
  45. void Set( ICiAdminParams * pCiAdminParams )
  46. {
  47. Win4Assert( 0 != pCiAdminParams );
  48. Win4Assert( 0 == _pCiAdminParams );
  49. pCiAdminParams->AddRef();
  50. _pCiAdminParams = pCiAdminParams;
  51. }
  52. const BOOL FilterContents()
  53. {
  54. DWORD dwVal = 0;
  55. _pCiAdminParams->GetValue( CI_AP_FILTER_CONTENTS, &dwVal );
  56. return 0 != dwVal;
  57. }
  58. const __int64 GetMaxFilesizeFiltered()
  59. {
  60. __int64 val;
  61. _pCiAdminParams->GetInt64Value( CI_AP_MAX_FILESIZE_FILTERED, &val );
  62. //
  63. // Filesize is specified in Kilobytes but used in bytes.
  64. //
  65. val *= 1024;
  66. return val;
  67. }
  68. const ULONG GetMasterMergeTime()
  69. {
  70. DWORD dwVal;
  71. SCODE sc = _pCiAdminParams->GetValue( CI_AP_MASTER_MERGE_TIME, &dwVal );
  72. Win4Assert( S_OK == sc );
  73. return dwVal;
  74. }
  75. const ULONG GetMaxFilesizeMultiplier()
  76. {
  77. DWORD dwVal;
  78. SCODE sc = _pCiAdminParams->GetValue(
  79. CI_AP_MAX_FILESIZE_MULTIPLIER, &dwVal );
  80. Win4Assert( S_OK == sc );
  81. return dwVal;
  82. }
  83. const int GetThreadPriorityFilter()
  84. {
  85. DWORD dwVal;
  86. SCODE sc = _pCiAdminParams->GetValue(
  87. CI_AP_THREAD_PRIORITY_FILTER, &dwVal );
  88. Win4Assert( S_OK == sc );
  89. return dwVal;
  90. }
  91. const int GetThreadClassFilter()
  92. {
  93. DWORD dwVal;
  94. SCODE sc = _pCiAdminParams->GetValue(
  95. CI_AP_THREAD_CLASS_FILTER, &dwVal );
  96. Win4Assert( S_OK == sc );
  97. return dwVal;
  98. }
  99. const ULONG GetDaemonResponseTimeout()
  100. {
  101. DWORD dwVal;
  102. SCODE sc = _pCiAdminParams->GetValue(
  103. CI_AP_DAEMON_RESPONSE_TIMEOUT, &dwVal );
  104. Win4Assert( S_OK == sc );
  105. return dwVal;
  106. }
  107. const ULONG GetMaxCharacterization()
  108. {
  109. DWORD dwVal;
  110. SCODE sc = _pCiAdminParams->GetValue(
  111. CI_AP_MAX_CHARACTERIZATION, &dwVal );
  112. Win4Assert( S_OK == sc );
  113. return dwVal;
  114. }
  115. const BOOL GenerateCharacterization()
  116. {
  117. DWORD dwVal;
  118. SCODE sc = _pCiAdminParams->GetValue(
  119. CI_AP_GENERATE_CHARACTERIZATION, &dwVal );
  120. Win4Assert( S_OK == sc );
  121. return 0 != dwVal;
  122. }
  123. const BOOL FilterDirectories()
  124. {
  125. DWORD dwVal;
  126. SCODE sc = _pCiAdminParams->GetValue(
  127. CI_AP_FILTER_DIRECTORIES, &dwVal );
  128. Win4Assert( S_OK == sc );
  129. return 0 != dwVal;
  130. }
  131. const BOOL FilterFilesWithUnknownExtensions()
  132. {
  133. DWORD dwVal;
  134. SCODE sc = _pCiAdminParams->GetValue(
  135. CI_AP_FFILTER_FILES_WITH_UNKNOWN_EXTENSIONS, &dwVal );
  136. Win4Assert( S_OK == sc );
  137. return 0 != dwVal;
  138. }
  139. const ULONG GetFilterDelayInterval()
  140. {
  141. DWORD dwVal;
  142. SCODE sc = _pCiAdminParams->GetValue(
  143. CI_AP_FILTER_DELAY_INTERVAL, &dwVal );
  144. Win4Assert( S_OK == sc );
  145. return dwVal;
  146. }
  147. const ULONG GetFilterRemainingThreshold()
  148. {
  149. DWORD dwVal;
  150. SCODE sc = _pCiAdminParams->GetValue(
  151. CI_AP_FILTER_REMAINING_THRESHOLD, &dwVal );
  152. Win4Assert( S_OK == sc );
  153. return dwVal;
  154. }
  155. const ULONG GetMaxMergeInterval()
  156. {
  157. DWORD dwVal;
  158. SCODE sc = _pCiAdminParams->GetValue(
  159. CI_AP_MERGE_INTERVAL, &dwVal );
  160. Win4Assert( S_OK == sc );
  161. return dwVal;
  162. }
  163. const int GetThreadPriorityMerge()
  164. {
  165. DWORD dwVal;
  166. SCODE sc = _pCiAdminParams->GetValue(
  167. CI_AP_THREAD_PRIORITY_MERGE, &dwVal );
  168. Win4Assert( S_OK == sc );
  169. return (int) dwVal;
  170. }
  171. const ULONG GetMaxUpdates()
  172. {
  173. DWORD dwVal;
  174. SCODE sc = _pCiAdminParams->GetValue(
  175. CI_AP_MAX_UPDATES, &dwVal );
  176. Win4Assert( S_OK == sc );
  177. return dwVal;
  178. }
  179. const ULONG GetMaxWordlists()
  180. {
  181. DWORD dwVal;
  182. SCODE sc = _pCiAdminParams->GetValue(
  183. CI_AP_MAX_WORDLISTS, &dwVal );
  184. Win4Assert( S_OK == sc );
  185. return dwVal;
  186. }
  187. const ULONG GetMinSizeMergeWordlist()
  188. {
  189. DWORD dwVal;
  190. SCODE sc = _pCiAdminParams->GetValue(
  191. CI_AP_MIN_SIZE_MERGE_WORDLISTS, &dwVal );
  192. Win4Assert( S_OK == sc );
  193. return dwVal;
  194. }
  195. const ULONG GetMaxWordlistSize()
  196. {
  197. DWORD dwVal;
  198. SCODE sc = _pCiAdminParams->GetValue(
  199. CI_AP_MAX_WORDLIST_SIZE, &dwVal );
  200. Win4Assert( S_OK == sc );
  201. return dwVal;
  202. }
  203. const ULONG GetMinWordlistMemory()
  204. {
  205. DWORD dwVal;
  206. SCODE sc = _pCiAdminParams->GetValue(
  207. CI_AP_MIN_WORDLIST_MEMORY, &dwVal );
  208. Win4Assert( S_OK == sc );
  209. return dwVal;
  210. }
  211. const ULONG GetMaxWordlistIo()
  212. {
  213. DWORD dwVal;
  214. SCODE sc = _pCiAdminParams->GetValue(
  215. CI_AP_MAX_WORDLIST_IO, &dwVal );
  216. Win4Assert( S_OK == sc );
  217. return dwVal;
  218. }
  219. const ULONG GetMinWordlistBattery()
  220. {
  221. DWORD dwVal;
  222. SCODE sc = _pCiAdminParams->GetValue(
  223. CI_AP_MIN_WORDLIST_BATTERY, &dwVal );
  224. Win4Assert( S_OK == sc );
  225. return dwVal;
  226. }
  227. const ULONG GetWordlistUserIdle()
  228. {
  229. DWORD dwVal;
  230. SCODE sc = _pCiAdminParams->GetValue(
  231. CI_AP_WORDLIST_USER_IDLE, &dwVal );
  232. Win4Assert( S_OK == sc );
  233. return dwVal;
  234. }
  235. const ULONG GetWordlistResourceCheckInterval()
  236. {
  237. DWORD dwVal;
  238. SCODE sc = _pCiAdminParams->GetValue(
  239. CI_AP_WORDLIST_RESOURCE_CHECK_INTERVAL, &dwVal );
  240. Win4Assert( S_OK == sc );
  241. return dwVal;
  242. }
  243. const ULONG GetStartupDelay()
  244. {
  245. DWORD dwVal;
  246. SCODE sc = _pCiAdminParams->GetValue(
  247. CI_AP_STARTUP_DELAY, &dwVal );
  248. Win4Assert( S_OK == sc );
  249. return dwVal;
  250. }
  251. const ULONG GetMaxFreshDeletes()
  252. {
  253. DWORD dwVal;
  254. SCODE sc = _pCiAdminParams->GetValue(
  255. CI_AP_MAX_FRESH_DELETES, &dwVal );
  256. Win4Assert( S_OK == sc );
  257. return dwVal;
  258. }
  259. const ULONG GetLowResourceSleep()
  260. {
  261. DWORD dwVal;
  262. SCODE sc = _pCiAdminParams->GetValue(
  263. CI_AP_LOW_RESOURCE_SLEEP, &dwVal );
  264. Win4Assert( S_OK == sc );
  265. return dwVal;
  266. }
  267. const ULONG GetMaxWordlistMemoryLoad()
  268. {
  269. DWORD dwVal;
  270. SCODE sc = _pCiAdminParams->GetValue(
  271. CI_AP_MAX_WORDLIST_MEMORY_LOAD, &dwVal );
  272. Win4Assert( S_OK == sc );
  273. return dwVal;
  274. }
  275. const ULONG GetMaxFreshCount()
  276. {
  277. DWORD dwVal;
  278. SCODE sc = _pCiAdminParams->GetValue(
  279. CI_AP_MAX_FRESH_COUNT, &dwVal );
  280. Win4Assert( S_OK == sc );
  281. return dwVal;
  282. }
  283. const ULONG GetMaxQueueChunks()
  284. {
  285. DWORD dwVal;
  286. SCODE sc = _pCiAdminParams->GetValue(
  287. CI_AP_MAX_QUEUE_CHUNKS, &dwVal );
  288. Win4Assert( S_OK == sc );
  289. return dwVal;
  290. }
  291. const ULONG GetMasterMergeCheckpointInterval()
  292. {
  293. DWORD dwVal;
  294. SCODE sc = _pCiAdminParams->GetValue(
  295. CI_AP_MASTER_MERGE_CHECKPOINT_INTERVAL, &dwVal );
  296. Win4Assert( S_OK == sc );
  297. return dwVal;
  298. }
  299. const ULONG GetFilterBufferSize()
  300. {
  301. DWORD dwVal;
  302. SCODE sc = _pCiAdminParams->GetValue(
  303. CI_AP_FILTER_BUFFER_SIZE, &dwVal );
  304. Win4Assert( S_OK == sc );
  305. return dwVal;
  306. }
  307. const ULONG GetFilterRetries()
  308. {
  309. DWORD dwVal;
  310. SCODE sc = _pCiAdminParams->GetValue(
  311. CI_AP_FILTER_RETRIES, &dwVal );
  312. Win4Assert( S_OK == sc );
  313. return dwVal;
  314. }
  315. const ULONG GetSecQFilterRetries()
  316. {
  317. DWORD dwVal;
  318. SCODE sc = _pCiAdminParams->GetValue(
  319. CI_AP_SECQ_FILTER_RETRIES, &dwVal );
  320. Win4Assert( S_OK == sc );
  321. return dwVal;
  322. }
  323. const ULONG GetFilterRetryInterval()
  324. {
  325. DWORD dwVal;
  326. SCODE sc = _pCiAdminParams->GetValue(
  327. CI_AP_FILTER_RETRY_INTERVAL, &dwVal );
  328. Win4Assert( S_OK == sc );
  329. return dwVal;
  330. }
  331. const ULONG GetMaxShadowIndexSize()
  332. {
  333. DWORD dwVal;
  334. SCODE sc = _pCiAdminParams->GetValue(
  335. CI_AP_MAX_SHADOW_INDEX_SIZE, &dwVal );
  336. Win4Assert( S_OK == sc );
  337. return dwVal;
  338. }
  339. const ULONG GetMinDiskFreeForceMerge()
  340. {
  341. DWORD dwVal;
  342. SCODE sc = _pCiAdminParams->GetValue(
  343. CI_AP_MIN_DISK_FREE_FORCE_MERGE, &dwVal );
  344. Win4Assert( S_OK == sc );
  345. return dwVal;
  346. }
  347. const ULONG GetMaxShadowFreeForceMerge()
  348. {
  349. DWORD dwVal;
  350. SCODE sc = _pCiAdminParams->GetValue(
  351. CI_AP_MAX_SHADOW_FREE_FORCE_MERGE, &dwVal );
  352. Win4Assert( S_OK == sc );
  353. return dwVal;
  354. }
  355. const ULONG GetMaxIndexes()
  356. {
  357. DWORD dwVal;
  358. SCODE sc = _pCiAdminParams->GetValue(
  359. CI_AP_MAX_INDEXES, &dwVal );
  360. Win4Assert( S_OK == sc );
  361. return dwVal;
  362. }
  363. const ULONG GetMaxIdealIndexes()
  364. {
  365. DWORD dwVal;
  366. SCODE sc = _pCiAdminParams->GetValue(
  367. CI_AP_MAX_IDEAL_INDEXES,
  368. &dwVal );
  369. Win4Assert( S_OK == sc );
  370. return dwVal;
  371. }
  372. const ULONG GetMinMergeIdleTime()
  373. {
  374. DWORD dwVal;
  375. SCODE sc = _pCiAdminParams->GetValue(
  376. CI_AP_MIN_MERGE_IDLE_TIME,
  377. &dwVal );
  378. Win4Assert( S_OK == sc );
  379. return dwVal;
  380. }
  381. const ULONG GetMaxPendingDocuments()
  382. {
  383. DWORD dwVal;
  384. SCODE sc = _pCiAdminParams->GetValue(
  385. CI_AP_MAX_PENDING_DOCUMENTS,
  386. &dwVal );
  387. Win4Assert( S_OK == sc );
  388. return dwVal;
  389. }
  390. const ULONG GetMinIdleQueryThreads()
  391. {
  392. DWORD dwVal;
  393. SCODE sc = _pCiAdminParams->GetValue(
  394. CI_AP_MIN_IDLE_QUERY_THREADS,
  395. &dwVal );
  396. Win4Assert( S_OK == sc );
  397. return dwVal;
  398. }
  399. const ULONG GetMaxActiveQueryThreads()
  400. {
  401. DWORD dwVal;
  402. SCODE sc = _pCiAdminParams->GetValue(
  403. CI_AP_MAX_ACTIVE_QUERY_THREADS,
  404. &dwVal );
  405. Win4Assert( S_OK == sc );
  406. return dwVal;
  407. }
  408. const ULONG GetMaxQueryTimeslice()
  409. {
  410. DWORD dwVal;
  411. SCODE sc = _pCiAdminParams->GetValue(
  412. CI_AP_MAX_QUERY_TIMESLICE,
  413. &dwVal );
  414. Win4Assert( S_OK == sc );
  415. return dwVal;
  416. }
  417. const ULONG GetMaxQueryExecutionTime()
  418. {
  419. DWORD dwVal;
  420. SCODE sc = _pCiAdminParams->GetValue(
  421. CI_AP_MAX_QUERY_EXECUTION_TIME,
  422. &dwVal );
  423. Win4Assert( S_OK == sc );
  424. return dwVal;
  425. }
  426. const ULONG GetMiscCiFlags()
  427. {
  428. DWORD dwVal;
  429. SCODE sc = _pCiAdminParams->GetValue(
  430. CI_AP_MISC_FLAGS,
  431. &dwVal );
  432. Win4Assert( S_OK == sc );
  433. return dwVal;
  434. }
  435. const ULONG GetMaxRestrictionNodes()
  436. {
  437. DWORD dwVal;
  438. SCODE sc = _pCiAdminParams->GetValue(
  439. CI_AP_MAX_RESTRICTION_NODES,
  440. &dwVal );
  441. Win4Assert( S_OK == sc );
  442. return dwVal;
  443. }
  444. const ULONG GetMaxDaemonVmUse()
  445. {
  446. DWORD dwVal;
  447. SCODE sc = _pCiAdminParams->GetValue(
  448. CI_AP_MAX_DAEMON_VM_USE,
  449. &dwVal );
  450. Win4Assert( S_OK == sc );
  451. return dwVal;
  452. }
  453. const BOOL IsEnumAllowed()
  454. {
  455. DWORD dwVal=0;
  456. SCODE sc = _pCiAdminParams->GetValue(
  457. CI_AP_IS_ENUM_ALLOWED,
  458. &dwVal);
  459. Win4Assert( S_OK == sc );
  460. if(dwVal)
  461. {
  462. return TRUE;
  463. }
  464. return FALSE ;
  465. }
  466. const ULONG GetMinDiskSpaceToLeave()
  467. {
  468. DWORD dwVal;
  469. SCODE sc = _pCiAdminParams->GetValue(
  470. CI_AP_MIN_DISK_SPACE_TO_LEAVE,
  471. &dwVal );
  472. Win4Assert( S_OK == sc );
  473. return dwVal;
  474. }
  475. const BOOL UseOle()
  476. {
  477. return FALSE;
  478. }
  479. const BOOL IsGenerateCharacterization()
  480. {
  481. return TRUE;
  482. }
  483. const ULONG GetEventLogFlags()
  484. {
  485. return 0;
  486. }
  487. private:
  488. ICiAdminParams * _pCiAdminParams;
  489. };
  490. //+---------------------------------------------------------------------------
  491. //
  492. // Class: CCiFrmPerfCounter
  493. //
  494. // Purpose: A performance counter using the framework ICiCAdviseStatus
  495. //
  496. // History: 12-09-96 srikants Created
  497. //
  498. // Notes:
  499. //
  500. //----------------------------------------------------------------------------
  501. class CCiFrmPerfCounter
  502. {
  503. public:
  504. CCiFrmPerfCounter( ICiCAdviseStatus * pAdviseStatus = 0,
  505. CI_PERF_COUNTER_NAME name = CI_PERF_TOTAL_QUERIES )
  506. : _xAdviseStatus( pAdviseStatus ),
  507. _name(name)
  508. {
  509. if ( 0 != pAdviseStatus )
  510. _xAdviseStatus->AddRef();
  511. }
  512. ~CCiFrmPerfCounter()
  513. {
  514. _xAdviseStatus.Free();
  515. }
  516. void SetAdviseStatus( ICiCAdviseStatus * pAdviseStatus )
  517. {
  518. _xAdviseStatus.Set( pAdviseStatus );
  519. _xAdviseStatus->AddRef();
  520. }
  521. void Update( CI_PERF_COUNTER_NAME name, long val )
  522. {
  523. _xAdviseStatus->SetPerfCounterValue( name, val );
  524. }
  525. void Update( long val )
  526. {
  527. Update( _name, val );
  528. }
  529. long GetCurrValue( CI_PERF_COUNTER_NAME name )
  530. {
  531. long val = 0;
  532. SCODE sc = _xAdviseStatus->GetPerfCounterValue( _name, &val );
  533. return S_OK == sc ? val : 0;
  534. }
  535. long GetCurrValue()
  536. {
  537. return GetCurrValue( _name );
  538. }
  539. private:
  540. XInterface<ICiCAdviseStatus> _xAdviseStatus;
  541. const CI_PERF_COUNTER_NAME _name;
  542. };
  543. //+---------------------------------------------------------------------------
  544. //
  545. // Class: CDiskFreeStatus
  546. //
  547. // Purpose: A class to monitor free space in a disk.
  548. //
  549. // History: 12-09-96 srikants Created
  550. // 01-Nov-98 KLam Added DiskSpaceToLeave to constructor
  551. // 20-Nov-98 KLam Added CDriveInfo private member
  552. //
  553. //----------------------------------------------------------------------------
  554. class CDiskFreeStatus
  555. {
  556. public:
  557. CDiskFreeStatus( WCHAR const * pwszPath, ULONG cMegToLeaveOnDisk )
  558. :_fIsLow(FALSE),
  559. _driveInfo ( pwszPath, cMegToLeaveOnDisk )
  560. {
  561. Win4Assert( pwszPath );
  562. }
  563. BOOL IsLow() const
  564. {
  565. return _fIsLow;
  566. }
  567. void UpdateDiskLowInfo();
  568. ULONG GetDiskSpaceToFree()
  569. {
  570. return highDiskWaterMark;
  571. }
  572. private:
  573. enum
  574. {
  575. lowDiskWaterMark = 3 * 512 * 1024, // 1.5 MB
  576. highDiskWaterMark = lowDiskWaterMark + 512 * 1024 // 2.0 MB
  577. };
  578. BOOL _fIsLow;
  579. CDriveInfo _driveInfo;
  580. };
  581. WCHAR * AllocHeapAndCopy( WCHAR const * pwszSrc, ULONG & cc );
  582. inline WCHAR * AllocHeapAndCopy( WCHAR const * pwszSrc )
  583. {
  584. ULONG cc;
  585. return AllocHeapAndCopy( pwszSrc, cc );
  586. }
  587. WCHAR * AllocHeapAndGetWString( PDeSerStream & stm );
  588. void PutWString( PSerStream & stm, WCHAR const * pwszStr );
  589. //+---------------------------------------------------------------------------
  590. //
  591. // Class: CFwPerfTime
  592. //
  593. // Purpose: A class analogous to CPerfTime but adapted to the framework.
  594. //
  595. // History: 1-07-97 srikants Created
  596. //
  597. // Notes: We don't AddRef and Release the ICiCAdviseStatus interface
  598. // here because we know it will not be deleted during the
  599. // existence of this class.
  600. //
  601. //----------------------------------------------------------------------------
  602. class CFwPerfTime
  603. {
  604. public:
  605. CFwPerfTime( ICiCAdviseStatus * pCiCAdviseStatus,
  606. CI_PERF_COUNTER_NAME name,
  607. int SizeDivisor=1,
  608. int TimeMultiplier=1 );
  609. ~CFwPerfTime() {}
  610. void TStart ();
  611. void TStop ( DWORD dwValue = 0 );
  612. private:
  613. LARGE_INTEGER _liStartTime;
  614. LONGLONG _llSizeDivisor;
  615. LONGLONG _llTimeMultiplier;
  616. long _counterVal;
  617. CI_PERF_COUNTER_NAME _name;
  618. ICiCAdviseStatus * _pAdviseStatus;
  619. };