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.

254 lines
5.0 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. appdict.cxx
  5. Abstract:
  6. This file stores the indexes of all class assocation entries based on IID.
  7. Notes:
  8. History:
  9. VibhasC Sep-29-1996 Created.
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "precomp.hxx"
  15. void
  16. APPDICT::Clear()
  17. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  18. Routine Description:
  19. Clear the dictionary of all ITF_ENTRY indexes allocated.
  20. NOTE: tHIS FUNCTION DOES NOT DELETE THE ITF_ENTRY, BUT ONLY THE INDEX
  21. OF THE CLASS ENTRY
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. Notes:
  27. ----------------------------------------------------------------------------*/
  28. {
  29. Dict_Status Status;
  30. APP_ENTRY * pClassEntry;
  31. //
  32. // The way to delete all elements is to get to the top and then
  33. // do a get next, delete each one.
  34. //
  35. //
  36. // Note: Dict_Next() has a default parameter of null. This returns the
  37. // first record in the dictionary.
  38. //
  39. Status = Dict_Next();
  40. while( SUCCESS == Status )
  41. {
  42. pClassEntry = (APP_ENTRY *)Dict_Curr_Item();
  43. Status = Dict_Delete( (pUserType *) &pClassEntry );
  44. }
  45. }
  46. APP_ENTRY *
  47. APPDICT::GetFirst()
  48. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  49. Routine Description:
  50. Get the first item in the dictionary
  51. Arguments:
  52. None.
  53. Return Value:
  54. None.
  55. Notes:
  56. ----------------------------------------------------------------------------*/
  57. {
  58. Dict_Status Status;
  59. APP_ENTRY * pClassEntry;
  60. //
  61. // Dict_Next() has a default parameter of null. This returns the
  62. // first record in the dictionary.
  63. //
  64. Status = Dict_Next();
  65. if( SUCCESS == Status )
  66. return pClassEntry = (APP_ENTRY *)Dict_Curr_Item();
  67. else
  68. return 0;
  69. }
  70. APP_ENTRY *
  71. APPDICT::GetNext( APP_ENTRY * pLastClassEntry)
  72. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  73. Routine Description:
  74. Get the next item in the dictionary
  75. Arguments:
  76. pLastClassEntry.
  77. Return Value:
  78. None.
  79. Notes:
  80. pLastClassEntry is the entry returned by the previous call to GetFirst
  81. or GetNext. This is the seed for this search.
  82. This function returns a zero if there are no more entries in the
  83. dictionary.
  84. ----------------------------------------------------------------------------*/
  85. {
  86. Dict_Status Status;
  87. //
  88. // Dict_Next() has a default parameter of null. This returns the
  89. // first record in the dictionary. But if we supply the last searched
  90. // item, we get the next in the dictionary.
  91. //
  92. if( (Status = Dict_Next( pLastClassEntry) ) == SUCCESS )
  93. return pLastClassEntry = (APP_ENTRY *)Dict_Curr_Item();
  94. else
  95. return 0;
  96. }
  97. APP_ENTRY *
  98. APPDICT::Insert(
  99. APP_ENTRY * pClassEntry )
  100. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  101. Routine Description:
  102. Insert a class entry in the index.
  103. Arguments:
  104. Return Value:
  105. A pointer to the APP_ENTRY entry which was created and inserted.
  106. Notes:
  107. Search for the class association entry and if it exists, return that,
  108. do not create a new one.
  109. ----------------------------------------------------------------------------*/
  110. {
  111. Dict_Status Status = Dict_Find( pClassEntry );
  112. switch( Status )
  113. {
  114. case EMPTY_DICTIONARY:
  115. case ITEM_NOT_FOUND:
  116. Dict_Insert( (pUserType) pClassEntry );
  117. return pClassEntry;
  118. default:
  119. return (APP_ENTRY *)Dict_Curr_Item();
  120. }
  121. }
  122. APP_ENTRY *
  123. APPDICT::Search(
  124. char * Iid, DWORD Context )
  125. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  126. Routine Description:
  127. Search for a class entry in the dictionary.
  128. Arguments:
  129. pClassEntry - Name of the APP_ENTRY being searched for.
  130. Return Value:
  131. A pointer to the APP_ENTRY expression if found.
  132. NULL otherwise.
  133. Notes:
  134. ----------------------------------------------------------------------------*/
  135. {
  136. //
  137. // In order to search, we must create a dummy APP_ENTRY to compare
  138. // against. We initialize this with the class id passed and search for it.
  139. //
  140. APP_ENTRY DummyClassEntry;
  141. Dict_Status Status;
  142. memset(&DummyClassEntry, '\0', sizeof( APP_ENTRY ) );
  143. memcpy( (char *)&DummyClassEntry.AppIDString[0], Iid , SIZEOF_STRINGIZED_CLSID );
  144. //
  145. // Search.
  146. //
  147. Status = Dict_Find( &DummyClassEntry );
  148. switch( Status )
  149. {
  150. case EMPTY_DICTIONARY:
  151. case ITEM_NOT_FOUND:
  152. return (APP_ENTRY *)0;
  153. default:
  154. return (APP_ENTRY *)Dict_Curr_Item();
  155. }
  156. }
  157. int
  158. APPDICT::Compare(
  159. void * p1,
  160. void * p2 )
  161. {
  162. APP_ENTRY * pRes1 = (APP_ENTRY *)p1;
  163. APP_ENTRY * pRes2 = (APP_ENTRY *)p2;
  164. int Result;
  165. Result = _memicmp( p1, p2, SIZEOF_STRINGIZED_CLSID );
  166. Result = (Result < 0) ? -1 : (Result > 0) ? 1 : 0;
  167. return Result;
  168. }
  169. void
  170. PrintAPP_ENTRYKey( void * p )
  171. {
  172. ((void)(p));
  173. }