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.

385 lines
7.7 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. rpcobj.cxx
  5. Abstract:
  6. The implementation of the object dictionary lives in this file;
  7. it is used to map from an object uuid to a type uuid. From there
  8. we need to map to a manager entry point vector.
  9. Author:
  10. Michael Montague (mikemon) 14-Nov-1991
  11. Revision History:
  12. --*/
  13. #include <precomp.hxx>
  14. #include <rpcobj.hxx>
  15. static RPC_OBJECT_INQ_FN PAPI * ObjectTypeInquiryFn = 0;
  16. class OBJECT_ENTRY
  17. /*++
  18. Class Description:
  19. Each of the entries in the object dictionary consist of one of these
  20. objects.
  21. Fields:
  22. ObjectUuid - Contains the object uuid of this entry.
  23. TypeUuid - Contains the type uuid of the object uuid in this entry.
  24. DictionaryKey - Contains the key in the dictionary for this object
  25. entry. I made this a public instance variable for two reasons:
  26. (1) I was just going to defined a writer and a reader for
  27. it (routines to set and get the value).
  28. (2) This class is private to a source file, so it is very
  29. obvious the scope of usage.
  30. --*/
  31. {
  32. private:
  33. RPC_UUID ObjectUuid;
  34. RPC_UUID TypeUuid;
  35. public:
  36. unsigned int DictionaryKey;
  37. OBJECT_ENTRY (
  38. IN RPC_UUID PAPI * ObjectUuid,
  39. IN RPC_UUID PAPI * TypeUuid
  40. );
  41. int
  42. MatchObjectUuid (
  43. IN RPC_UUID PAPI * ObjectUuid
  44. );
  45. void
  46. CopyToTypeUuid (
  47. OUT RPC_UUID PAPI * TypeUuid
  48. );
  49. };
  50. OBJECT_ENTRY::OBJECT_ENTRY (
  51. IN RPC_UUID PAPI * ObjectUuid,
  52. IN RPC_UUID PAPI * TypeUuid
  53. )
  54. /*++
  55. Routine Description:
  56. This routine is used to construct an entry in the object dictionary.
  57. Arguments:
  58. ObjectUuid - Supplies the uuid to use to initialize the object uuid
  59. in this entry.
  60. TypeUuid - Supplies the uuid to use to initialize the type uuid in
  61. this entry.
  62. --*/
  63. {
  64. ALLOCATE_THIS(OBJECT_ENTRY);
  65. this->ObjectUuid.CopyUuid(ObjectUuid);
  66. this->TypeUuid.CopyUuid(TypeUuid);
  67. }
  68. inline int
  69. OBJECT_ENTRY::MatchObjectUuid (
  70. IN RPC_UUID PAPI * ObjectUuid
  71. )
  72. /*++
  73. Routine Description:
  74. This method compares the supplied object uuid against the object
  75. uuid contained in this object entry.
  76. Arguments:
  77. ObjectUuid - Supplies the object uuid.
  78. Return Value:
  79. Zero will be returned if the supplied object uuid is the same as the
  80. object uuid contained in this.
  81. --*/
  82. {
  83. return(this->ObjectUuid.MatchUuid(ObjectUuid));
  84. }
  85. inline void
  86. OBJECT_ENTRY::CopyToTypeUuid (
  87. OUT RPC_UUID PAPI * TypeUuid
  88. )
  89. /*++
  90. Routine Description:
  91. We copy the type uuid for this object entry into the supplied type
  92. uuid.
  93. Arguments:
  94. TypeUuid - Returns a copy of the type uuid in this object entry.
  95. --*/
  96. {
  97. TypeUuid->CopyUuid(&(this->TypeUuid));
  98. }
  99. NEW_SDICT(OBJECT_ENTRY);
  100. OBJECT_ENTRY_DICT * ObjectDictionary;
  101. OBJECT_ENTRY *
  102. FindObject (
  103. IN RPC_UUID PAPI * ObjectUuid
  104. )
  105. /*++
  106. Routine Description:
  107. This routine is used to find the object entry in the object dictionary
  108. having the specified object uuid.
  109. Arguments:
  110. ObjectUuid - Supplies the object uuid which we wish to find.
  111. Return Value:
  112. The object entry having the supplied object uuid will be returned if
  113. it can be found, otherwise, zero will be returned.
  114. --*/
  115. {
  116. OBJECT_ENTRY * ObjectEntry;
  117. DictionaryCursor cursor;
  118. ObjectDictionary->Reset(cursor);
  119. while ((ObjectEntry = ObjectDictionary->Next(cursor)) != 0)
  120. {
  121. if (ObjectEntry->MatchObjectUuid(ObjectUuid) == 0)
  122. return(ObjectEntry);
  123. }
  124. return(0);
  125. }
  126. RPC_STATUS
  127. ObjectInqType (
  128. IN RPC_UUID PAPI * ObjUuid,
  129. OUT RPC_UUID PAPI * TypeUuid
  130. )
  131. /*++
  132. Routine Description:
  133. We search in the dictionary for the specified object UUID; if it
  134. is found, we return its type UUID.
  135. Parameters:
  136. ObjUuid - Supplies the object UUID for which we are trying to
  137. find the type UUID.
  138. TypeUuid - Returns the type UUID of the object UUID, presuming
  139. that the object UUID is found.
  140. Return Value:
  141. RPC_S_OK - The operation completed successfully; the object uuid
  142. is registered with the runtime or the object inquiry function
  143. knows the object uuid.
  144. RPC_S_OBJECT_NOT_FOUND - The specified object uuid has not been
  145. registered with the runtime and the object inquiry function
  146. does not know about the object uuid.
  147. --*/
  148. {
  149. RPC_STATUS Status;
  150. OBJECT_ENTRY * ObjectEntry;
  151. if ( ObjUuid == NULL
  152. || ObjUuid->IsNullUuid())
  153. {
  154. TypeUuid->SetToNullUuid();
  155. return(RPC_S_OK);
  156. }
  157. RequestGlobalMutex();
  158. ObjectEntry = FindObject(ObjUuid);
  159. if (ObjectEntry == 0)
  160. {
  161. if (ObjectTypeInquiryFn == 0)
  162. {
  163. ClearGlobalMutex();
  164. TypeUuid->SetToNullUuid();
  165. return(RPC_S_OBJECT_NOT_FOUND);
  166. }
  167. ClearGlobalMutex();
  168. (*ObjectTypeInquiryFn)((UUID PAPI *) ObjUuid, (UUID PAPI *) TypeUuid,
  169. &Status);
  170. return(Status);
  171. }
  172. ObjectEntry->CopyToTypeUuid(TypeUuid);
  173. ClearGlobalMutex();
  174. return(RPC_S_OK);
  175. }
  176. RPC_STATUS
  177. ObjectSetInqFn (
  178. IN RPC_OBJECT_INQ_FN PAPI * InquiryFn
  179. )
  180. /*++
  181. Routine Description:
  182. With just two lines of code, the comment for this routine is
  183. already longer than the routine.
  184. Arguments:
  185. InquiryFn - Supplies a function to be used when the type of an
  186. unknown object is inquired.
  187. Return Value:
  188. RPC_S_OK - This is always returned by the second line of code.
  189. --*/
  190. {
  191. ObjectTypeInquiryFn = InquiryFn;
  192. return(RPC_S_OK);
  193. }
  194. RPC_STATUS
  195. ObjectSetType (
  196. IN RPC_UUID PAPI * ObjUuid,
  197. IN RPC_UUID PAPI * TypeUuid OPTIONAL
  198. )
  199. /*++
  200. Routine Description:
  201. This routine is used to associate a type UUID with an object UUID.
  202. Arguments:
  203. ObjUuid - Supplies the object UUID.
  204. TypeUuid - Supplies the type UUID to associate with the object
  205. UUID.
  206. Return Value:
  207. RPC_S_OK - The type UUID was successfully associated with the
  208. object UUID.
  209. RPC_S_ALREADY_REGISTERED - The object uuid specified has already
  210. been registered with the runtime.
  211. RPC_S_OUT_OF_MEMORY - There is insufficient memory available to
  212. associate the object UUID with the type UUID.
  213. RPC_S_INVALID_OBJECT - The object uuid specified is the nil uuid.
  214. --*/
  215. {
  216. OBJECT_ENTRY * ObjectEntry;
  217. if ( ObjUuid->IsNullUuid() != 0 )
  218. {
  219. return(RPC_S_INVALID_OBJECT);
  220. }
  221. RequestGlobalMutex();
  222. ObjectEntry = FindObject(ObjUuid);
  223. if ( (ARGUMENT_PRESENT(TypeUuid) == 0)
  224. || (TypeUuid->IsNullUuid() != 0))
  225. {
  226. if (ObjectEntry != 0)
  227. {
  228. ObjectDictionary->Delete(ObjectEntry->DictionaryKey);
  229. ClearGlobalMutex();
  230. return(RPC_S_OK);
  231. }
  232. ClearGlobalMutex();
  233. return(RPC_S_OK);
  234. }
  235. if (ObjectEntry != 0)
  236. {
  237. ClearGlobalMutex();
  238. return(RPC_S_ALREADY_REGISTERED);
  239. }
  240. ObjectEntry = new OBJECT_ENTRY(ObjUuid,TypeUuid);
  241. if (ObjectEntry == 0)
  242. {
  243. ClearGlobalMutex();
  244. return(RPC_S_OUT_OF_MEMORY);
  245. }
  246. ObjectEntry->DictionaryKey = ObjectDictionary->Insert(ObjectEntry);
  247. if (ObjectEntry->DictionaryKey == -1)
  248. {
  249. ClearGlobalMutex();
  250. delete ObjectEntry;
  251. return(RPC_S_OUT_OF_MEMORY);
  252. }
  253. ClearGlobalMutex();
  254. return(RPC_S_OK);
  255. }
  256. int
  257. InitializeObjectDictionary (
  258. )
  259. /*++
  260. Routine Description:
  261. At DLL initialization time, this routine will get called.
  262. Return Value:
  263. Zero will be returned if initialization completes successfully;
  264. otherwise, non-zero will be returned.
  265. --*/
  266. {
  267. ObjectDictionary = new OBJECT_ENTRY_DICT;
  268. if (ObjectDictionary == 0)
  269. return(1);
  270. return(0);
  271. }