Source code of Windows XP (NT5)
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.

957 lines
26 KiB

  1. //==========================================================================//
  2. // Includes //
  3. //==========================================================================//
  4. #include "setedit.h" // included by all source files
  5. #include "line.h" // external declarations for this file
  6. //#include <tchar.h> // for _tcsncpy
  7. #include "fileutil.h" // for FileRead, FileWrite
  8. #include "pmemory.h" // for MemoryXXX (mallloc-type) routines
  9. #include "perfdata.h" // for UpdateSystemData, et al
  10. #include "perfmops.h" // for InsertLine
  11. #include "system.h" // for SystemAdd
  12. #include "utils.h"
  13. #include "counters.h" // CounterEntry
  14. #include <string.h> // for strncpy
  15. #ifdef UNICODE
  16. #define _tcsncpy wcsncpy
  17. #else
  18. #define _tcsncpy strncpy
  19. #endif
  20. TCHAR LOCAL_SYS_CODE_NAME[] = TEXT("....") ;
  21. #define sizeofCodeName sizeof(LOCAL_SYS_CODE_NAME) / sizeof(TCHAR) - 1
  22. // Local Function prototype
  23. PLINE ReadLine (PPERFSYSTEM *ppSystem,
  24. PPPERFSYSTEM ppSystemFirst,
  25. PPERFDATA *ppPerfData,
  26. HANDLE hFile,
  27. int LineType,
  28. PDISKLINE *ppDiskLine,
  29. DWORD *pSizeofDiskLine) ;
  30. //==========================================================================//
  31. // Exported Functions //
  32. //==========================================================================//
  33. PLINE LineAllocate (void)
  34. /*
  35. Effect: Allocate and initialize a Line data structure. Lines
  36. are used as the primary elements of both charts and
  37. alerts.
  38. Establish any representation invariants for the Line
  39. type.
  40. Also alllocate another structure, an array of data
  41. elements, iNumDataValues long.
  42. */
  43. { // LineAllocate
  44. PLINE pLine ;
  45. pLine = MemoryAllocate (sizeof (LINESTRUCT)) ;
  46. if (pLine) {
  47. // don't need to zero these again since MemoryAllocate is using
  48. // GMEM_ZEROPOINT
  49. // pLine->pLineNext = NULL ;
  50. // pLine->pLineCounterNext = NULL ;
  51. // do want to do this since (FLOAT)0.0 is not 0
  52. pLine->lnMinValue =
  53. pLine->lnMaxValue =
  54. pLine->lnAveValue = (FLOAT) 0.0 ;
  55. // we want to take 2 samples before plotting the first data
  56. pLine->bFirstTime = 2 ;
  57. } // if
  58. return (pLine) ;
  59. } // LineAllocate
  60. void LineFree (PLINE pLine)
  61. { // LineFree
  62. // free any memory allocated by this line
  63. if (pLine->lnSystemName)
  64. MemoryFree (pLine->lnSystemName) ;
  65. if (pLine->lnObjectName)
  66. MemoryFree (pLine->lnObjectName) ;
  67. if (pLine->lnCounterName)
  68. MemoryFree (pLine->lnCounterName) ;
  69. if (pLine->lnInstanceName)
  70. MemoryFree (pLine->lnInstanceName) ;
  71. if (pLine->lnParentObjName)
  72. MemoryFree (pLine->lnParentObjName) ;
  73. if (pLine->lnPINName)
  74. MemoryFree (pLine->lnPINName) ;
  75. if (pLine->lpszAlertProgram)
  76. MemoryFree (pLine->lpszAlertProgram) ;
  77. if (pLine->hPen)
  78. DeletePen(pLine->hPen);
  79. if (pLine->hBrush)
  80. DeletePen(pLine->hBrush);
  81. #if 0
  82. if (pLine->lnValues)
  83. MemoryFree (pLine->lnValues) ;
  84. if (pLine->aiLogIndexes)
  85. MemoryFree (pLine->aiLogIndexes) ;
  86. #endif
  87. MemoryFree (pLine) ;
  88. } // LineFree
  89. void LineAppend (PPLINE ppLineFirst,
  90. PLINE pLineNew)
  91. {
  92. PLINE pLine ;
  93. if (!*ppLineFirst)
  94. *ppLineFirst = pLineNew ;
  95. else { // else
  96. for (pLine = *ppLineFirst ;
  97. pLine->pLineNext ;
  98. pLine = pLine->pLineNext)
  99. /* nothing */ ;
  100. pLine->pLineNext = pLineNew ;
  101. } // else
  102. }
  103. BOOL LineRemove (PPLINE ppLineFirst,
  104. PLINE pLineRemove)
  105. {
  106. PLINE pLine ;
  107. if (*ppLineFirst == pLineRemove) {
  108. *ppLineFirst = (*ppLineFirst)->pLineNext ;
  109. return (TRUE) ;
  110. }
  111. for (pLine = *ppLineFirst ;
  112. pLine->pLineNext ;
  113. pLine = pLine->pLineNext) { // for
  114. if (pLine->pLineNext == pLineRemove) {
  115. pLine->pLineNext = pLineRemove->pLineNext ;
  116. return (TRUE) ;
  117. } // if
  118. } // for
  119. return (FALSE) ;
  120. } // LineRemove
  121. int NumLines (PLINE pLineFirst)
  122. { // NumLines
  123. PLINE pLine ;
  124. int iNumLines ;
  125. if (!pLineFirst)
  126. return (0) ;
  127. iNumLines = 0 ;
  128. for (pLine = pLineFirst ;
  129. pLine ;
  130. pLine = pLine->pLineNext) { // for
  131. iNumLines++ ;
  132. } // for
  133. return (iNumLines) ;
  134. } // NumLines
  135. LPTSTR LineInstanceName (PLINE pLine)
  136. {
  137. if (pLine->lnObject.NumInstances <= 0)
  138. return (NULL) ;
  139. else
  140. return (pLine->lnInstanceName) ;
  141. }
  142. LPTSTR LineParentName (PLINE pLine)
  143. {
  144. if (pLine->lnObject.NumInstances <= 0)
  145. return (NULL) ;
  146. else if (pLine->lnInstanceDef.ParentObjectTitleIndex)
  147. return (pLine->lnPINName) ;
  148. else
  149. return (NULL) ;
  150. }
  151. void LineCounterAppend (PPLINE ppLineFirst,
  152. PLINE pLineNew)
  153. {
  154. PLINE pLine ;
  155. if (!*ppLineFirst)
  156. *ppLineFirst = pLineNew ;
  157. else { // else
  158. for (pLine = *ppLineFirst ;
  159. pLine->pLineCounterNext ;
  160. pLine = pLine->pLineCounterNext)
  161. /* nothing */ ;
  162. pLine->pLineCounterNext = pLineNew ;
  163. } // else
  164. }
  165. BOOL EquivalentLine (PLINE pLine1,
  166. PLINE pLine2)
  167. { // LineEquivalent
  168. return (pstrsame (pLine1->lnCounterName, pLine2->lnCounterName) &&
  169. pstrsame (pLine1->lnInstanceName, pLine2->lnInstanceName) &&
  170. pstrsame (pLine1->lnPINName, pLine2->lnPINName) &&
  171. pstrsame (pLine1->lnObjectName, pLine2->lnObjectName) &&
  172. pstrsamei (pLine1->lnSystemName, pLine2->lnSystemName)) ;
  173. } // LineEquivalent
  174. PLINE FindEquivalentLine (PLINE pLineToFind,
  175. PLINE pLineFirst)
  176. {
  177. PLINE pLine ;
  178. for (pLine = pLineFirst ;
  179. pLine ;
  180. pLine = pLine->pLineNext) { // for
  181. if (EquivalentLine (pLine, pLineToFind))
  182. return (pLine) ;
  183. } // for
  184. return (NULL) ;
  185. } // FindEquivalentLine
  186. // This routine is used only to read the system name from a disk string
  187. // It is mainly for performance improvement.
  188. LPTSTR DiskStringReadSys (PDISKSTRING pDS)
  189. { // DiskStringReadSys
  190. LPTSTR lpszText ;
  191. LPTSTR pDiskSysName ;
  192. int iIndex ;
  193. BOOL bLocalSysName = FALSE ;
  194. if (pDS->dwLength == 0) {
  195. return (NULL) ;
  196. }
  197. if (pDS->dwLength == sizeofCodeName) {
  198. // check for LOCAL_SYS_CODE_NAME
  199. bLocalSysName = TRUE ;
  200. pDiskSysName = (LPTSTR)((PBYTE) pDS + pDS->dwOffset) ;
  201. for (iIndex = 0 ; iIndex < sizeofCodeName; iIndex++, pDiskSysName++) {
  202. if (*pDiskSysName != LOCAL_SYS_CODE_NAME[iIndex]) {
  203. bLocalSysName = FALSE ;
  204. break ;
  205. }
  206. }
  207. }
  208. if (bLocalSysName) {
  209. lpszText =
  210. MemoryAllocate ((lstrlen(LocalComputerName)+1) * sizeof(TCHAR)) ;
  211. if (lpszText) {
  212. lstrcpy (lpszText, LocalComputerName) ;
  213. }
  214. } else {
  215. lpszText = MemoryAllocate (sizeof (TCHAR) * (pDS->dwLength + 1)) ;
  216. if (lpszText) {
  217. _tcsncpy ((WCHAR *)lpszText, (WCHAR *)((PBYTE) pDS + pDS->dwOffset),
  218. pDS->dwLength) ;
  219. }
  220. }
  221. return (lpszText) ;
  222. } // DiskStringReadSys
  223. LPTSTR DiskStringRead (PDISKSTRING pDS)
  224. { // DiskStringRead
  225. LPTSTR lpszText ;
  226. if (pDS->dwLength == 0) {
  227. return (NULL) ;
  228. }
  229. lpszText = MemoryAllocate (sizeof (TCHAR) * (pDS->dwLength + 1)) ;
  230. if (!lpszText) {
  231. return (NULL) ;
  232. }
  233. _tcsncpy ((WCHAR *)lpszText, (WCHAR *)((PBYTE) pDS + pDS->dwOffset),
  234. pDS->dwLength) ;
  235. return (lpszText) ;
  236. } // DiskStringRead
  237. int DiskStringLength (LPTSTR lpszText)
  238. {
  239. if (!lpszText)
  240. return (0) ;
  241. else
  242. return (lstrlen (lpszText)) ;
  243. }
  244. PBYTE DiskStringCopy (PDISKSTRING pDS, LPTSTR lpszText, PBYTE pNextFree)
  245. {
  246. if (!lpszText) {
  247. pDS->dwOffset = 0 ;
  248. pDS->dwLength = 0 ;
  249. return (pNextFree) ;
  250. } else {
  251. pDS->dwOffset = (DWORD)(pNextFree - (PBYTE) pDS) ;
  252. pDS->dwLength = DiskStringLength (lpszText) ;
  253. _tcsncpy ((WCHAR *)pNextFree, (WCHAR *)lpszText, pDS->dwLength) ;
  254. return (pNextFree + pDS->dwLength * sizeof(TCHAR)) ;
  255. }
  256. } // DiskStringCopy
  257. void CounterName (PPERFSYSTEM pSystem,
  258. PPERFCOUNTERDEF pCounter,
  259. LPTSTR lpszCounter)
  260. { // CounterName
  261. //!! strclr (lpszCounter) ;
  262. lpszCounter [0] = TEXT('\0') ;
  263. QueryPerformanceName (pSystem,
  264. pCounter->CounterNameTitleIndex,
  265. 0, 256,
  266. lpszCounter,
  267. FALSE) ;
  268. } // CounterName
  269. PERF_OBJECT_TYPE UNALIGNED *
  270. LineFindObject (PPERFSYSTEM pSystem,
  271. PPERFDATA pPerfData,
  272. PLINE pLine)
  273. /*
  274. Effect: Set the lnObject field of pLine to the object with the
  275. name of lnObjectName, and return TRUE. Return FALSE if
  276. there is no such object.
  277. */
  278. { // LineFindObject
  279. PERF_OBJECT_TYPE UNALIGNED *pObject ;
  280. pObject = (PERF_OBJECT_TYPE UNALIGNED *)GetObjectDefByName (pSystem, pPerfData, pLine->lnObjectName) ;
  281. if (pObject) {
  282. pLine->lnObject = *pObject ;
  283. return (pObject) ;
  284. } else
  285. return (NULL) ;
  286. } // LineFindObject
  287. PPERFCOUNTERDEF LineFindCounter (PPERFSYSTEM pSystem,
  288. PERF_OBJECT_TYPE UNALIGNED *pObject,
  289. PPERFDATA pPerfData,
  290. PLINE pLine)
  291. { // LineFindCounter
  292. UINT i ;
  293. PPERFCOUNTERDEF pCounter ;
  294. TCHAR szCounter [256] ;
  295. for (i = 0, pCounter = FirstCounter (pObject) ;
  296. i < pObject->NumCounters ;
  297. i++, pCounter = NextCounter (pCounter)) { // for
  298. CounterName (pSystem, pCounter, szCounter) ;
  299. if (strsame (szCounter, pLine->lnCounterName)) {
  300. pLine->lnCounterDef = *pCounter ;
  301. return (pCounter) ;
  302. } // if
  303. } // for
  304. return (NULL) ;
  305. } // LineFindCounter
  306. PPERFINSTANCEDEF LineFindInstance (PPERFDATA pPerfData,
  307. PERF_OBJECT_TYPE UNALIGNED *pObject,
  308. PLINE pLine)
  309. { // LineFindInstance
  310. PPERFINSTANCEDEF pInstance = NULL ;
  311. if ((pObject->NumInstances > 0) && pLine->lnInstanceName) {
  312. // instances exist, find the right one
  313. if (pLine->lnUniqueID != PERF_NO_UNIQUE_ID) {
  314. pInstance = GetInstanceByUniqueID(pObject, pLine->lnUniqueID,
  315. pLine->dwInstanceIndex) ;
  316. } else {
  317. pInstance = GetInstanceByName(pPerfData, pObject,
  318. pLine->lnInstanceName, pLine->lnPINName,
  319. pLine->dwInstanceIndex) ;
  320. }
  321. }
  322. if (pInstance) {
  323. pLine->lnInstanceDef = *pInstance ;
  324. }
  325. return (pInstance) ;
  326. } // LineFindInstance
  327. void ReadLines (HANDLE hFile,
  328. DWORD dwNumLines,
  329. PPPERFSYSTEM ppSystemFirst,
  330. PPLINE ppLineFirst,
  331. int LineType)
  332. {
  333. DWORD i ;
  334. PPERFDATA pPerfData ;
  335. PLINE pLine ;
  336. PPERFSYSTEM pSystem ;
  337. PDISKLINE pDiskLine = NULL ;
  338. DWORD SizeofDiskLine = 0 ; // bytes in pDiskLine
  339. pPerfData = AllocatePerfData () ;
  340. pSystem = *ppSystemFirst ;
  341. #if 0
  342. if (!pSystem) {
  343. pSystem = SystemAdd (ppSystemFirst, LocalComputerName, NULL) ;
  344. pSystem = *ppSystemFirst ; //!!
  345. }
  346. UpdateSystemData (pSystem, &pPerfData) ;
  347. #endif
  348. pDiskLine = MemoryAllocate (FilePathLen) ;
  349. if (!pDiskLine) {
  350. // no memory to begin with, forget it
  351. DlgErrorBox (hWndMain, ERR_NO_MEMORY) ;
  352. return ;
  353. }
  354. SizeofDiskLine = FilePathLen ;
  355. for (i = 0 ;
  356. i < dwNumLines ;
  357. i++) {
  358. pLine = ReadLine (&pSystem, ppSystemFirst, &pPerfData, hFile,
  359. LineType, &pDiskLine, &SizeofDiskLine) ;
  360. if (pLine)
  361. InsertLine (pLine) ;
  362. }
  363. if (pDiskLine) {
  364. MemoryFree (pDiskLine);
  365. }
  366. MemoryFree (pPerfData) ;
  367. } // ReadLines
  368. void LineSetCounter (PLINE pLine,
  369. PPERFSYSTEM pSystem,
  370. PPERFCOUNTERDEF pCounter,
  371. PPERFINSTANCEDEF pInstance)
  372. /*
  373. Effect: Set the counter-specific portions of pLine to point to
  374. the desired counter.
  375. Called By: AddLine, ReadLine.
  376. */
  377. {
  378. }
  379. PLINE ReadLine (PPERFSYSTEM *ppSystem,
  380. PPPERFSYSTEM ppSystemFirst,
  381. PPERFDATA *ppPerfData,
  382. HANDLE hFile,
  383. int LineType,
  384. PDISKLINE *ppDiskLine,
  385. DWORD *pSizeofDiskLine)
  386. /*
  387. Effect: Read in a line from the file hFile, at the current file
  388. position.
  389. Internals: The very first characters are a line signature, then a
  390. length integer. If the signature is correct, then allocate
  391. the length amount, and work with that.
  392. */
  393. { // ReadLine
  394. PLINE pLine ;
  395. struct {
  396. DWORD dwSignature ;
  397. DWORD dwLength ;
  398. } LineHeader ;
  399. PERF_OBJECT_TYPE UNALIGNED *pObject ;
  400. PPERFCOUNTERDEF pCounter ;
  401. PDISKLINE pDiskLine ; // Local copy of the pointer
  402. #ifdef KEEP_IT
  403. int i ;
  404. int iCounterIndex ;
  405. int j ;
  406. PERF_COUNTER_BLOCK *pCounterBlock ;
  407. #endif
  408. PPERFINSTANCEDEF pInstance ;
  409. // PPERFINSTANCEDEF pInstanceParent ;
  410. // TCHAR szInstanceParent [256] ;
  411. // TCHAR szObjectParent [PerfObjectLen] ;
  412. pLine = NULL ;
  413. //=============================//
  414. // read and compare signature //
  415. //=============================//
  416. if (!FileRead (hFile, &LineHeader, sizeof (LineHeader)))
  417. return (NULL) ;
  418. if (LineHeader.dwSignature != dwLineSignature ||
  419. LineHeader.dwLength == 0) {
  420. SetLastError (ERROR_BAD_FORMAT) ;
  421. return (NULL) ;
  422. }
  423. //=============================//
  424. // read and allocate length //
  425. //=============================//
  426. // if (!FileRead (hFile, &dwLength, sizeof (dwLength)) || dwLength == 0)
  427. // return (NULL) ;
  428. // check if we need a bigger buffer,
  429. // normally, it should be the same except the first time...
  430. if (LineHeader.dwLength > *pSizeofDiskLine) {
  431. if (*ppDiskLine) {
  432. // free the previous buffer
  433. MemoryFree (*ppDiskLine);
  434. *pSizeofDiskLine = 0 ;
  435. }
  436. // re-allocate a new buffer
  437. *ppDiskLine = (PDISKLINE) MemoryAllocate (LineHeader.dwLength) ;
  438. if (!(*ppDiskLine)) {
  439. // no memory, should flag an error...
  440. return (NULL) ;
  441. }
  442. *pSizeofDiskLine = LineHeader.dwLength ;
  443. }
  444. pDiskLine = *ppDiskLine ;
  445. //=============================//
  446. // copy diskline, alloc line //
  447. //=============================//
  448. if (!FileRead (hFile, pDiskLine, LineHeader.dwLength))
  449. return (NULL) ;
  450. pLine = LineAllocate () ;
  451. if (!pLine) {
  452. return (NULL) ;
  453. }
  454. pLine->iLineType = pDiskLine->iLineType ;
  455. //=============================//
  456. // convert system information //
  457. //=============================//
  458. pLine->lnSystemName = DiskStringReadSys (&(pDiskLine->dsSystemName)) ;
  459. if (!pLine->lnSystemName)
  460. goto ErrorBadLine ;
  461. if (!*ppSystem || !strsamei (pLine->lnSystemName, (*ppSystem)->sysName)) {
  462. *ppSystem = SystemAdd (ppSystemFirst, pLine->lnSystemName, NULL) ;
  463. if (!*ppSystem) {
  464. SetLastError (ERROR_BAD_FORMAT) ;
  465. goto ErrorBadLine ;
  466. }
  467. UpdateSystemData (*ppSystem, ppPerfData) ;
  468. } // if
  469. //=============================//
  470. // convert object information //
  471. //=============================//
  472. pLine->lnObjectName = DiskStringRead (&(pDiskLine->dsObjectName)) ;
  473. if (!pLine->lnObjectName)
  474. goto ErrorBadLine ;
  475. pObject = LineFindObject (*ppSystem, *ppPerfData, pLine) ;
  476. if (!pObject) {
  477. SetLastError (ERROR_BAD_FORMAT) ;
  478. goto ErrorBadLine ;
  479. }
  480. //=============================//
  481. // convert counter information //
  482. //=============================//
  483. pLine->lnCounterName = DiskStringRead (&(pDiskLine->dsCounterName)) ;
  484. if (!pLine->lnCounterName)
  485. goto ErrorBadLine ;
  486. pCounter = LineFindCounter (*ppSystem, pObject, *ppPerfData, pLine) ;
  487. if (!pCounter) {
  488. SetLastError (ERROR_BAD_FORMAT) ;
  489. goto ErrorBadLine ;
  490. }
  491. //=============================//
  492. // convert instance info //
  493. //=============================//
  494. pLine->lnUniqueID = pDiskLine->dwUniqueID ;
  495. pLine->lnInstanceName = DiskStringRead (&(pDiskLine->dsInstanceName)) ;
  496. pLine->lnPINName = DiskStringRead (&(pDiskLine->dsPINName)) ;
  497. if (pLine->lnObject.NumInstances > 0 &&
  498. pLine->lnInstanceName == NULL) {
  499. goto ErrorBadLine ;
  500. }
  501. pInstance = LineFindInstance (*ppPerfData, pObject, pLine) ;
  502. if (pInstance) {
  503. pLine->lnParentObjName = DiskStringRead (&(pDiskLine->dsParentObjName)) ;
  504. } else {
  505. pLine->bUserEdit = TRUE ;
  506. pLine->lnParentObjName = DiskStringRead (&(pDiskLine->dsParentObjName)) ;
  507. }
  508. //=============================//
  509. // convert chart information //
  510. //=============================//
  511. if (LineType == IDM_VIEWCHART) {
  512. pLine->Visual = pDiskLine->Visual ;
  513. pLine->hPen = CreatePen (pLine->Visual.iStyle,
  514. pLine->Visual.iWidth,
  515. pLine->Visual.crColor) ;
  516. pLine->iScaleIndex = pDiskLine->iScaleIndex ;
  517. pLine->eScale = pDiskLine->eScale ;
  518. }
  519. //=============================//
  520. // convert alert information //
  521. //=============================//
  522. if (LineType == IDM_VIEWALERT) {
  523. pLine->Visual = pDiskLine->Visual ;
  524. pLine->hBrush = CreateSolidBrush (pLine->Visual.crColor) ;
  525. pLine->bAlertOver = pDiskLine->bAlertOver ;
  526. pLine->eAlertValue = pDiskLine->eAlertValue ;
  527. pLine->lpszAlertProgram = DiskStringRead (&(pDiskLine->dsAlertProgram)) ;
  528. pLine->bEveryTime = pDiskLine->bEveryTime ;
  529. pLine->bAlerted = FALSE ;
  530. }
  531. //=============================//
  532. // Convert the nasty stuff //
  533. //=============================//
  534. pLine->lnCounterType = pCounter->CounterType;
  535. pLine->lnCounterLength = pCounter->CounterSize;
  536. // we don't need these line info since we will get it
  537. // from the first couple clock ticks...
  538. // If we decide to keep these line, just define KEEP_IT
  539. #ifdef KEEP_IT
  540. pLine->lnOldTime = (*ppPerfData)->PerfTime ;
  541. pLine->lnNewTime = (*ppPerfData)->PerfTime ;
  542. pLine->lnOldTime100Ns = (*ppPerfData)->PerfTime100nSec ;
  543. pLine->lnNewTime100Ns = (*ppPerfData)->PerfTime100nSec;
  544. pLine->lnPerfFreq = (*ppPerfData)->PerfFreq ;
  545. for (j = 0 ; j < 2 ; j++) {
  546. pLine->lnaCounterValue[j].LowPart = 0 ;
  547. pLine->lnaCounterValue[j].HighPart = 0 ;
  548. }
  549. if (pObject->NumInstances > 0 && pInstance) {
  550. pCounterBlock = (PERF_COUNTER_BLOCK *) ( (PBYTE) pInstance +
  551. pInstance->ByteLength);
  552. } else {
  553. pCounterBlock = (PERF_COUNTER_BLOCK *) ( (PBYTE) pObject +
  554. pObject->DefinitionLength);
  555. }
  556. if (pLine->lnCounterLength <= 4)
  557. pLine->lnaOldCounterValue[0].LowPart =
  558. * ( (DWORD FAR *) ( (PBYTE)pCounterBlock +
  559. pCounter[0].CounterOffset));
  560. else {
  561. pLine->lnaOldCounterValue[0] =
  562. * ( (LARGE_INTEGER *) ( (PBYTE)pCounterBlock +
  563. pCounter[0].CounterOffset));
  564. }
  565. // Get second counter, only if we are not at
  566. // the end of the counters; some computations
  567. // require a second counter
  568. iCounterIndex = CounterIndex (pCounter, pObject) ;
  569. if ((UINT) iCounterIndex < pObject->NumCounters - 1 &&
  570. iCounterIndex != -1) {
  571. if (pLine->lnCounterLength <= 4)
  572. pLine->lnaOldCounterValue[1].LowPart =
  573. * ( (DWORD FAR *) ( (PBYTE)pCounterBlock +
  574. pCounter[1].CounterOffset));
  575. else
  576. pLine->lnaOldCounterValue[1] =
  577. * ( (LARGE_INTEGER *) ( (PBYTE)pCounterBlock +
  578. pCounter[1].CounterOffset));
  579. }
  580. // pLine->valNext = CounterFuncEntry ;
  581. pLine->valNext = CounterEntry ;
  582. pLine->lnaOldCounterValue[0] = pLine->lnaCounterValue[0];
  583. pLine->lnaOldCounterValue[1] = pLine->lnaCounterValue[1];
  584. #endif // KEEP_IT
  585. // pLine->valNext = CounterFuncEntry ;
  586. pLine->valNext = CounterEntry ;
  587. return (pLine) ;
  588. ErrorBadLine:
  589. if (!pLine) {
  590. LineFree (pLine) ;
  591. }
  592. return (NULL) ;
  593. } // ReadLine
  594. BOOL WriteLine (PLINE pLine,
  595. HANDLE hFile)
  596. { // WriteLine
  597. PDISKLINE pDiskLine ;
  598. DWORD dwSignature ;
  599. DWORD dwLength ;
  600. PBYTE pNextFree ;
  601. BOOL bConvertName ;
  602. //=============================//
  603. // write signature //
  604. //=============================//
  605. dwSignature = dwLineSignature ;
  606. if (!FileWrite (hFile, &dwSignature, sizeof (dwSignature)))
  607. return (FALSE) ;
  608. if (IsLocalComputer(pLine->lnSystemName)) {
  609. bConvertName = TRUE ;
  610. } else {
  611. bConvertName = FALSE ;
  612. }
  613. //=============================//
  614. // compute and allocate length //
  615. //=============================//
  616. dwLength = sizeof (DISKLINE) ;
  617. if (bConvertName) {
  618. dwLength += DiskStringLength (LOCAL_SYS_CODE_NAME) * sizeof (TCHAR) ;
  619. } else {
  620. dwLength += DiskStringLength (pLine->lnSystemName) * sizeof (TCHAR) ;
  621. }
  622. dwLength += DiskStringLength (pLine->lnObjectName) * sizeof (TCHAR) ;
  623. dwLength += DiskStringLength (pLine->lnCounterName) * sizeof (TCHAR) ;
  624. dwLength += DiskStringLength (pLine->lnInstanceName) * sizeof (TCHAR) ;
  625. dwLength += DiskStringLength (pLine->lnPINName) * sizeof (TCHAR) ;
  626. dwLength += DiskStringLength (pLine->lnParentObjName) * sizeof (TCHAR) ;
  627. dwLength += DiskStringLength (pLine->lpszAlertProgram) * sizeof (TCHAR) ;
  628. if (!FileWrite (hFile, &dwLength, sizeof (dwLength)))
  629. return (FALSE) ;
  630. pDiskLine = (PDISKLINE) MemoryAllocate (dwLength) ;
  631. if (!pDiskLine)
  632. return (FALSE) ;
  633. pNextFree = (PBYTE) pDiskLine + sizeof (DISKLINE) ;
  634. //=============================//
  635. // convert fixed size fields //
  636. //=============================//
  637. pDiskLine->iLineType = pLine->iLineType ;
  638. pDiskLine->dwUniqueID = pLine->lnUniqueID ;
  639. pDiskLine->Visual = pLine->Visual ;
  640. pDiskLine->iScaleIndex = pLine->iScaleIndex ;
  641. pDiskLine->eScale = pLine->eScale ;
  642. pDiskLine->bAlertOver = pLine->bAlertOver ;
  643. pDiskLine->eAlertValue = pLine->eAlertValue ;
  644. pDiskLine->bEveryTime = pLine->bEveryTime ;
  645. //=============================//
  646. // copy disk string fields //
  647. //=============================//
  648. if (bConvertName) {
  649. pNextFree = DiskStringCopy (&pDiskLine->dsSystemName,
  650. LOCAL_SYS_CODE_NAME,
  651. pNextFree) ;
  652. } else {
  653. pNextFree = DiskStringCopy (&pDiskLine->dsSystemName,
  654. pLine->lnSystemName,
  655. pNextFree) ;
  656. }
  657. pNextFree = DiskStringCopy (&pDiskLine->dsObjectName,
  658. pLine->lnObjectName,
  659. pNextFree) ;
  660. pNextFree = DiskStringCopy (&pDiskLine->dsCounterName,
  661. pLine->lnCounterName,
  662. pNextFree) ;
  663. pNextFree = DiskStringCopy (&pDiskLine->dsParentObjName,
  664. pLine->lnParentObjName,
  665. pNextFree) ;
  666. pNextFree = DiskStringCopy (&pDiskLine->dsInstanceName,
  667. pLine->lnInstanceName,
  668. pNextFree) ;
  669. pNextFree = DiskStringCopy (&pDiskLine->dsPINName,
  670. pLine->lnPINName,
  671. pNextFree) ;
  672. pNextFree = DiskStringCopy (&pDiskLine->dsAlertProgram,
  673. pLine->lpszAlertProgram,
  674. pNextFree) ;
  675. FileWrite (hFile, pDiskLine, dwLength) ;
  676. MemoryFree (pDiskLine) ;
  677. return (TRUE) ;
  678. //ErrorBadLine:
  679. MemoryFree (pDiskLine) ;
  680. return (FALSE) ;
  681. } // WriteLine
  682. // we are not doing printing. In case we need this
  683. // later, then define DO_PRINTING
  684. #ifdef DO_PRINTING
  685. int aiPrinterLineStyles [] =
  686. {
  687. PS_SOLID,
  688. PS_DASH,
  689. PS_DOT,
  690. PS_DASHDOT,
  691. PS_DASHDOTDOT
  692. } ;
  693. #define NumPrinterLineStyles() \
  694. (sizeof (aiPrinterLineStyles) / sizeof (aiPrinterLineStyles [0]))
  695. COLORREF acrPrinterLineColors [] =
  696. {
  697. RGB (192, 192, 192),
  698. RGB (128, 128, 128),
  699. RGB (64, 64, 64),
  700. RGB (0, 0, 0)
  701. } ;
  702. #define NumPrinterLineColors() \
  703. (sizeof (acrPrinterLineColors) / sizeof (acrPrinterLineColors [0]))
  704. #endif // DO_PRINTING
  705. HPEN LineCreatePen (HDC hDC,
  706. PLINEVISUAL pVisual,
  707. BOOL bForPrint)
  708. { // LineCreatePen
  709. HPEN hPen ;
  710. hPen = CreatePen (pVisual->iStyle,
  711. pVisual->iWidth,
  712. pVisual->crColor) ;
  713. return (hPen) ;
  714. } // LineCreatePen
  715. VOID FreeLines (PLINESTRUCT pLineFirst)
  716. { // FreeLines
  717. PLINESTRUCT pLine,next_line;
  718. for (pLine = pLineFirst; pLine; pLine = next_line) {
  719. next_line = pLine->pLineNext;
  720. LineFree (pLine) ;
  721. }
  722. } // FreeLines