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.

932 lines
24 KiB

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