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.

1516 lines
39 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // CChapter, CChapterMgr and CWMIInstanceMgr class implementation
  7. // - Implements utility classes to maintain rowset
  8. //
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////////
  11. #include "headers.h"
  12. ////////////////////////////////////////////////////////////////////////////////////////
  13. //// CChapter class Implementation
  14. ////////////////////////////////////////////////////////////////////////////////////////
  15. ////////////////////////////////////////////////////////////////////////////////////////
  16. // Constructor
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. CChapter::CChapter()
  19. {
  20. m_pNext = NULL;
  21. m_hChapter = 0;
  22. m_pFirstRow = NULL;
  23. m_pInstance = NULL;
  24. m_cRefChapter = 0;
  25. m_lCount = 0;
  26. m_strKey = NULL;
  27. m_dwStatus = 0;
  28. }
  29. ////////////////////////////////////////////////////////////////////////////////////////
  30. // Destructor
  31. ////////////////////////////////////////////////////////////////////////////////////////
  32. CChapter::~CChapter()
  33. {
  34. CHRowsForChapter *pRowToDel = NULL;
  35. CHRowsForChapter *pRowTemp = NULL;
  36. pRowToDel = m_pFirstRow;
  37. while(pRowToDel)
  38. {
  39. pRowTemp = pRowToDel->m_pNext;
  40. delete pRowToDel;
  41. pRowToDel = pRowTemp;
  42. }
  43. if(m_strKey)
  44. {
  45. SysFreeString(m_strKey);
  46. }
  47. }
  48. ////////////////////////////////////////////////////////////////////////////////////////
  49. // Add a HROW to the chapter
  50. ////////////////////////////////////////////////////////////////////////////////////////
  51. HRESULT CChapter::AddHRow(HROW hRow ,CWbemClassWrapper *pInstance, HSLOT hSlot)
  52. {
  53. HRESULT hr = S_OK;
  54. CHRowsForChapter *pRowNew = NULL;
  55. CHRowsForChapter *pRowTemp = NULL;
  56. try
  57. {
  58. pRowNew = new CHRowsForChapter;
  59. }
  60. catch(...)
  61. {
  62. SAFE_DELETE_PTR(pRowNew);
  63. throw;
  64. }
  65. if(pRowNew)
  66. {
  67. pRowNew->m_hRow = hRow;
  68. pRowNew->m_hSlot = hSlot;
  69. pRowNew->m_pInstance = pInstance;
  70. if(pRowNew == NULL)
  71. {
  72. hr = E_OUTOFMEMORY;
  73. }
  74. else
  75. {
  76. if(m_pFirstRow == NULL)
  77. {
  78. m_pFirstRow = pRowNew;
  79. }
  80. else
  81. {
  82. for(pRowTemp = m_pFirstRow ; pRowTemp->m_pNext != NULL ; pRowTemp = pRowTemp->m_pNext);
  83. pRowTemp->m_pNext = pRowNew;
  84. }
  85. m_lCount++;
  86. }
  87. }
  88. else
  89. {
  90. hr = E_OUTOFMEMORY;
  91. }
  92. return hr;
  93. }
  94. ////////////////////////////////////////////////////////////////////////////////////////
  95. // Delete a HROW for the chapter
  96. ////////////////////////////////////////////////////////////////////////////////////////
  97. HRESULT CChapter::DeleteHRow(HROW hRow)
  98. {
  99. HRESULT hr = E_FAIL;
  100. CHRowsForChapter *pRowToDel = NULL;
  101. CHRowsForChapter *pRowTemp = NULL;
  102. if(m_pFirstRow != NULL)
  103. {
  104. if(m_pFirstRow->m_hRow == hRow)
  105. {
  106. pRowToDel = m_pFirstRow;
  107. m_pFirstRow = m_pFirstRow->m_pNext;
  108. delete pRowToDel;
  109. hr = S_OK;
  110. }
  111. else
  112. {
  113. for(pRowTemp = m_pFirstRow ; pRowTemp->m_pNext != NULL ; pRowTemp = pRowTemp->m_pNext)
  114. {
  115. //==================================================
  116. // if the row searching is found then delete
  117. // the element from the list
  118. //==================================================
  119. if(pRowTemp->m_pNext->m_hRow == hRow)
  120. {
  121. pRowToDel = pRowTemp->m_pNext;
  122. pRowTemp->m_pNext = pRowToDel->m_pNext;
  123. delete pRowToDel;
  124. hr = S_OK;
  125. break;
  126. }
  127. }
  128. }
  129. m_lCount--;
  130. }
  131. return hr;
  132. }
  133. ////////////////////////////////////////////////////////////////////////////////////////
  134. // Check if the HROW passed belongs to the chapter
  135. ////////////////////////////////////////////////////////////////////////////////////////
  136. HRESULT CChapter::IsHRowOfThisChapter(HROW hRow)
  137. {
  138. HRESULT hr = E_FAIL;
  139. CHRowsForChapter *pRowToDel = NULL;
  140. CHRowsForChapter *pRowTemp = NULL;
  141. if(m_pFirstRow != NULL)
  142. {
  143. for(pRowTemp = m_pFirstRow ; pRowTemp != NULL ; pRowTemp = pRowTemp->m_pNext)
  144. {
  145. //==================================================
  146. // if the row searching is found then delete
  147. // the element from the list
  148. //==================================================
  149. if(pRowTemp->m_hRow == hRow)
  150. {
  151. hr = S_OK;
  152. break;
  153. }
  154. }
  155. }
  156. return hr;
  157. }
  158. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. // Function to get all the open rows in the list
  160. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. HRESULT CChapter::GetAllHRowsInList(HROW *pHRows)
  162. {
  163. HRESULT hr = S_OK;
  164. CHRowsForChapter *pRowTemp = NULL;
  165. int nIndex = 0;
  166. if(m_pFirstRow != NULL)
  167. {
  168. for(pRowTemp = m_pFirstRow ; pRowTemp != NULL ; pRowTemp = pRowTemp->m_pNext)
  169. {
  170. pHRows[nIndex++] = pRowTemp->m_hRow;
  171. }
  172. }
  173. return S_OK;
  174. }
  175. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  176. // Function to set the slot number for the row
  177. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  178. HRESULT CChapter::SetSlot(HROW hRow , HSLOT hSolt)
  179. {
  180. HRESULT hr = E_FAIL;
  181. CHRowsForChapter *pRow = NULL;
  182. if(m_pFirstRow != NULL)
  183. {
  184. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  185. {
  186. //==================================================
  187. // if the row searching is found then delete
  188. // the element from the list
  189. //==================================================
  190. if(pRow->m_hRow == hRow)
  191. {
  192. pRow->m_hSlot = hSolt;
  193. hr = S_OK;
  194. break;
  195. }
  196. }
  197. }
  198. return hr;
  199. }
  200. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  201. // Function to get the slot number for a row
  202. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  203. HSLOT CChapter::GetSlot(HROW hRow)
  204. {
  205. HSLOT hSlot = -1;
  206. CHRowsForChapter *pRow = NULL;
  207. if(m_pFirstRow != NULL)
  208. {
  209. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  210. {
  211. //==================================================
  212. // if the row searching is found then delete
  213. // the element from the list
  214. //==================================================
  215. if(pRow->m_hRow == hRow)
  216. {
  217. hSlot = pRow->m_hSlot;
  218. break;
  219. }
  220. }
  221. }
  222. return hSlot;
  223. }
  224. //////////////////////////////////////////////////////////////////////////////////
  225. // This method is for chapter representing child rows of type Embeded classes
  226. //////////////////////////////////////////////////////////////////////////////////
  227. HRESULT CChapter::SetInstance(HROW hRow , BSTR strInstKey , CWbemClassWrapper *pInstance)
  228. {
  229. CHRowsForChapter *pRow = NULL;
  230. HRESULT hr = E_FAIL;
  231. if(m_pFirstRow != NULL)
  232. {
  233. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  234. {
  235. //==================================================
  236. // if the row searching is found then delete
  237. // the element from the list
  238. //==================================================
  239. if(pRow->m_hRow == hRow)
  240. {
  241. pRow->m_pInstance = pInstance;
  242. SAFE_FREE_SYSSTRING(pRow->m_strKey);
  243. pRow->m_strKey = Wmioledb_SysAllocString(strInstKey);
  244. hr = S_OK;
  245. break;
  246. }
  247. }
  248. }
  249. return hr;
  250. }
  251. //////////////////////////////////////////////////////////////////////////////////
  252. // This method is for chapter representing child rows of type Embeded classes
  253. //////////////////////////////////////////////////////////////////////////////////
  254. CWbemClassWrapper * CChapter::GetInstance(HROW hRow)
  255. {
  256. CHRowsForChapter * pRow = NULL;
  257. CWbemClassWrapper * pRetInst = NULL;
  258. if(m_pFirstRow != NULL)
  259. {
  260. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  261. {
  262. //==================================================
  263. // if the row searching is found then delete
  264. // the element from the list
  265. //==================================================
  266. if(pRow->m_hRow == hRow)
  267. {
  268. pRetInst = pRow->m_pInstance;
  269. break;
  270. }
  271. }
  272. }
  273. return pRetInst;
  274. }
  275. //////////////////////////////////////////////////////////////////////////////////
  276. // This method is for chapter representing child rows of type Embeded classes
  277. //////////////////////////////////////////////////////////////////////////////////
  278. HRESULT CChapter::GetInstanceKey(HROW hRow , BSTR *pstrKey)
  279. {
  280. CHRowsForChapter *pRow = NULL;
  281. HRESULT hr = E_FAIL;
  282. if(m_pFirstRow != NULL)
  283. {
  284. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  285. {
  286. //==================================================
  287. // if the row searching is found then delete
  288. // the element from the list
  289. //==================================================
  290. if(pRow->m_hRow == hRow)
  291. {
  292. *pstrKey = Wmioledb_SysAllocString(pRow->m_strKey);
  293. hr = S_OK;
  294. break;
  295. }
  296. }
  297. }
  298. return hr;
  299. }
  300. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  301. // Set the status of a particular row
  302. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  303. void CChapter::SetRowStatus(HROW hRow , DBSTATUS dwStatus)
  304. {
  305. CHRowsForChapter *pRow = NULL;
  306. if(m_pFirstRow != NULL)
  307. {
  308. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  309. {
  310. //==================================================
  311. // if the row searching is found then delete
  312. // the element from the list
  313. //==================================================
  314. if(pRow->m_hRow == hRow)
  315. {
  316. pRow->SetRowStatus(dwStatus);
  317. break;
  318. }
  319. }
  320. }
  321. }
  322. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  323. // Get the status of a particular row
  324. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  325. DBSTATUS CChapter::GetRowStatus(HROW hRow)
  326. {
  327. DBSTATUS dwStatus = DBROWSTATUS_E_FAIL;
  328. CHRowsForChapter *pRow = NULL;
  329. if(m_pFirstRow != NULL)
  330. {
  331. for(pRow = m_pFirstRow ; pRow != NULL ; pRow = pRow->m_pNext)
  332. {
  333. //==================================================
  334. // if the row searching is found then delete
  335. // the element from the list
  336. //==================================================
  337. if(pRow->m_hRow == hRow)
  338. {
  339. dwStatus = pRow->GetRowStatus();
  340. break;
  341. }
  342. }
  343. }
  344. return dwStatus;
  345. }
  346. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  347. // Get HROW of the row identified by the key
  348. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  349. HROW CChapter::GetHRow(BSTR strInstKey)
  350. {
  351. CHRowsForChapter * pRow = m_pFirstRow;
  352. HROW hRow = 0;
  353. while(pRow != NULL)
  354. {
  355. //==================================================
  356. // if the row searching is found then
  357. //==================================================
  358. if(pRow->m_strKey != NULL && strInstKey != NULL)
  359. if(0 == _wcsicmp((WCHAR *)strInstKey,pRow->m_strKey))
  360. {
  361. hRow = pRow->m_hRow;
  362. break;
  363. }
  364. pRow = pRow->m_pNext;
  365. }
  366. return hRow;
  367. }
  368. ///////////////////////////////////////////////////////////////////////////////////////
  369. // CChapterMgr class Implementation
  370. ///////////////////////////////////////////////////////////////////////////////////////
  371. ///////////////////////////////////////////////////////////////////////////////////////
  372. // Constructor
  373. ///////////////////////////////////////////////////////////////////////////////////////
  374. CChapterMgr::CChapterMgr()
  375. {
  376. m_pHead = NULL;
  377. m_lCount = 0;
  378. }
  379. ///////////////////////////////////////////////////////////////////////////////////////
  380. // Destructor
  381. ///////////////////////////////////////////////////////////////////////////////////////
  382. CChapterMgr::~CChapterMgr()
  383. {
  384. CChapter *pTempChap, *pTempChapToDel = NULL;
  385. pTempChapToDel = m_pHead;
  386. // Navigate thru the list and delete all the elements
  387. while(pTempChapToDel)
  388. {
  389. pTempChap = pTempChapToDel->m_pNext;
  390. delete pTempChapToDel;
  391. pTempChapToDel = pTempChap;
  392. }
  393. }
  394. ///////////////////////////////////////////////////////////////////////////////////////
  395. // Add a Chapter to the list
  396. ///////////////////////////////////////////////////////////////////////////////////////
  397. HRESULT CChapterMgr::AddChapter(HCHAPTER hChapter)
  398. {
  399. CChapter *pNewChap = NULL;
  400. CChapter *pTempChap = NULL;
  401. HRESULT hr = S_OK;
  402. try
  403. {
  404. pNewChap = new CChapter;
  405. } // try
  406. catch(...)
  407. {
  408. SAFE_DELETE_PTR(pNewChap);
  409. throw;
  410. }
  411. if(pNewChap == NULL)
  412. {
  413. hr = E_OUTOFMEMORY;
  414. }
  415. else
  416. {
  417. pNewChap->m_cRefChapter = 1; // The moment HCHAPPTER is retrieved is ref count is 1
  418. pNewChap->m_hChapter = hChapter;
  419. if(m_pHead == NULL)
  420. {
  421. m_pHead = pNewChap;
  422. }
  423. else
  424. {
  425. for(pTempChap = m_pHead; pTempChap->m_pNext != NULL ; pTempChap = pTempChap->m_pNext);
  426. pTempChap->m_pNext = pNewChap;
  427. }
  428. m_lCount++;
  429. }
  430. return hr;
  431. }
  432. ///////////////////////////////////////////////////////////////////////////////////////
  433. // Delete a chapter from the list
  434. ///////////////////////////////////////////////////////////////////////////////////////
  435. HRESULT CChapterMgr::DeleteChapter(HCHAPTER hChapter)
  436. {
  437. CChapter *pTempChap = NULL;
  438. CChapter *pTempChapToDel = NULL;
  439. if( m_pHead)
  440. {
  441. if(m_pHead->m_hChapter == hChapter)
  442. {
  443. pTempChapToDel = m_pHead;
  444. m_pHead = m_pHead->m_pNext;
  445. delete pTempChapToDel;
  446. }
  447. else
  448. {
  449. //============================================================
  450. // Get to the previous node which is being searched
  451. //============================================================
  452. for( pTempChap = m_pHead ; pTempChap->m_pNext != NULL ; pTempChap = pTempChap->m_pNext)
  453. {
  454. if(pTempChap->m_pNext->m_hChapter == hChapter)
  455. {
  456. pTempChapToDel = pTempChap->m_pNext;
  457. pTempChap->m_pNext = pTempChapToDel->m_pNext;
  458. delete pTempChapToDel;
  459. break;
  460. } // if
  461. } // for
  462. } // else
  463. m_lCount--;
  464. } // if the head pointer is valid
  465. return S_OK;
  466. }
  467. ///////////////////////////////////////////////////////////////////////////////////////
  468. // Set the Instance pointer for the HCHAPTER
  469. ///////////////////////////////////////////////////////////////////////////////////////
  470. void CChapterMgr::SetInstance(HCHAPTER hChapter , CWbemClassWrapper *pInstance,BSTR strKey,HROW hRow)
  471. {
  472. CChapter *pTempChap = m_pHead;
  473. while(pTempChap != NULL)
  474. {
  475. if(pTempChap->m_hChapter == hChapter)
  476. {
  477. //============================================================
  478. // hRow will be zero if the chapter is representing qualifier
  479. //============================================================
  480. if( hRow == 0)
  481. {
  482. pTempChap->m_pInstance = pInstance;
  483. pTempChap->m_strKey = Wmioledb_SysAllocString(strKey);
  484. }
  485. //============================================================
  486. // else the chapter will be refering to a embeded class
  487. //============================================================
  488. else
  489. {
  490. pTempChap->SetInstance(hRow,strKey,pInstance);
  491. }
  492. break;
  493. }
  494. pTempChap = pTempChap->m_pNext;
  495. }
  496. }
  497. ///////////////////////////////////////////////////////////////////////////////////////
  498. // Get the Instance pointer for the chapter
  499. ///////////////////////////////////////////////////////////////////////////////////////
  500. CWbemClassWrapper *CChapterMgr::GetInstance(HCHAPTER hChapter, HROW hRow)
  501. {
  502. CChapter * pTempChap = m_pHead;
  503. CWbemClassWrapper * pRetInst = NULL;
  504. while(pTempChap != NULL)
  505. {
  506. if(pTempChap->m_hChapter == hChapter)
  507. {
  508. //============================================================
  509. // hRow will be zero if the chapter is representing qualifier
  510. //============================================================
  511. if( hRow == 0)
  512. {
  513. pRetInst = pTempChap->m_pInstance;
  514. }
  515. //============================================================
  516. // else the chapter will be refering to a embeded class
  517. //============================================================
  518. else
  519. {
  520. pRetInst = pTempChap->GetInstance(hRow);
  521. }
  522. }
  523. pTempChap = pTempChap->m_pNext;
  524. }
  525. return pRetInst;
  526. }
  527. ///////////////////////////////////////////////////////////////////////////////////////
  528. // Add a HROW to the list of HROWS for the chapter
  529. ///////////////////////////////////////////////////////////////////////////////////////
  530. HRESULT CChapterMgr::AddHRowForChapter(HCHAPTER hChapter , HROW hRow, CWbemClassWrapper *pInstance , HSLOT hSlot)
  531. {
  532. HRESULT hr = E_FAIL;
  533. CChapter *pTempChap = m_pHead;
  534. while(pTempChap != NULL)
  535. {
  536. if(pTempChap->m_hChapter == hChapter)
  537. {
  538. hr = pTempChap->AddHRow(hRow,pInstance, hSlot);
  539. break;
  540. }
  541. pTempChap = pTempChap->m_pNext;
  542. }
  543. return hr;
  544. }
  545. ///////////////////////////////////////////////////////////////////////////////////////
  546. // Delete a HROW from the list of HROWS for the chapter
  547. ///////////////////////////////////////////////////////////////////////////////////////
  548. HRESULT CChapterMgr::DeleteHRow(HROW hRow)
  549. {
  550. HRESULT hr = S_OK;
  551. CChapter *pTempChap = NULL;
  552. //======================================================
  553. // Get to the node which is being searched
  554. //======================================================
  555. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  556. {
  557. if(S_OK == pTempChap->IsHRowOfThisChapter(hRow))
  558. {
  559. hr = pTempChap->DeleteHRow(hRow);
  560. break;
  561. } // if row is of this chapter
  562. }// for
  563. return hr;
  564. }
  565. ///////////////////////////////////////////////////////////////////////////////////////
  566. // Get the HCHAPTER for the given HROW
  567. ///////////////////////////////////////////////////////////////////////////////////////
  568. HCHAPTER CChapterMgr::GetChapterForHRow(HROW hRow)
  569. {
  570. HCHAPTER hChapter = -1;
  571. CChapter *pTempChap = NULL;
  572. //========================================================
  573. // Get to the previous node which is being searched
  574. //========================================================
  575. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  576. {
  577. if(S_OK == pTempChap->IsHRowOfThisChapter(hRow))
  578. {
  579. hChapter = pTempChap->m_hChapter;
  580. break;
  581. }
  582. }
  583. return hChapter;
  584. }
  585. ///////////////////////////////////////////////////////////////////////////////////////
  586. // Check if the given HCHAPTER exists in the list
  587. ///////////////////////////////////////////////////////////////////////////////////////
  588. BOOL CChapterMgr::IsExists(HCHAPTER hChapter)
  589. {
  590. BOOL bRet = FALSE;
  591. CChapter *pTempChap = m_pHead;
  592. while(pTempChap != NULL)
  593. {
  594. if(pTempChap->m_hChapter == hChapter)
  595. {
  596. bRet = TRUE;
  597. break;
  598. }
  599. pTempChap = pTempChap->m_pNext;
  600. }
  601. return bRet;
  602. }
  603. ///////////////////////////////////////////////////////////////////////////////////////
  604. // Add a reference to HCHAPTER
  605. ///////////////////////////////////////////////////////////////////////////////////////
  606. ULONG CChapterMgr::AddRefChapter(HCHAPTER hChapter)
  607. {
  608. ULONG ulRet = 0;
  609. CChapter *pTempChap = m_pHead;
  610. while(pTempChap != NULL)
  611. {
  612. if(pTempChap->m_hChapter == hChapter)
  613. {
  614. ulRet = ++(pTempChap->m_cRefChapter);
  615. break;
  616. }
  617. pTempChap = pTempChap->m_pNext;
  618. }
  619. return ulRet;
  620. }
  621. ///////////////////////////////////////////////////////////////////////////////////////
  622. // Release a reference to the chapter
  623. ///////////////////////////////////////////////////////////////////////////////////////
  624. ULONG CChapterMgr::ReleaseRefChapter(HCHAPTER hChapter)
  625. {
  626. ULONG ulRet = 0;
  627. CChapter *pTempChap = m_pHead;
  628. while(pTempChap != NULL)
  629. {
  630. if(pTempChap->m_hChapter == hChapter)
  631. {
  632. ulRet = --(pTempChap->m_cRefChapter);
  633. break;
  634. }
  635. pTempChap = pTempChap->m_pNext;
  636. }
  637. return ulRet;
  638. }
  639. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  640. // Function to get all the open rows
  641. // caller releases the memory allocated
  642. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  643. HRESULT CChapterMgr::GetAllHROWs(HROW *&prghRows , DBCOUNTITEM &cRows)
  644. {
  645. HRESULT hr = S_OK;
  646. DBCOUNTITEM ulRowCount = 0;
  647. CChapter *pTempChap = NULL;
  648. HROW *pHRowTemp = NULL;
  649. prghRows = NULL;
  650. //========================================================
  651. // Get to the previous node which is being searched
  652. //========================================================
  653. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  654. {
  655. ulRowCount += pTempChap->m_lCount;
  656. }
  657. if( ulRowCount > 0)
  658. {
  659. pHRowTemp = new HROW[ulRowCount];
  660. //NTRaid:111769
  661. // 06/07/00
  662. if(pHRowTemp)
  663. {
  664. prghRows = pHRowTemp;
  665. cRows = ulRowCount;
  666. //========================================================
  667. // Get to the previous node which is being searched
  668. //========================================================
  669. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  670. {
  671. if(S_OK == (hr = pTempChap->GetAllHRowsInList(pHRowTemp)))
  672. {
  673. pHRowTemp += pTempChap->m_lCount;
  674. }
  675. else
  676. {
  677. SAFE_DELETE_ARRAY(pHRowTemp);
  678. prghRows = NULL;
  679. cRows = 0;
  680. break;
  681. }
  682. }
  683. }
  684. else
  685. {
  686. hr = E_OUTOFMEMORY;
  687. }
  688. }
  689. return hr;
  690. }
  691. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  692. // Function to find if any rows are opened for the chapter
  693. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  694. HRESULT CChapterMgr::IsRowExistsForChapter(HCHAPTER hChapter)
  695. {
  696. HRESULT hr = E_FAIL;
  697. CChapter * pTempChap = NULL;
  698. //========================================================
  699. // Get to the previous node which is being searched
  700. //========================================================
  701. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  702. {
  703. if(pTempChap->m_hChapter == hChapter)
  704. {
  705. if(pTempChap->m_lCount >0)
  706. {
  707. hr = S_OK;
  708. }
  709. break;
  710. }
  711. }
  712. return hr;
  713. }
  714. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  715. // Function to set the slot number for the row
  716. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  717. HRESULT CChapterMgr::SetSlot(HROW hRow , HSLOT hSlot)
  718. {
  719. HRESULT hr = E_FAIL;
  720. CChapter * pTempChap = NULL;
  721. //========================================================
  722. // Get to the previous node which is being searched
  723. //========================================================
  724. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  725. {
  726. if(S_OK == pTempChap->IsHRowOfThisChapter(hRow))
  727. {
  728. pTempChap->SetSlot(hRow,hSlot);
  729. hr = S_OK;
  730. break;
  731. }
  732. }
  733. return hr;
  734. }
  735. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  736. // Function to get slot number for the row
  737. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  738. HSLOT CChapterMgr::GetSlot(HROW hRow)
  739. {
  740. HSLOT hSlot = -1;
  741. CChapter * pTempChap = NULL;
  742. //========================================================
  743. // Get to the previous node which is being searched
  744. //========================================================
  745. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  746. {
  747. if(S_OK == pTempChap->IsHRowOfThisChapter(hRow))
  748. {
  749. hSlot = pTempChap->GetSlot(hRow);
  750. break;
  751. }
  752. }
  753. return hSlot;
  754. }
  755. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  756. // Function to check if the particular row is opened
  757. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  758. BOOL CChapterMgr::IsRowExists(HROW hRow)
  759. {
  760. BOOL bRet = FALSE;
  761. if( hRow > 0)
  762. if(0 < GetChapterForHRow(hRow))
  763. {
  764. bRet = TRUE;
  765. }
  766. return bRet;
  767. }
  768. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  769. // Function to get the key for the chapter
  770. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  771. HRESULT CChapterMgr::GetInstanceKey(HCHAPTER hChapter, BSTR *pstrKey, HROW hRow)
  772. {
  773. CChapter *pTempChap = m_pHead;
  774. HRESULT hr = E_FAIL;
  775. while(pTempChap != NULL)
  776. {
  777. if(pTempChap->m_hChapter == hChapter)
  778. {
  779. //==================================================================
  780. // hRow will be zero if the chapter is representing qualifier
  781. //==================================================================
  782. if( hRow == 0)
  783. {
  784. hr = S_OK;
  785. *pstrKey = Wmioledb_SysAllocString(pTempChap->m_strKey);
  786. }
  787. //==================================================================
  788. // else the chapter will be refering to a embeded class
  789. //==================================================================
  790. else
  791. {
  792. hr = pTempChap->GetInstanceKey(hRow,pstrKey);
  793. }
  794. break;
  795. }
  796. pTempChap = pTempChap->m_pNext;
  797. }
  798. return hr;
  799. }
  800. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  801. // Function to check if the instance identified by the key exists
  802. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  803. BOOL CChapterMgr::IsInstanceExist(BSTR strKey)
  804. {
  805. BOOL bRet = FALSE;
  806. CChapter * pTempChap = m_pHead;
  807. while(pTempChap != NULL)
  808. {
  809. if(pTempChap->m_strKey != NULL && strKey != NULL)
  810. if(0 == wbem_wcsicmp(strKey,pTempChap->m_strKey))
  811. {
  812. bRet = TRUE;
  813. break;
  814. }
  815. pTempChap = pTempChap->m_pNext;
  816. }
  817. return bRet;
  818. }
  819. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  820. // Function to check if a instance exists
  821. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  822. BOOL CChapterMgr::IsInstanceExist(CWbemClassWrapper *pInstance)
  823. {
  824. BOOL bRet = FALSE;
  825. CChapter * pTempChap = m_pHead;
  826. while(pTempChap != NULL)
  827. {
  828. if(pTempChap->m_pInstance == pInstance)
  829. {
  830. bRet = TRUE;
  831. break;
  832. }
  833. pTempChap = pTempChap->m_pNext;
  834. }
  835. return bRet;
  836. }
  837. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  838. // Set the status of a particular row
  839. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  840. void CChapterMgr::SetRowStatus(HROW hRow , DWORD dwStatus)
  841. {
  842. CChapter *pTempChap = NULL;
  843. //======================================================
  844. // Get to the node which is being searched
  845. //======================================================
  846. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  847. {
  848. if(S_OK == pTempChap->IsHRowOfThisChapter(hRow))
  849. {
  850. pTempChap->SetRowStatus(hRow , dwStatus);
  851. break;
  852. } // if row is of this chapter
  853. }// for
  854. }
  855. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  856. // Get the status of a particular row
  857. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  858. DBSTATUS CChapterMgr::GetRowStatus(HROW hRow)
  859. {
  860. DBSTATUS dwStatus = DBROWSTATUS_S_OK;
  861. CChapter * pTempChap = NULL;
  862. //======================================================
  863. // Get to the node which is being searched
  864. //======================================================
  865. for( pTempChap = m_pHead ; pTempChap != NULL ; pTempChap = pTempChap->m_pNext)
  866. {
  867. if(S_OK == pTempChap->IsHRowOfThisChapter(hRow))
  868. {
  869. dwStatus = pTempChap->GetRowStatus(hRow);
  870. break;
  871. } // if row is of this chapter
  872. }// for
  873. return dwStatus;
  874. }
  875. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  876. // Set the status of a particular chapter
  877. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  878. void CChapterMgr::SetChapterStatus(HCHAPTER hChapter , DBSTATUS dwStatus)
  879. {
  880. CChapter *pTempChap = m_pHead;
  881. while(pTempChap != NULL)
  882. {
  883. if(pTempChap->m_hChapter == hChapter)
  884. {
  885. pTempChap->m_dwStatus &= dwStatus;
  886. break;
  887. }
  888. pTempChap = pTempChap->m_pNext;
  889. }
  890. }
  891. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  892. // Get the status of the chapter
  893. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  894. DBSTATUS CChapterMgr::GetChapterStatus(HCHAPTER hChapter)
  895. {
  896. DBSTATUS dwStatus = 0;
  897. CChapter * pTempChap = m_pHead;
  898. while(pTempChap != NULL)
  899. {
  900. if(pTempChap->m_hChapter == hChapter)
  901. {
  902. dwStatus = pTempChap->m_dwStatus;
  903. break;
  904. }
  905. pTempChap = pTempChap->m_pNext;
  906. }
  907. return dwStatus;
  908. }
  909. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  910. // Get a HROW of the row identified by the key
  911. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  912. HROW CChapterMgr::GetHRow(HCHAPTER hChapter, BSTR strInstKey)
  913. {
  914. HROW hRow = 0;
  915. CChapter *pTempChap = m_pHead;
  916. while(pTempChap != NULL)
  917. {
  918. if(pTempChap->m_hChapter == hChapter)
  919. {
  920. break;
  921. }
  922. pTempChap = pTempChap->m_pNext;
  923. }
  924. if(pTempChap != NULL )
  925. {
  926. if( pTempChap->m_lCount != 0)
  927. {
  928. if( strInstKey == NULL )
  929. {
  930. hRow = pTempChap->m_pFirstRow->m_hRow;
  931. }
  932. else
  933. {
  934. hRow = pTempChap->GetHRow(strInstKey);
  935. }
  936. }
  937. }
  938. return hRow;
  939. }
  940. ///////////////////////////////////////////////////////////////////////////////
  941. // CWMIInstanceMgr class Implementation
  942. //////////////////////////////////////////////////////////////////////////////
  943. ///////////////////////////////////////////////////////////////////////////////
  944. // Constructor
  945. //////////////////////////////////////////////////////////////////////////////
  946. CWMIInstanceMgr::CWMIInstanceMgr()
  947. {
  948. m_pFirst = NULL;
  949. m_lCount = 0;
  950. }
  951. ///////////////////////////////////////////////////////////////////////////////
  952. // Destructor
  953. //////////////////////////////////////////////////////////////////////////////
  954. CWMIInstanceMgr::~CWMIInstanceMgr()
  955. {
  956. CWMIInstance *pTempInst = NULL , *pTempInstToDel = NULL;
  957. pTempInstToDel = m_pFirst;
  958. while(pTempInstToDel != NULL)
  959. {
  960. pTempInst = pTempInstToDel->m_pNext;
  961. delete pTempInstToDel;
  962. pTempInstToDel = pTempInst;
  963. }
  964. }
  965. ///////////////////////////////////////////////////////////////////////////////////////
  966. // Add an instance to the list
  967. ///////////////////////////////////////////////////////////////////////////////////////
  968. HRESULT CWMIInstanceMgr::AddInstanceToList(HROW hRow,CWbemClassWrapper *pInstance, BSTR strKey ,HSLOT hSlot)
  969. {
  970. HRESULT hr = S_OK;
  971. CWMIInstance * pNewInstance = NULL;
  972. CWMIInstance * pTempInstance = NULL;
  973. try
  974. {
  975. pNewInstance = new CWMIInstance;
  976. }
  977. catch(...)
  978. {
  979. SAFE_DELETE_PTR(pNewInstance);
  980. throw;
  981. }
  982. if(pNewInstance == NULL)
  983. {
  984. hr = E_OUTOFMEMORY;
  985. }
  986. else
  987. {
  988. pNewInstance->m_pInstance = pInstance;
  989. pNewInstance->m_hRow = hRow;
  990. pNewInstance->m_hSlot = hSlot;
  991. pNewInstance->m_strKey = Wmioledb_SysAllocString(strKey);
  992. if(m_pFirst == NULL)
  993. {
  994. m_pFirst = pNewInstance;
  995. }
  996. else
  997. {
  998. //========================================================================
  999. // Navigate to the last instance in the list and link the new instance
  1000. //========================================================================
  1001. for(pTempInstance = m_pFirst ; pTempInstance->m_pNext != NULL ; pTempInstance = pTempInstance->m_pNext);
  1002. pTempInstance->m_pNext = pNewInstance;
  1003. }
  1004. m_lCount++;
  1005. }
  1006. return hr;
  1007. }
  1008. ///////////////////////////////////////////////////////////////////////////////////////
  1009. // Delete the instance identified from the given HROW from the list
  1010. ///////////////////////////////////////////////////////////////////////////////////////
  1011. HRESULT CWMIInstanceMgr::DeleteInstanceFromList(HROW hRow)
  1012. {
  1013. HRESULT hr = S_OK;
  1014. CWMIInstance * pTempInstance = NULL;
  1015. CWMIInstance * pTempInstToDel = NULL;
  1016. if(m_pFirst != NULL)
  1017. {
  1018. pTempInstance = m_pFirst;
  1019. //====================================================
  1020. // if the first one in the list is to be deleted
  1021. //====================================================
  1022. if(pTempInstance->m_hRow == hRow)
  1023. {
  1024. m_pFirst = pTempInstance->m_pNext;
  1025. delete pTempInstance;
  1026. }
  1027. else
  1028. {
  1029. while(pTempInstance->m_pNext != NULL)
  1030. {
  1031. if(pTempInstance->m_pNext->m_hRow == hRow)
  1032. {
  1033. pTempInstToDel = pTempInstance->m_pNext;
  1034. pTempInstance->m_pNext = pTempInstToDel->m_pNext;
  1035. delete pTempInstToDel;
  1036. break;
  1037. }
  1038. pTempInstance = pTempInstance->m_pNext;
  1039. } // while
  1040. } // else
  1041. m_lCount--;
  1042. } // if m_pFirst)
  1043. return hr;
  1044. }
  1045. ///////////////////////////////////////////////////////////////////////////////////////
  1046. // Get the pointer to the instance for the given HROW
  1047. ///////////////////////////////////////////////////////////////////////////////////////
  1048. CWbemClassWrapper * CWMIInstanceMgr::GetInstance(HROW hRow)
  1049. {
  1050. CWMIInstance * pTempInstance = NULL;
  1051. CWbemClassWrapper* pRetInst = NULL;
  1052. pTempInstance = m_pFirst;
  1053. while(pTempInstance != NULL)
  1054. {
  1055. if(pTempInstance->m_hRow == hRow)
  1056. {
  1057. pRetInst = pTempInstance->m_pInstance;
  1058. break;
  1059. }
  1060. pTempInstance = pTempInstance->m_pNext;
  1061. } // while
  1062. return pRetInst;
  1063. }
  1064. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1065. // Function to get instance key identified by HROW
  1066. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1067. HRESULT CWMIInstanceMgr::GetInstanceKey(HROW hRow,BSTR *strKey)
  1068. {
  1069. HRESULT hr = E_FAIL;
  1070. CWMIInstance * pTempInstance = NULL;
  1071. pTempInstance = m_pFirst;
  1072. while(pTempInstance != NULL)
  1073. {
  1074. if(pTempInstance->m_hRow == hRow)
  1075. {
  1076. hr = S_OK;
  1077. *strKey = Wmioledb_SysAllocString(pTempInstance->m_strKey);
  1078. break;
  1079. }
  1080. pTempInstance = pTempInstance->m_pNext;
  1081. } // while
  1082. return hr;
  1083. }
  1084. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1085. // Get all the HROWS in the list
  1086. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1087. HRESULT CWMIInstanceMgr::GetAllHROWs(HROW * &prghRows , DBCOUNTITEM &cRows)
  1088. {
  1089. CWMIInstance * pTempInstance = NULL;
  1090. int nIndex = 0;
  1091. HRESULT hr = E_OUTOFMEMORY;
  1092. pTempInstance = m_pFirst;
  1093. //==============================
  1094. // If there are any open rows
  1095. //==============================
  1096. if(m_lCount >0)
  1097. {
  1098. try
  1099. {
  1100. prghRows = new HROW[m_lCount];
  1101. }
  1102. catch(...)
  1103. {
  1104. SAFE_DELETE_PTR(prghRows);
  1105. throw;
  1106. }
  1107. if(prghRows != NULL)
  1108. {
  1109. cRows = m_lCount;
  1110. //=================================================
  1111. // Navigate through the list and get all HROWS
  1112. //=================================================
  1113. while(pTempInstance != NULL)
  1114. {
  1115. prghRows[nIndex++] = pTempInstance->m_hRow;
  1116. pTempInstance = pTempInstance->m_pNext;
  1117. }
  1118. hr = S_OK;
  1119. }
  1120. }
  1121. return hr;
  1122. }
  1123. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1124. // Check if the row identified by HROW exists
  1125. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1126. BOOL CWMIInstanceMgr::IsRowExists(HROW hRow)
  1127. {
  1128. BOOL bRet = FALSE;
  1129. if( hRow > 0)
  1130. if(NULL != GetInstance(hRow))
  1131. {
  1132. bRet = TRUE;
  1133. }
  1134. return bRet;
  1135. }
  1136. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1137. // Set the slot number for the row
  1138. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1139. HRESULT CWMIInstanceMgr::SetSlot(HROW hRow,HSLOT hSlot)
  1140. {
  1141. CWMIInstance * pTempInstance = NULL;
  1142. HRESULT hr = E_FAIL;
  1143. pTempInstance = m_pFirst;
  1144. while(pTempInstance != NULL)
  1145. {
  1146. if(pTempInstance->m_hRow == hRow)
  1147. {
  1148. pTempInstance->m_hSlot = hSlot;
  1149. hr = S_OK;
  1150. break;
  1151. }
  1152. pTempInstance = pTempInstance->m_pNext;
  1153. } // while
  1154. return hr;
  1155. }
  1156. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1157. // Get the slot number for the row
  1158. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1159. HSLOT CWMIInstanceMgr::GetSlot(HROW hRow)
  1160. {
  1161. HSLOT hSlot = -1;
  1162. CWMIInstance * pTempInstance = NULL;
  1163. pTempInstance = m_pFirst;
  1164. while(pTempInstance != NULL)
  1165. {
  1166. if(pTempInstance->m_hRow == hRow)
  1167. {
  1168. hSlot = pTempInstance->m_hSlot;
  1169. break;
  1170. }
  1171. pTempInstance = pTempInstance->m_pNext;
  1172. } // while
  1173. return hSlot;
  1174. }
  1175. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1176. // Check if the instance identified by the key exists in the list
  1177. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1178. BOOL CWMIInstanceMgr::IsInstanceExist(BSTR strKey)
  1179. {
  1180. BOOL bRet = FALSE;
  1181. CWMIInstance * pTempInstance = NULL;
  1182. pTempInstance = m_pFirst;
  1183. while(pTempInstance != NULL)
  1184. {
  1185. if(pTempInstance->m_strKey != NULL && strKey != NULL)
  1186. if(wbem_wcsicmp(pTempInstance->m_strKey,strKey) == 0)
  1187. {
  1188. bRet = TRUE;
  1189. break;
  1190. }
  1191. pTempInstance = pTempInstance->m_pNext;
  1192. } // while
  1193. return bRet;
  1194. }
  1195. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1196. // check if the instance identified from the pointer exists
  1197. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1198. BOOL CWMIInstanceMgr::IsInstanceExist(CWbemClassWrapper * pInstance)
  1199. {
  1200. BOOL bRet = FALSE;
  1201. CWMIInstance * pTempInstance = NULL;
  1202. pTempInstance = m_pFirst;
  1203. while(pTempInstance != NULL)
  1204. {
  1205. if(pTempInstance->m_pInstance == pInstance)
  1206. {
  1207. bRet = TRUE;
  1208. break;
  1209. }
  1210. pTempInstance = pTempInstance->m_pNext;
  1211. } // while
  1212. return bRet;
  1213. }
  1214. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1215. // Get the HROW identified by the key
  1216. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1217. HROW CWMIInstanceMgr::GetHRow(BSTR strKey)
  1218. {
  1219. HROW hRow = -1;
  1220. CWMIInstance * pTempInstance = NULL;
  1221. pTempInstance = m_pFirst;
  1222. while(pTempInstance != NULL)
  1223. {
  1224. if(pTempInstance->m_strKey != NULL && strKey != NULL)
  1225. if(wbem_wcsicmp(pTempInstance->m_strKey,strKey) == 0)
  1226. {
  1227. hRow = pTempInstance->m_hRow;
  1228. break;
  1229. }
  1230. pTempInstance = pTempInstance->m_pNext;
  1231. } // while
  1232. return hRow;
  1233. }
  1234. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1235. // Set the status of a particular row
  1236. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1237. void CWMIInstanceMgr::SetRowStatus(HROW hRow , DBSTATUS dwStatus)
  1238. {
  1239. CWMIInstance * pTempInstance = NULL;
  1240. pTempInstance = m_pFirst;
  1241. while(pTempInstance != NULL)
  1242. {
  1243. if(pTempInstance->m_hRow == hRow)
  1244. {
  1245. pTempInstance->SetRowStatus(dwStatus);
  1246. break;
  1247. }
  1248. pTempInstance = pTempInstance->m_pNext;
  1249. } // while
  1250. }
  1251. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1252. // Get the status of a particular row
  1253. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1254. DBSTATUS CWMIInstanceMgr::GetRowStatus(HROW hRow)
  1255. {
  1256. DBSTATUS dwStatus = DBROWSTATUS_E_FAIL;
  1257. CWMIInstance * pTempInstance = NULL;
  1258. pTempInstance = m_pFirst;
  1259. while(pTempInstance != NULL)
  1260. {
  1261. if(pTempInstance->m_hRow == hRow)
  1262. {
  1263. dwStatus = pTempInstance->GetRowStatus();
  1264. break;
  1265. }
  1266. pTempInstance = pTempInstance->m_pNext;
  1267. } // while
  1268. return dwStatus;
  1269. }