Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
5.2 KiB

  1. /*****************************************************************************\
  2. CFtpList.cpp - Internal list manager
  3. It is the caller's responsibility to manage any needed serialization.
  4. \*****************************************************************************/
  5. #include "priv.h"
  6. #include "ftplist.h"
  7. /*****************************************************************************\
  8. FUNCTION: CFtpList::DeleteItemPtr
  9. Remove the element "pv" from the array.
  10. \*****************************************************************************/
  11. void CFtpList::DeleteItemPtr(LPVOID pv)
  12. {
  13. int nIndex;
  14. ASSERT(m_hdpa);
  15. nIndex = DPA_GetPtrIndex(m_hdpa, pv);
  16. TraceMsg(TF_FTPLIST, "CFtpList::DeleteItemPtr(pv=%#08lx) this=%#08lx, nIndex=%d", pv, this, nIndex);
  17. if (-1 != nIndex)
  18. DPA_DeletePtr(m_hdpa, nIndex);
  19. }
  20. /*****************************************************************************\
  21. FUNCTION: AppendItem
  22. Add a new pv to the growing array.
  23. \*****************************************************************************/
  24. HRESULT CFtpList::AppendItem(LPVOID pv)
  25. {
  26. ASSERT(m_hdpa);
  27. DPA_AppendPtr(m_hdpa, pv);
  28. //TraceMsg(TF_FTPLIST, "CFtpList::AppendItem(pv=%#08lx) this=%#08lx", pv, this);
  29. return S_OK;
  30. }
  31. /*****************************************************************************\
  32. FUNCTION: InsertSorted
  33. Add a new pv to the growing array.
  34. \*****************************************************************************/
  35. HRESULT CFtpList::InsertSorted(LPVOID pv, PFNDPACOMPARE pfnCompare, LPARAM lParam)
  36. {
  37. ASSERT(m_hdpa);
  38. DPA_SortedInsertPtr(m_hdpa, pv, 0, pfnCompare, lParam, DPAS_INSERTBEFORE, pv);
  39. return S_OK;
  40. }
  41. /*****************************************************************************\
  42. FUNCTION: SortedSearch
  43. DESCRIPTION:
  44. Search thru the list for the item.
  45. \*****************************************************************************/
  46. int CFtpList::SortedSearch(LPVOID pv, PFNDPACOMPARE pfnCompare, LPARAM lParam, UINT options)
  47. {
  48. return DPA_Search(m_hdpa, pv, 0, pfnCompare, lParam, options);
  49. }
  50. /*****************************************************************************\
  51. FUNCTION: Find
  52. Call back once for each item in the pv list. Stops when the
  53. callback returns 0, returning the item that triggered the match.
  54. The callback typically returns the result of a comparison function.
  55. \*****************************************************************************/
  56. LPVOID CFtpList::Find(PFNDPACOMPARE pfn, LPCVOID pv)
  57. {
  58. LPVOID pvoid = NULL;
  59. int nIndex;
  60. nIndex = DPA_Search(m_hdpa, (LPVOID) pv, 0, pfn, NULL, 0);
  61. if (-1 != nIndex)
  62. pvoid = DPA_GetPtr(m_hdpa, nIndex);
  63. //TraceMsg(TF_FTPLIST, "CFtpList::Find(pfn=%#08lx; pv=%#08lx) this=%#08lx, nIndex=%d, result=%#08lx", pfn, pv, this, nIndex, pvoid);
  64. return pvoid;
  65. }
  66. /*****************************************************************************\
  67. CFtpList_Create
  68. Start up a new pv list, with a recommended initial size and other
  69. callback info.
  70. \*****************************************************************************/
  71. HRESULT CFtpList_Create(int cpvInit, PFNDPAENUMCALLBACK pfn, UINT nGrow, CFtpList ** ppfl)
  72. {
  73. HRESULT hres = E_OUTOFMEMORY;
  74. CFtpList * pfl = new CFtpList(pfn);
  75. *ppfl = pfl;
  76. if (pfl)
  77. {
  78. pfl->m_hdpa = DPA_Create(nGrow);
  79. //CFtpList_Create(pfn=%#08lx) this=%#08lx, cpvInit=%d, nGrow=%d", pfn, pfl, cpvInit, nGrow);
  80. if (EVAL(pfl->m_hdpa))
  81. hres = S_OK;
  82. else
  83. {
  84. pfl->Release();
  85. *ppfl = NULL;
  86. }
  87. }
  88. return hres;
  89. }
  90. /****************************************************\
  91. Constructor
  92. \****************************************************/
  93. CFtpList::CFtpList(PFNDPAENUMCALLBACK pfnDestroy) : m_cRef(1)
  94. {
  95. DllAddRef();
  96. // This needs to be allocated in Zero Inited Memory.
  97. // Assert that all Member Variables are inited to Zero.
  98. ASSERT(!m_hdpa);
  99. m_pfnDestroy = pfnDestroy;
  100. LEAK_ADDREF(LEAK_CFtpList);
  101. }
  102. /****************************************************\
  103. Destructor
  104. \****************************************************/
  105. CFtpList::~CFtpList()
  106. {
  107. //TraceMsg(TF_FTPLIST, "CFtpList::~CFtpList() this=%#08lx", this);
  108. if (m_pfnDestroy)
  109. DPA_DestroyCallback(m_hdpa, m_pfnDestroy, NULL);
  110. else
  111. DPA_Destroy(m_hdpa);
  112. DllRelease();
  113. LEAK_DELREF(LEAK_CFtpList);
  114. }
  115. //===========================
  116. // *** IUnknown Interface ***
  117. //===========================
  118. ULONG CFtpList::AddRef()
  119. {
  120. m_cRef++;
  121. return m_cRef;
  122. }
  123. ULONG CFtpList::Release()
  124. {
  125. ASSERT(m_cRef > 0);
  126. m_cRef--;
  127. if (m_cRef > 0)
  128. return m_cRef;
  129. delete this;
  130. return 0;
  131. }
  132. HRESULT CFtpList::QueryInterface(REFIID riid, void **ppvObj)
  133. {
  134. if (IsEqualIID(riid, IID_IUnknown))
  135. {
  136. *ppvObj = SAFECAST(this, IUnknown *);
  137. }
  138. else
  139. {
  140. TraceMsg(TF_FTPQI, "CFtpList::QueryInterface() failed.");
  141. *ppvObj = NULL;
  142. return E_NOINTERFACE;
  143. }
  144. AddRef();
  145. return S_OK;
  146. }