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.

180 lines
4.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. harray.h
  7. Index mgr for TAPI devices db
  8. FILE HISTORY:
  9. Dec 16 1997 EricDav Created
  10. */
  11. #ifndef _HARRAY_H__
  12. #define _HARRAY_H__
  13. #ifndef TAPI_H
  14. #include "tapi.h"
  15. #endif
  16. #ifndef _TAPIMMC_H
  17. #define _TAPIMMC_H
  18. #include "tapimmc.h"
  19. #endif
  20. #include "afxmt.h"
  21. typedef LPDEVICEINFO HDEVICE;
  22. typedef HDEVICE FAR * LPHDEVICE;
  23. typedef enum _INDEX_TYPE
  24. {
  25. INDEX_TYPE_NAME,
  26. INDEX_TYPE_USERS,
  27. INDEX_TYPE_STATUS
  28. } INDEX_TYPE;
  29. typedef enum _SORT_OPTIONS
  30. {
  31. SORT_DESCENDING = 0x00,
  32. SORT_ASCENDING = 0x01
  33. } SORT_OPTIONS;
  34. class CHDeviceIndex;
  35. typedef CArray<HDEVICE, HDEVICE> HDeviceArray;
  36. typedef CList<CHDeviceIndex *, CHDeviceIndex *> HDeviceArrayList;
  37. class CProviderIndexInfo
  38. {
  39. public:
  40. DWORD m_dwProviderID;
  41. HDeviceArrayList m_listIndicies;
  42. POSITION m_posCurrentIndex;
  43. };
  44. typedef CList<CProviderIndexInfo *, CProviderIndexInfo *> ProviderIndexList;
  45. // base class for a sorted index
  46. class CHDeviceIndex
  47. {
  48. public:
  49. CHDeviceIndex(INDEX_TYPE IndexType);
  50. virtual ~CHDeviceIndex();
  51. public:
  52. // used for insertion into the list
  53. virtual int BCompare(const void *, const void *) = 0;
  54. virtual HRESULT Sort(LPBYTE pStart) = 0;
  55. virtual HRESULT Add(HDEVICE hDevice, BOOL bEnd);
  56. virtual HRESULT Remove(HDEVICE hDevice);
  57. virtual HRESULT GetType(INDEX_TYPE * pIndexType);
  58. virtual HDEVICE GetHDevice(int nIndex);
  59. virtual int GetIndex(HDEVICE hDevice);
  60. BOOL IsAscending() { return m_bAscending; }
  61. void SetAscending(BOOL bAscending) { m_bAscending = bAscending; }
  62. HRESULT SetArray(HDeviceArray & hdeviceArray);
  63. HDeviceArray & GetArray() { return m_hdeviceArray; }
  64. void SetType(INDEX_TYPE indexType)
  65. {
  66. m_dbType = indexType;
  67. }
  68. void * BSearch(const void * key, const void * base, size_t num, size_t width);
  69. protected:
  70. INDEX_TYPE m_dbType;
  71. HDeviceArray m_hdeviceArray;
  72. BOOL m_bAscending;
  73. };
  74. // the Index manager
  75. class CIndexMgr : public HDeviceArrayList
  76. {
  77. public:
  78. CIndexMgr();
  79. virtual ~CIndexMgr();
  80. public:
  81. HRESULT Initialize();
  82. HRESULT Reset();
  83. UINT GetTotalCount();
  84. UINT GetCurrentCount();
  85. HRESULT AddHDevice(DWORD dwProviderID, HDEVICE hDevice, BOOL bLoading = FALSE);
  86. HRESULT RemoveHDevice(DWORD dwProviderID, HDEVICE hDevice);
  87. HRESULT Sort(DWORD dwProviderID, INDEX_TYPE SortType, DWORD dwSortOptions, LPBYTE pStart);
  88. HRESULT GetHDevice(DWORD dwProviderID, int nIndex, LPHDEVICE phdevice);
  89. HRESULT GetIndex(DWORD dwProviderID, HDEVICE hrow, int * pIndex);
  90. void CleanupIndicies();
  91. HRESULT SetCurrentProvider(DWORD dwProviderID);
  92. protected:
  93. ProviderIndexList m_listProviderIndex;
  94. POSITION m_posCurrentProvider;
  95. CCriticalSection m_cs;
  96. };
  97. // Index for name sorted
  98. class CIndexName : public CHDeviceIndex
  99. {
  100. public:
  101. CIndexName() : CHDeviceIndex(INDEX_TYPE_NAME) { };
  102. public:
  103. // used for insertion into the list
  104. int BCompare(const void *, const void *);
  105. // used for sorting the list
  106. virtual HRESULT Sort(LPBYTE pStart);
  107. static int __cdecl QCompareA(const void *, const void *);
  108. static int __cdecl QCompareD(const void *, const void *);
  109. };
  110. // Index for Users sorted
  111. class CIndexUsers : public CHDeviceIndex
  112. {
  113. public:
  114. CIndexUsers() : CHDeviceIndex(INDEX_TYPE_USERS) { };
  115. public:
  116. // used for insertion into the list
  117. int BCompare(const void *, const void *);
  118. // used for sorting the list
  119. virtual HRESULT Sort(LPBYTE pStart);
  120. static int __cdecl QCompareA(const void *, const void *);
  121. static int __cdecl QCompareD(const void *, const void *);
  122. };
  123. // Index for status sorted
  124. class CIndexStatus : public CHDeviceIndex
  125. {
  126. public:
  127. CIndexStatus() : CHDeviceIndex(INDEX_TYPE_STATUS) { };
  128. public:
  129. // used for insertion into the list
  130. int BCompare(const void *, const void *);
  131. // used for sorting the list
  132. virtual HRESULT Sort(LPBYTE pStart);
  133. static int __cdecl QCompareA(const void *, const void *);
  134. static int __cdecl QCompareD(const void *, const void *);
  135. };
  136. #endif //_HARRAY_H__