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.

873 lines
16 KiB

  1. //
  2. // MODULE: CACHEGEN.CPP
  3. //
  4. // PURPOSE: Cache File Generator and Reader for BN Networks
  5. //
  6. // PROJECT: Generic Troubleshooter DLL for Microsoft AnswerPoint
  7. //
  8. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  9. //
  10. // AUTHOR: Roman Mach
  11. //
  12. // ORIGINAL DATE: 8/7/97
  13. //
  14. // NOTES:
  15. // 1.
  16. //
  17. // Version Date By Comments
  18. //--------------------------------------------------------------------
  19. // V0.2 8/7/97 RM Local Version for Memphis
  20. // V0.3 04/09/98 JM/OK+ Local Version for NT5
  21. //
  22. #include "stdafx.h"
  23. #include <afxwin.h>
  24. #include <afxtempl.h>
  25. #include "apgts.h"
  26. #include "bnts.h"
  27. #include "cachegen.h"
  28. #include "BackupInfo.h"
  29. #include "apgtsinf.h"
  30. #include "ChmRead.h"
  31. int nodecomp(const void *elem1, const void *elem2);
  32. //
  33. //
  34. GTSCacheGenerator::GTSCacheGenerator(BOOL bScanAll, const char *szLogFile, const char *szBNTSLogFile)
  35. {
  36. m_fp = NULL;
  37. m_bScanAll = bScanAll;
  38. m_szBNTSLogFile = szBNTSLogFile;
  39. if (szLogFile != NULL)
  40. m_fp = fopen(szLogFile, "w");
  41. m_nCount = 0;
  42. m_nItemCount = 0;
  43. m_headposition = 0;
  44. m_filedata = NULL;
  45. m_netstartoffset = 0;
  46. m_nodeorder = NULL;
  47. }
  48. //
  49. //
  50. GTSCacheGenerator::~GTSCacheGenerator()
  51. {
  52. if (m_fp)
  53. fclose(m_fp);
  54. if (m_filedata)
  55. free(m_filedata);
  56. if (m_nodeorder)
  57. free(m_nodeorder);
  58. }
  59. bool GTSCacheGenerator::TcharToChar(char szOut[], LPCTSTR szIn, int &OutLen)
  60. {
  61. int x = 0;
  62. while(NULL != szIn[x] && x < OutLen)
  63. {
  64. szOut[x] = (char) szIn[x];
  65. x++;
  66. }
  67. if (x < OutLen)
  68. szOut[x] = NULL;
  69. return x < OutLen;
  70. }
  71. //
  72. //
  73. /*
  74. void GTSCacheGenerator::LogOut(TCHAR *szcFormat, ...)
  75. {
  76. va_list ptr;
  77. if (!m_fp)
  78. return;
  79. if (!szcFormat)
  80. return;
  81. va_start(ptr, szcFormat);
  82. vfprintf(m_fp, szcFormat, ptr);
  83. va_end(ptr);
  84. }
  85. */
  86. #ifdef _DEBUG
  87. #define LogOut ::AfxTrace
  88. //#define LogOut 1 ? (void)0 : ::AfxTrace
  89. #else
  90. #define LogOut 1 ? (void)0 : ::AfxTrace
  91. #endif
  92. //
  93. //
  94. int nodecomp(const void *elem1, const void *elem2)
  95. {
  96. return (((GTS_NODE_ORDER *)elem1)->depth - ((GTS_NODE_ORDER *)elem2)->depth);
  97. }
  98. //
  99. //
  100. void GTSCacheGenerator::SaveNetItem(CPtrList *nsp, BNTS *bp, FILE *fp, LPCSTR name)
  101. {
  102. GTS_NODE_ITEM *ni;
  103. if (!bp->BNetPropItemStr( name, 0 ))
  104. return;
  105. ni = new GTS_NODE_ITEM(name);
  106. int j = 0;
  107. while (bp->BNetPropItemStr( name, j++ ))
  108. {
  109. CString sTemp = bp->SzcResult();
  110. ni->sStringArr.Add(sTemp);
  111. }
  112. nsp->AddTail(ni);
  113. }
  114. //
  115. //
  116. BOOL GTSCacheGenerator::NodeTraverse( FILE *fp,
  117. BNTS *bp,
  118. int depth,
  119. CArray<int,int> &newnodes,
  120. CArray<int,int> &newstates,
  121. int currnode,
  122. int currstate)
  123. {
  124. BOOL bEnd = FALSE;
  125. int i, j;
  126. if (depth > 30)
  127. {
  128. LogOut(_T("Depth Exceeded\n"));
  129. return FALSE;
  130. }
  131. // uninstantiate
  132. UninstantiateAll(bp);
  133. newnodes.Add(currnode);
  134. newstates.Add(currstate);
  135. depth++;
  136. for (i=0;i<newnodes.GetSize();i++)
  137. {
  138. if (bp->BNodeSetCurrent(newnodes[i]))
  139. {
  140. bp->NodeSymName();
  141. CString sTemp = bp->SzcResult();
  142. LogOut(_T("%s"), sTemp);
  143. ESTDLBL albl = bp->ELblNode();
  144. if (albl == ESTDLBL_problem)
  145. {
  146. LogOut(_T("(prob)"));
  147. }
  148. else if (albl == ESTDLBL_info)
  149. {
  150. LogOut(_T("(info)"));
  151. }
  152. else if (albl == ESTDLBL_fixobs ||
  153. albl == ESTDLBL_fixunobs ||
  154. albl == ESTDLBL_unfix)
  155. {
  156. LogOut(_T("(fix)"));
  157. }
  158. else
  159. {
  160. LogOut(_T("(?)"));
  161. }
  162. }
  163. LogOut(_T("(%d=%d) "), newnodes[i], newstates[i]);
  164. }
  165. SetNodes( bp, newnodes, newstates );
  166. BOOL bRec = FALSE;
  167. if (!bp->BGetRecommendations())
  168. {
  169. bRec = TRUE;
  170. }
  171. else
  172. {
  173. }
  174. const int *rg = bp->RgInt();
  175. i = 0;
  176. if (bRec)
  177. {
  178. if (bp->BImpossible())
  179. {
  180. LogOut(_T("IMPOSSIBLE\n"));
  181. }
  182. else
  183. {
  184. LogOut(_T("RECOMMENDATION ERROR\n"));
  185. }
  186. }
  187. else
  188. {
  189. if (bp->BImpossible())
  190. {
  191. LogOut(_T("IMPOSSIBLE (Have Rec)\n"));
  192. }
  193. else
  194. {
  195. int reccount = bp->CInt();
  196. if (reccount)
  197. {
  198. int nodecount = (int)newstates.GetSize();
  199. if (nodecount)
  200. {
  201. BOOL bFound = FALSE;
  202. for (i=0;i<reccount;i++)
  203. {
  204. bFound = FALSE;
  205. for (j=0;j<nodecount;j++)
  206. {
  207. if (newnodes[j] == rg[i])
  208. {
  209. bFound = TRUE;
  210. break;
  211. }
  212. }
  213. if (!bFound)
  214. break;
  215. }
  216. if (!bFound)
  217. {
  218. LogOut(_T("RECOMMENDATION: "));
  219. if (bp->BNodeSetCurrent(rg[i]))
  220. {
  221. CString sTemp1 = "Error";
  222. CString sTemp2 = "Error";
  223. if (bp->BNodePropItemStr( "HNodeHd", 0 ))
  224. sTemp1 = bp->SzcResult();
  225. bp->NodeSymName();
  226. sTemp2 = bp->SzcResult();
  227. LogOut(_T("%s (%s) (Node: %d)"), sTemp1, sTemp2, rg[i]);
  228. if (m_nodeorder)
  229. {
  230. if (m_nodeorder[rg[i]].depth > depth)
  231. m_nodeorder[rg[i]].depth = depth;
  232. }
  233. UINT realcount = 0;
  234. for (j=0;j<nodecount;j++)
  235. if (newstates[j] != STATE_UNKNOWN)
  236. realcount++;
  237. fwrite(&realcount, sizeof (UINT), 1, fp);
  238. for (j=0;j<nodecount;j++)
  239. if (newstates[j] != STATE_UNKNOWN)
  240. {
  241. GTS_CACHE_NODE cnode;
  242. cnode.node = newnodes[j];
  243. cnode.state = newstates[j];
  244. fwrite(&cnode, sizeof (cnode), 1, fp);
  245. }
  246. // write to cache out file
  247. UINT ucount = reccount;
  248. fwrite(&ucount, sizeof (UINT), 1, fp);
  249. for (j=0;j<reccount;j++)
  250. {
  251. UINT rgval = rg[j];
  252. fwrite(&rgval, sizeof (UINT), 1, fp);
  253. }
  254. m_nCount++;
  255. }
  256. LogOut(_T("\n"));
  257. }
  258. else
  259. {
  260. LogOut(_T("NO RECOMMENDATIONS - ALL AVAILABLE MARKED AS UNKNOWN\n"));
  261. bEnd = TRUE;
  262. }
  263. }
  264. else
  265. LogOut(_T("STATE COUNT 0 - INTERNAL ERROR\n"));
  266. }
  267. else
  268. LogOut(_T("NO RECOMMENDATIONS\n"));
  269. }
  270. }
  271. LogOut(_T("\n"));
  272. // recommendations - let's figure out what to do with them
  273. // the first rec in the returned array will be array[1] in the set array
  274. // so we have to watch for that
  275. if (bp->CInt() && !bEnd)
  276. {
  277. // have rec
  278. CArray<int,int> states;
  279. int node = rg[i];
  280. if (bp->BNodeSetCurrent(node))
  281. {
  282. ESTDLBL albl = bp->ELblNode();
  283. if (albl == ESTDLBL_info)
  284. {
  285. states.Add(0);
  286. states.Add(1);
  287. if (m_bScanAll)
  288. states.Add(STATE_UNKNOWN);
  289. }
  290. else if (albl == ESTDLBL_fixobs ||
  291. albl == ESTDLBL_fixunobs ||
  292. albl == ESTDLBL_unfix)
  293. {
  294. states.Add(0);
  295. if (m_bScanAll)
  296. states.Add(STATE_UNKNOWN);
  297. }
  298. else
  299. {
  300. LogOut(_T("Unexpected Node Type\n"));
  301. }
  302. }
  303. else
  304. LogOut(_T("Can't set node current\n"));
  305. int count = (int)states.GetSize();
  306. for (i=0;i<count;i++)
  307. {
  308. if (!NodeTraverse( fp, bp, depth, newnodes, newstates, node, states[i] ))
  309. return FALSE;
  310. }
  311. }
  312. // done, remove references to our current node
  313. newnodes.RemoveAt(depth - 1);
  314. newstates.RemoveAt(depth - 1);
  315. return TRUE;
  316. }
  317. //
  318. //
  319. void GTSCacheGenerator::UninstantiateAll(BNTS *bp)
  320. {
  321. int count = (int)m_oldnodes.GetSize();
  322. // uninstantiate all nodes
  323. if (!count)
  324. return;
  325. for (int j=0;j<count;j++)
  326. {
  327. if (bp->BNodeSetCurrent(m_oldnodes[j]))
  328. {
  329. if (bp->BNodeSet(-1))
  330. {
  331. }
  332. else
  333. {
  334. LogOut(_T("Can't uninstantiate node\n"));
  335. }
  336. }
  337. else
  338. {
  339. LogOut(_T("Can't set node %d to uninstantiate\n"), m_oldnodes[j]);
  340. }
  341. }
  342. }
  343. //
  344. //
  345. void GTSCacheGenerator::SetNodes(BNTS *bp, CArray<int,int> &nodes, CArray<int,int> &states)
  346. {
  347. m_oldnodes.Copy(nodes);
  348. int count = (int)nodes.GetSize();
  349. if (!count)
  350. return;
  351. LogOut(_T("\nSetNodes:"));
  352. for (int j=0;j<count;j++)
  353. {
  354. if (bp->BNodeSetCurrent(nodes[j]))
  355. {
  356. if (states[j] != STATE_UNKNOWN)
  357. {
  358. LogOut(_T("(%d=%d)"), nodes[j], states[j]);
  359. if (bp->BNodeSet(states[j], false))
  360. {
  361. }
  362. else
  363. {
  364. LogOut(_T("Can't set node\n"));
  365. }
  366. }
  367. else
  368. LogOut(_T("(%d=X)"), nodes[j]);
  369. }
  370. else
  371. LogOut(_T("Can't set node %d\n"), nodes[j]);
  372. }
  373. LogOut(_T("\n"));
  374. }
  375. //
  376. //
  377. BOOL GTSCacheGenerator::ReadCacheFileHeader(CString &sCacheFilename, const CString& strCacheFileWithinCHM)
  378. {
  379. GTS_CACHE_FILE_HEADER header;
  380. bool bUseCHM = strCacheFileWithinCHM.GetLength() != 0;
  381. if (bUseCHM)
  382. {
  383. DWORD size =0;
  384. if (S_OK != ::ReadChmFile(sCacheFilename, strCacheFileWithinCHM, (void**)&m_filedata, &size))
  385. {
  386. return FALSE;
  387. }
  388. }
  389. else
  390. {
  391. UINT size;
  392. // must be binary
  393. FILE *cfp = _tfopen(sCacheFilename, _T("rb"));
  394. if (cfp==NULL)
  395. {
  396. LogOut(_T("Error opening cache file for reading\n"));
  397. return FALSE;
  398. }
  399. // get file size
  400. if (fseek(cfp, 0, SEEK_END))
  401. {
  402. LogOut(_T("Can't set pos to end of file\n"));
  403. fclose(cfp);
  404. return FALSE;
  405. }
  406. fpos_t position;
  407. if (fgetpos(cfp, &position))
  408. {
  409. LogOut(_T("Can't get pos at end of file\n"));
  410. fclose(cfp);
  411. return FALSE;
  412. }
  413. size = (UINT) position;
  414. rewind(cfp);
  415. // allocate space for file
  416. m_filedata = (char *) malloc(size);
  417. if (m_filedata == NULL)
  418. {
  419. LogOut(_T("Error allocating memory\n"));
  420. fclose(cfp);
  421. return FALSE;
  422. }
  423. if (fread(m_filedata, size, 1, cfp) != 1)
  424. {
  425. LogOut(_T("Error reading file into memory\n"));
  426. fclose(cfp);
  427. return FALSE;
  428. }
  429. fclose(cfp);
  430. }
  431. memcpy(&header, m_filedata, sizeof(header));
  432. if (memcmp(header.signature, GTS_CACHE_SIG, sizeof (header.signature)) != 0)
  433. {
  434. LogOut(_T("Bad file signature!\n"));
  435. return FALSE;
  436. }
  437. if (!header.count)
  438. {
  439. LogOut(_T("No items in file!\n"));
  440. return FALSE;
  441. }
  442. m_netstartoffset = header.netoffset;
  443. LogOut(_T("ItemCount: %d\n"), header.count);
  444. m_nItemCount = header.count;
  445. m_cachepos = (GTS_CACHE_FILE_SETDATA *) (m_filedata + sizeof (GTS_CACHE_FILE_HEADER));
  446. return TRUE;
  447. }
  448. //
  449. //
  450. BOOL GTSCacheGenerator::FindNetworkProperty(LPCSTR szName, CString &sResult, int index)
  451. {
  452. if (m_filedata == NULL)
  453. return FALSE;
  454. GTS_CACHE_PROP_NETSTART_BLK *netstart =
  455. (GTS_CACHE_PROP_NETSTART_BLK *)(m_filedata + m_netstartoffset);
  456. GTS_CACHE_PROP_STR_BLK *netstrblk =
  457. (GTS_CACHE_PROP_STR_BLK *) (m_filedata + netstart->netpropoffset);
  458. for (UINT i = 0; i < netstart->netpropcount; i++, netstrblk++)
  459. {
  460. LPCSTR szItem = (LPCSTR) (m_filedata + netstrblk->nameoffset);
  461. if (!strcmp(szName, szItem))
  462. {
  463. if (!index)
  464. {
  465. sResult = (LPCSTR) (m_filedata + netstrblk->stringoffset);
  466. return TRUE;
  467. }
  468. else
  469. {
  470. LPCSTR szStrArrItem = (LPCSTR) (m_filedata + netstrblk->stringoffset);
  471. int len = strlen(szStrArrItem);
  472. for (int j=0;(j < index) && len ;j++)
  473. {
  474. szStrArrItem += len + 1;
  475. len = strlen(szStrArrItem);
  476. }
  477. if (!len)
  478. return FALSE;
  479. sResult = szStrArrItem;
  480. return TRUE;
  481. }
  482. }
  483. }
  484. return FALSE;
  485. }
  486. //
  487. //
  488. BOOL GTSCacheGenerator::FindNodeProperty(UINT nodeid, LPCSTR szName, CString &sResult, int index)
  489. {
  490. if (m_filedata == NULL)
  491. return FALSE;
  492. GTS_CACHE_PROP_NETSTART_BLK *netstart =
  493. (GTS_CACHE_PROP_NETSTART_BLK *)(m_filedata + m_netstartoffset);
  494. GTS_CACHE_PROP_NODEOFF_BLK *nodeblk =
  495. (GTS_CACHE_PROP_NODEOFF_BLK *) (m_filedata + m_netstartoffset + sizeof (GTS_CACHE_PROP_NETSTART_BLK));
  496. for (UINT i = 0; i < netstart->nodecountfile; i++, nodeblk++)
  497. {
  498. if (nodeid == nodeblk->nodeid)
  499. {
  500. GTS_CACHE_PROP_NODESTART_BLK *nodestart =
  501. (GTS_CACHE_PROP_NODESTART_BLK *)(m_filedata + nodeblk->nodeoffset);
  502. GTS_CACHE_PROP_STR_BLK *nodestr =
  503. (GTS_CACHE_PROP_STR_BLK *)(m_filedata + nodeblk->nodeoffset + sizeof (GTS_CACHE_PROP_NODESTART_BLK));
  504. // now try to find string
  505. for (UINT j=0;j<nodestart->nodestringcount;j++, nodestr++)
  506. {
  507. LPCSTR szItem = (LPCSTR) (m_filedata + nodestr->nameoffset);
  508. if (!strcmp(szName, szItem))
  509. {
  510. if (!index)
  511. {
  512. sResult = (LPCSTR) (m_filedata + nodestr->stringoffset);
  513. return TRUE;
  514. }
  515. else
  516. {
  517. LPCSTR szStrArrItem = (LPCSTR) (m_filedata + nodestr->stringoffset);
  518. int len = strlen(szStrArrItem);
  519. for (int j=0;(j < index) && len ;j++)
  520. {
  521. szStrArrItem += len + 1;
  522. len = strlen(szStrArrItem);
  523. }
  524. if (!len)
  525. return FALSE;
  526. sResult = szStrArrItem;
  527. return TRUE;
  528. }
  529. }
  530. }
  531. return FALSE;
  532. }
  533. }
  534. return FALSE;
  535. }
  536. //
  537. //
  538. BOOL GTSCacheGenerator::IsNodePresent(UINT nodeid)
  539. {
  540. if (m_filedata == NULL)
  541. return FALSE;
  542. GTS_CACHE_PROP_NETSTART_BLK *netstart =
  543. (GTS_CACHE_PROP_NETSTART_BLK *)(m_filedata + m_netstartoffset);
  544. GTS_CACHE_PROP_NODEOFF_BLK *nodeblk =
  545. (GTS_CACHE_PROP_NODEOFF_BLK *) (m_filedata + m_netstartoffset + sizeof (GTS_CACHE_PROP_NETSTART_BLK));
  546. for (UINT i = 0; i < netstart->nodecountfile; i++, nodeblk++)
  547. {
  548. if (nodeid == nodeblk->nodeid)
  549. return TRUE;
  550. }
  551. return FALSE;
  552. }
  553. // returns the node count for the network, not what's in the file
  554. //
  555. int GTSCacheGenerator::GetNodeCount()
  556. {
  557. if (m_filedata == NULL)
  558. return 0;
  559. GTS_CACHE_PROP_NETSTART_BLK *netstart =
  560. (GTS_CACHE_PROP_NETSTART_BLK *)(m_filedata + m_netstartoffset);
  561. return netstart->nodecountnetwork;
  562. }
  563. //
  564. //
  565. BOOL GTSCacheGenerator::GetNodeIDFromSymName(LPCTSTR szSymName, UINT &nodeid)
  566. {
  567. char sznSymName[MAX_SYM_NAME_BUF_LEN];
  568. int nSymLen = MAX_SYM_NAME_BUF_LEN;
  569. if (m_filedata == NULL)
  570. return FALSE;
  571. if (!TcharToChar(sznSymName, szSymName, nSymLen))
  572. return FALSE;
  573. GTS_CACHE_PROP_NETSTART_BLK *netstart =
  574. (GTS_CACHE_PROP_NETSTART_BLK *)(m_filedata + m_netstartoffset);
  575. GTS_CACHE_PROP_NODEOFF_BLK *nodeblk =
  576. (GTS_CACHE_PROP_NODEOFF_BLK *) (m_filedata + m_netstartoffset + sizeof (GTS_CACHE_PROP_NETSTART_BLK));
  577. for (UINT i = 0; i < netstart->nodecountfile; i++, nodeblk++)
  578. {
  579. GTS_CACHE_PROP_NODESTART_BLK *nodestart =
  580. (GTS_CACHE_PROP_NODESTART_BLK *)(m_filedata + nodeblk->nodeoffset);
  581. GTS_CACHE_PROP_STR_BLK *nodestr =
  582. (GTS_CACHE_PROP_STR_BLK *)(m_filedata + nodeblk->nodeoffset + sizeof (GTS_CACHE_PROP_NODESTART_BLK));
  583. // now try to find string
  584. for (UINT j=0;j<nodestart->nodestringcount;j++, nodestr++)
  585. {
  586. LPCSTR szItem = (LPCSTR) (m_filedata + nodestr->nameoffset);
  587. if (!strcmp(G_SYMBOLIC_NAME, szItem))
  588. {
  589. if (!strcmp(sznSymName, (LPCSTR) (m_filedata + nodestr->stringoffset)))
  590. {
  591. nodeid = nodeblk->nodeid;
  592. return TRUE;
  593. }
  594. break;
  595. }
  596. }
  597. }
  598. return FALSE;
  599. }
  600. //
  601. //
  602. BOOL GTSCacheGenerator::GetLabelOfNode(UINT nodeid, UINT &lbl)
  603. {
  604. if (m_filedata == NULL)
  605. return FALSE;
  606. GTS_CACHE_PROP_NETSTART_BLK *netstart =
  607. (GTS_CACHE_PROP_NETSTART_BLK *)(m_filedata + m_netstartoffset);
  608. GTS_CACHE_PROP_NODEOFF_BLK *nodeblk =
  609. (GTS_CACHE_PROP_NODEOFF_BLK *) (m_filedata + m_netstartoffset + sizeof (GTS_CACHE_PROP_NETSTART_BLK));
  610. for (UINT i = 0; i < netstart->nodecountfile; i++, nodeblk++)
  611. {
  612. if (nodeid == nodeblk->nodeid)
  613. {
  614. GTS_CACHE_PROP_NODESTART_BLK *nodestart =
  615. (GTS_CACHE_PROP_NODESTART_BLK *)(m_filedata + nodeblk->nodeoffset);
  616. lbl = nodestart->labelnode;
  617. return TRUE;
  618. }
  619. }
  620. return FALSE;
  621. }
  622. //
  623. //
  624. BOOL GTSCacheGenerator::GetNextCacheEntryFromFile(BOOL &bErr, CBNCache *pCache)
  625. {
  626. BOOL bStat = FALSE;
  627. bErr = TRUE;
  628. if (m_filedata == NULL)
  629. return FALSE;
  630. if (!m_nItemCount)
  631. {
  632. bErr = FALSE;
  633. return FALSE;
  634. }
  635. m_nItemCount--;
  636. BN_CACHE_ITEM CacheItem;
  637. // initialize
  638. CacheItem.uNodeCount = 0;
  639. CacheItem.uRecCount = 0;
  640. CacheItem.uName = NULL;
  641. CacheItem.uValue = NULL;
  642. CacheItem.uRec = NULL;
  643. bStat = GetNCEFF(&CacheItem, pCache);
  644. // free allocated space as necessary
  645. if (CacheItem.uName)
  646. free(CacheItem.uName);
  647. if (CacheItem.uValue)
  648. free(CacheItem.uValue);
  649. if (CacheItem.uRec)
  650. free(CacheItem.uRec);
  651. if (!bStat)
  652. {
  653. bErr = TRUE;
  654. return FALSE;
  655. }
  656. bErr = FALSE;
  657. return TRUE;
  658. }
  659. //
  660. //
  661. BOOL GTSCacheGenerator::GetNCEFF(BN_CACHE_ITEM *pCacheItem, CBNCache *pCache)
  662. {
  663. UINT j;
  664. UINT setcount;
  665. UINT reccount;
  666. GTS_CACHE_FILE_SETDATA *setp = m_cachepos;
  667. setcount = setp->count;
  668. if (!setcount || setcount > 1000)
  669. {
  670. LogOut(_T("Set Count out of bounds: %d\n"), setcount);
  671. return FALSE;
  672. }
  673. // initialize
  674. pCacheItem->uNodeCount = setcount;
  675. pCacheItem->uName = (UINT *)malloc(setcount * sizeof (UINT));
  676. pCacheItem->uValue = (UINT *)malloc(setcount * sizeof (UINT));
  677. LogOut(_T("Count: %d\n"), setcount);
  678. GTS_CACHE_NODE *cachenode = &setp->item[0];
  679. // second, read in node = state pairs
  680. for (j=0;j<setcount;j++, cachenode++)
  681. {
  682. pCacheItem->uName[j] = cachenode->node;
  683. pCacheItem->uValue[j] = cachenode->state;
  684. LogOut(_T("(%d,%d)"), cachenode->node, cachenode->state);
  685. }
  686. LogOut(_T("\n"));
  687. GTS_CACHE_FILE_RECDATA *recp = (GTS_CACHE_FILE_RECDATA *) cachenode;
  688. reccount = recp->count;
  689. if (!reccount || reccount > 1000)
  690. {
  691. LogOut(_T("Rec Count out of bounds: %d\n"), reccount);
  692. return FALSE;
  693. }
  694. pCacheItem->uRecCount = reccount;
  695. pCacheItem->uRec = (UINT *)malloc(reccount * sizeof (UINT));
  696. UINT *uitem = &recp->item[0];
  697. for (j=0;j<reccount;j++, uitem++)
  698. {
  699. pCacheItem->uRec[j] = *uitem;
  700. LogOut(_T("(%d)"), *uitem);
  701. }
  702. LogOut(_T("\n"));
  703. if (!pCache->AddCacheItem(pCacheItem))
  704. {
  705. LogOut(_T("Error Adding Item To Cache\n"));
  706. return FALSE;
  707. }
  708. m_cachepos = (GTS_CACHE_FILE_SETDATA *) uitem;
  709. // success!
  710. return TRUE;
  711. }
  712.