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.

200 lines
6.8 KiB

  1. //
  2. // catmgr.h
  3. //
  4. #ifndef CATMGR_H
  5. #define CATMGR_H
  6. #include "private.h"
  7. #include "strary.h"
  8. #include "enumguid.h"
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // CCatGUIDTbl
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #define CATGUID_HASHSIZE 31
  15. #define ValidGUIDHash(hashid) (hashid < CATGUID_HASHSIZE)
  16. #define ValidGUIDARRAYCount(cnt) (cnt < 0x07ffffff)
  17. #define MAKEGUIDATOM(cnt, hashid) (cnt * 32 | (hashid + 1))
  18. #define HASHIDFROMGUIDATOM(atom) ((atom & 0x1f) - 1)
  19. #define IDFROMGUIDATOM(atom) (atom / 32)
  20. typedef enum { CAT_FORWARD = 0x0,
  21. CAT_BACKWARD = 0x1
  22. } CATDIRECTION;
  23. typedef struct tag_CATGUIDITEM {
  24. GUID guid;
  25. SHARED_GUID_ARRAY *rgGuidAry[2];
  26. } CATGUIDITEM;
  27. class CCatGUIDTbl
  28. {
  29. public:
  30. CCatGUIDTbl() {}
  31. ~CCatGUIDTbl()
  32. {
  33. for (int i = 0; i < CATGUID_HASHSIZE; i++)
  34. {
  35. if (_prgCatGUID[i])
  36. {
  37. int nCnt = _prgCatGUID[i]->Count();
  38. for (int j = 0; j < nCnt; j++)
  39. {
  40. CATGUIDITEM *pItem = _prgCatGUID[i]->GetPtr(j);
  41. SGA_Release(pItem->rgGuidAry[CAT_FORWARD]);
  42. SGA_Release(pItem->rgGuidAry[CAT_BACKWARD]);
  43. }
  44. delete _prgCatGUID[i];
  45. }
  46. }
  47. }
  48. void FreeCatCache()
  49. {
  50. for (int i = 0; i < CATGUID_HASHSIZE; i++)
  51. {
  52. if (_prgCatGUID[i])
  53. {
  54. int nCnt = _prgCatGUID[i]->Count();
  55. for (int j = 0; j < nCnt; j++)
  56. {
  57. CATGUIDITEM *pItem = _prgCatGUID[i]->GetPtr(j);
  58. SGA_Release(pItem->rgGuidAry[CAT_FORWARD]);
  59. SGA_Release(pItem->rgGuidAry[CAT_BACKWARD]);
  60. pItem->rgGuidAry[CAT_FORWARD] = NULL;
  61. pItem->rgGuidAry[CAT_BACKWARD] = NULL;
  62. }
  63. }
  64. }
  65. }
  66. TfGuidAtom Add(REFGUID rguid);
  67. TfGuidAtom FindGuid(REFGUID rguid);
  68. CATGUIDITEM *GetGUID(TfGuidAtom atom);
  69. private:
  70. UINT _HashFunc(REFGUID rguid)
  71. {
  72. return (DWORD)rguid.Data1 % CATGUID_HASHSIZE;
  73. }
  74. CStructArray<CATGUIDITEM> *_prgCatGUID[CATGUID_HASHSIZE];
  75. };
  76. //////////////////////////////////////////////////////////////////////////////
  77. //
  78. // CCategoryMgr
  79. //
  80. //////////////////////////////////////////////////////////////////////////////
  81. // perf: this class doesn't really need CComObjectRootImmx, it is stateless
  82. class CCategoryMgr :
  83. public ITfCategoryMgr,
  84. public CComObjectRoot_CreateInstance<CCategoryMgr>
  85. {
  86. public:
  87. CCategoryMgr();
  88. ~CCategoryMgr();
  89. BEGIN_COM_MAP_IMMX(CCategoryMgr)
  90. COM_INTERFACE_ENTRY(ITfCategoryMgr)
  91. END_COM_MAP_IMMX()
  92. //
  93. // ITfCategoryMgr
  94. //
  95. STDMETHODIMP RegisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid);
  96. STDMETHODIMP UnregisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid);
  97. STDMETHODIMP EnumCategoriesInItem(REFGUID rguid, IEnumGUID **ppEnum);
  98. STDMETHODIMP EnumItemsInCategory(REFGUID rcatid, IEnumGUID **ppEnum);
  99. STDMETHODIMP FindClosestCategory(REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount);
  100. STDMETHODIMP RegisterGUIDDescription(REFCLSID rclsid, REFGUID rguid, const WCHAR *pchDesc, ULONG cch);
  101. STDMETHODIMP UnregisterGUIDDescription(REFCLSID rclsid, REFGUID rguid);
  102. STDMETHODIMP GetGUIDDescription(REFGUID rguid, BSTR *pbstrDesc);
  103. STDMETHODIMP RegisterGUIDDWORD(REFCLSID rclsid, REFGUID rguid, DWORD dw);
  104. STDMETHODIMP UnregisterGUIDDWORD(REFCLSID rclsid, REFGUID rguid);
  105. STDMETHODIMP GetGUIDDWORD(REFGUID rguid, DWORD *pdw);
  106. STDMETHODIMP RegisterGUID(REFGUID rguid, TfGuidAtom *pguidatom);
  107. STDMETHODIMP GetGUID(TfGuidAtom guidatom, GUID *pguid);
  108. STDMETHODIMP IsEqualTfGuidAtom(TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual);
  109. static BOOL InitGlobal();
  110. static BOOL s_IsValidGUIDATOM(TfGuidAtom guidatom)
  111. {
  112. if (!_pCatGUIDTbl)
  113. return FALSE;
  114. return _pCatGUIDTbl->GetGUID(guidatom) ? TRUE : FALSE;
  115. }
  116. static void UninitGlobal()
  117. {
  118. if (_pCatGUIDTbl)
  119. delete _pCatGUIDTbl;
  120. _pCatGUIDTbl = NULL;
  121. }
  122. static void FreeCatCache()
  123. {
  124. CicEnterCriticalSection(g_cs);
  125. if (_pCatGUIDTbl)
  126. _pCatGUIDTbl->FreeCatCache();
  127. CicLeaveCriticalSection(g_cs);
  128. }
  129. static HRESULT s_RegisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid);
  130. static HRESULT s_UnregisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid);
  131. static HRESULT s_EnumCategoriesInItem(REFGUID rguid, IEnumGUID **ppEnum);
  132. static HRESULT s_EnumItemsInCategory(REFGUID rcatid, IEnumGUID **ppEnum);
  133. static HRESULT s_RegisterGUID(REFGUID rguid, TfGuidAtom *pguidatom);
  134. static HRESULT s_GetGUID(TfGuidAtom guidatom, GUID *pguid);
  135. static HRESULT s_IsEqualTfGuidAtom(TfGuidAtom guidatom, REFGUID rguid, BOOL *pfEqual);
  136. static HRESULT s_FindClosestCategory(REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount);
  137. static HRESULT s_RegisterGUIDDescription(REFCLSID rclsid, REFGUID rguid, WCHAR *pszDesc);
  138. static HRESULT s_UnregisterGUIDDescription(REFCLSID rclsid, REFGUID rguid);
  139. static HRESULT s_GetGUIDDescription(REFGUID rguid, BSTR *pbstrDesc);
  140. static HRESULT s_GetGUIDValue(REFGUID rguid, const WCHAR* pszValue, BSTR *pbstrDesc);
  141. static HRESULT s_RegisterGUIDDWORD(REFCLSID rclsid, REFGUID rguid, DWORD dw);
  142. static HRESULT s_UnregisterGUIDDWORD(REFCLSID rclsid, REFGUID rguid);
  143. static HRESULT s_GetGUIDDWORD(REFGUID rguid, DWORD *pdw);
  144. static CCatGUIDTbl *_pCatGUIDTbl;
  145. private:
  146. static HRESULT _InternalRegisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid, CATDIRECTION catdir);
  147. static HRESULT _InternalUnregisterCategory(REFCLSID rclsid, REFGUID rcatid, REFGUID rguid, CATDIRECTION catdir);
  148. static HRESULT _InternalEnumCategories(REFGUID rguid, IEnumGUID **ppEnum, CATDIRECTION catdir);
  149. static HRESULT _InternalFindClosestCategory(REFGUID rguidOrg, REFGUID rguid, GUID *pcatid, const GUID **ppcatidList, ULONG ulCount);
  150. static HRESULT _GetFirstCategory(REFGUID rguid, GUID *pcatid);
  151. static void _FlushGuidArrayCache(REFGUID rguid, CATDIRECTION catdir);
  152. DBG_ID_DECLARE;
  153. };
  154. //////////////////////////////////////////////////////////////////////////////
  155. //
  156. // CEnumCategories
  157. //
  158. //////////////////////////////////////////////////////////////////////////////
  159. class CEnumCategories : public CEnumGuid
  160. {
  161. public:
  162. CEnumCategories();
  163. BOOL _Init(REFGUID rcatid, CATDIRECTION catdir);
  164. DBG_ID_DECLARE;
  165. };
  166. #endif // CATMGR_H