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.

268 lines
7.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: frmutils.cxx
  7. //
  8. // Contents: Utility classes and functions for the frame work and
  9. // client code.
  10. //
  11. // History: 12-09-96 srikants Created
  12. // 20-Nov-98 KLam Removed CDiskFreeStatus::GetDiskSpace
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <frmutils.hxx>
  18. #include <sstream.hxx>
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Member: CDiskFreeStatus::UpdateDiskLowInfo
  22. //
  23. // Synopsis: Updates disk low state information by checking the
  24. // disk free space situation.
  25. //
  26. // History: 12-09-96 srikants Created
  27. // 20-Nov-98 KLam Call disk info GetDiskSpace
  28. //
  29. //----------------------------------------------------------------------------
  30. void CDiskFreeStatus::UpdateDiskLowInfo()
  31. {
  32. __int64 diskTotal, diskRemaining;
  33. _driveInfo.GetDiskSpace( diskTotal, diskRemaining );
  34. BOOL fLowOnDisk = FALSE;
  35. if ( !_fIsLow )
  36. {
  37. fLowOnDisk = diskRemaining < lowDiskWaterMark;
  38. }
  39. else
  40. {
  41. fLowOnDisk = diskRemaining < highDiskWaterMark;
  42. }
  43. //
  44. // It is okay to read it without mutex as it is only a heuristic.
  45. //
  46. if ( fLowOnDisk && !_fIsLow )
  47. {
  48. ciDebugOut(( DEB_WARN, "****YOU ARE RUNNING LOW ON DISK SPACE****\n"));
  49. ciDebugOut(( DEB_WARN, "****PLEASE FREE UP SOME SPACE ****\n"));
  50. }
  51. else if ( _fIsLow && !fLowOnDisk )
  52. {
  53. ciDebugOut(( DEB_WARN, "****DISK SPACE FREED UP ****\n"));
  54. }
  55. _fIsLow = fLowOnDisk;
  56. }
  57. //+---------------------------------------------------------------------------
  58. //
  59. // Function: AllocHeapAndCopy
  60. //
  61. // Synopsis: Allocates memory from heap and copies the source string into
  62. // the destination buffer. The destination buffer ownership
  63. // is given to the caller.
  64. //
  65. // Arguments: [pSrc] - [in] source string.
  66. // [cc] - [out] Number of characters in the string, excluding the
  67. // terminating NULL.
  68. //
  69. // History: 12-11-96 srikants Created
  70. //
  71. //----------------------------------------------------------------------------
  72. WCHAR * AllocHeapAndCopy( WCHAR const * pSrc, ULONG & cc )
  73. {
  74. WCHAR * pDst = 0;
  75. if ( 0 != pSrc )
  76. {
  77. cc = wcslen( pSrc );
  78. pDst = new WCHAR [cc+1];
  79. RtlCopyMemory( pDst, pSrc, (cc+1)*sizeof(WCHAR) );
  80. }
  81. else
  82. {
  83. cc = 0;
  84. }
  85. return pDst;
  86. }
  87. //+---------------------------------------------------------------------------
  88. //
  89. // Function: PutWString
  90. //
  91. // Synopsis: Serializes the given WCHAR string into the serializer.
  92. //
  93. // Arguments: [stm] - Serializer
  94. // [pwszStr] - String to serialize.
  95. //
  96. // History: 12-11-96 srikants Created
  97. //
  98. //----------------------------------------------------------------------------
  99. void PutWString( PSerStream & stm, WCHAR const * pwszStr )
  100. {
  101. ULONG cwc = (0 != pwszStr) ? wcslen( pwszStr ) : 0;
  102. stm.PutULong( cwc );
  103. if (cwc)
  104. stm.PutWChar( pwszStr, cwc );
  105. }
  106. //+---------------------------------------------------------------------------
  107. //
  108. // Function: AllocHeapAndGetWString
  109. //
  110. // Synopsis: DeSerizlizes a WCHAR string from the deserializer, allocates
  111. // memory and copies the string into it.
  112. //
  113. // Arguments: [stm] - DeSerializer Stream
  114. //
  115. // Returns: NULL if there was no string
  116. //
  117. // History: 12-11-96 srikants Created
  118. //
  119. //----------------------------------------------------------------------------
  120. WCHAR * AllocHeapAndGetWString( PDeSerStream & stm )
  121. {
  122. ULONG cwc = stm.GetULong();
  123. // Guard against attack
  124. if ( 0 == cwc || cwc > 65536 )
  125. {
  126. return 0;
  127. }
  128. WCHAR * pwszStr = new WCHAR [cwc+1];
  129. stm.GetWChar( pwszStr, cwc );
  130. pwszStr[cwc] = L'\0';
  131. return pwszStr;
  132. }
  133. //+---------------------------------------------------------------------------
  134. //
  135. // Function : CFwPerfTime::CFwPerfTime
  136. //
  137. // Purpose : Constructor
  138. //
  139. // Arguments : [SizeDivisor] -- Raw (byte) size divided by this.
  140. // [TimeMultiplier] -- Raw (millisecond) time multiplied by this.
  141. //
  142. // History : 23-Mar-94 t-joshh Created
  143. // 31-Jan-95 KyleP Added unit adjustment
  144. // 06-Jan-97 Srikants Adapted to framework
  145. //
  146. //----------------------------------------------------------------------------
  147. CFwPerfTime::CFwPerfTime ( ICiCAdviseStatus * pAdviseStatus,
  148. CI_PERF_COUNTER_NAME name,
  149. int SizeDivisor, int TimeMultiplier )
  150. : _llSizeDivisor( SizeDivisor ),
  151. _llTimeMultiplier( TimeMultiplier ),
  152. _counterVal(0),
  153. _name(name),
  154. _pAdviseStatus(pAdviseStatus)
  155. {
  156. _liStartTime.QuadPart = 0;
  157. Win4Assert( _llSizeDivisor > 0 );
  158. Win4Assert( _llTimeMultiplier > 0 );
  159. }
  160. //+---------------------------------------------------------------------------
  161. //
  162. // Function : CFwPerfTime::TStart
  163. //
  164. // Purpose : Start counting the time
  165. //
  166. // Arguments : none
  167. //
  168. // History : 23-March-94 t-joshh Created
  169. //
  170. //----------------------------------------------------------------------------
  171. void CFwPerfTime::TStart ()
  172. {
  173. _liStartTime.LowPart = GetTickCount();
  174. }
  175. //+---------------------------------------------------------------------------
  176. //
  177. // Function : CFwPerfTime::TStop
  178. //
  179. // Purpose : Stop counting the time and evaluate the result
  180. //
  181. // Arguments : [dwValue]
  182. //
  183. // History : 23-March-94 t-joshh Created
  184. //
  185. //----------------------------------------------------------------------------
  186. void CFwPerfTime::TStop( DWORD dwValue )
  187. {
  188. LARGE_INTEGER liStop;
  189. liStop.LowPart = GetTickCount();
  190. ULONG ulDiff = liStop.LowPart - _liStartTime.LowPart;
  191. LARGE_INTEGER liVal;
  192. //
  193. // If the time difference is negative, then use the value from
  194. // the perfmon data.
  195. //
  196. if ( ulDiff <= 0 )
  197. {
  198. SCODE sc = _pAdviseStatus->GetPerfCounterValue( _name, &_counterVal );
  199. if ( FAILED(sc) )
  200. {
  201. ciDebugOut(( DEB_ERROR, "GetPerfCounterValue failed (0x%X)\n",
  202. sc ));
  203. return;
  204. }
  205. }
  206. if ( dwValue > 0 )
  207. {
  208. if ( ulDiff > 0 )
  209. liVal.QuadPart = dwValue / ulDiff;
  210. else
  211. liVal.QuadPart = _counterVal * _llSizeDivisor / _llTimeMultiplier;
  212. }
  213. else
  214. {
  215. if ( ulDiff > 0 )
  216. liVal.QuadPart = ulDiff;
  217. else
  218. liVal.QuadPart = _counterVal * _llSizeDivisor / _llTimeMultiplier;
  219. }
  220. liVal.QuadPart = liVal.QuadPart * _llTimeMultiplier / _llSizeDivisor;
  221. Win4Assert( liVal.HighPart == 0 );
  222. _counterVal = liVal.LowPart;
  223. SCODE sc = _pAdviseStatus->SetPerfCounterValue( _name, _counterVal );
  224. if ( FAILED(sc) )
  225. {
  226. ciDebugOut(( DEB_ERROR, "SetPerfCounterValue failed (0x%X)\n",
  227. sc ));
  228. }
  229. }