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.

194 lines
5.4 KiB

  1. //+------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1991-1997 Microsoft Corporation.
  4. //
  5. // File: identran.cxx
  6. //
  7. // Contents: Identity workid <--> doc name translator
  8. //
  9. // Classes: CIdentityNameTranslator
  10. //
  11. // History: 24-Feb-97 SitaramR Created
  12. //
  13. //-------------------------------------------------------------------
  14. #include <pch.cxx>
  15. #pragma hdrstop
  16. #include "identran.hxx"
  17. #include "docname.hxx"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Member: CIdentityNameTranslator::CIdentityNameTranslator
  21. //
  22. // Synopsis: Constructor
  23. //
  24. // History: 24-Feb-97 SitaramR Created
  25. //
  26. //----------------------------------------------------------------------------
  27. CIdentityNameTranslator::CIdentityNameTranslator()
  28. : _cRefs( 1 )
  29. {
  30. }
  31. //+-------------------------------------------------------------------------
  32. //
  33. // Method: CIdentityNameTranslator::AddRef
  34. //
  35. // Synopsis: Increments refcount
  36. //
  37. // History: 24-Feb-1997 SitaramR Created
  38. //
  39. //--------------------------------------------------------------------------
  40. ULONG STDMETHODCALLTYPE CIdentityNameTranslator::AddRef()
  41. {
  42. return InterlockedIncrement( (long *) &_cRefs );
  43. }
  44. //+-------------------------------------------------------------------------
  45. //
  46. // Method: CIdentityNameTranslator::Release
  47. //
  48. // Synopsis: Decrement refcount. Delete if necessary.
  49. //
  50. // History: 24-Feb-1997 SitaramR Created
  51. //
  52. //--------------------------------------------------------------------------
  53. ULONG STDMETHODCALLTYPE CIdentityNameTranslator::Release()
  54. {
  55. Win4Assert( _cRefs > 0 );
  56. ULONG uTmp = InterlockedDecrement( (long *) &_cRefs );
  57. if ( 0 == uTmp )
  58. delete this;
  59. return(uTmp);
  60. }
  61. //+-------------------------------------------------------------------------
  62. //
  63. // Method: CIdentityNameTranslator::QueryInterface
  64. //
  65. // Synopsis: Rebind to other interface
  66. //
  67. // Arguments: [riid] -- IID of new interface
  68. // [ppvObject] -- New interface * returned here
  69. //
  70. // Returns: S_OK if bind succeeded, E_NOINTERFACE if bind failed
  71. //
  72. // History: 24-Feb-1997 SitaramR Created
  73. //
  74. //--------------------------------------------------------------------------
  75. SCODE STDMETHODCALLTYPE CIdentityNameTranslator::QueryInterface( REFIID riid,
  76. void ** ppvObject)
  77. {
  78. Win4Assert( 0 != ppvObject );
  79. if ( riid == IID_ICiCDocNameToWorkidTranslator )
  80. *ppvObject = (void *)(ICiCDocNameToWorkidTranslator *) this;
  81. else if ( riid == IID_IUnknown )
  82. *ppvObject = (void *)(IUnknown *) this;
  83. else
  84. {
  85. *ppvObject = 0;
  86. return E_NOINTERFACE;
  87. }
  88. AddRef();
  89. return S_OK;
  90. }
  91. //+---------------------------------------------------------------------------
  92. //
  93. // Member: CIdentityNameTranslator::QueryDocName
  94. //
  95. // Synopsis: Returns a new doc name object
  96. //
  97. // Arguments: [ppICiCDocName] - Pointer to ICiCDocName object returned here
  98. //
  99. // History: 24-Feb-97 SitaramR Created
  100. //
  101. //----------------------------------------------------------------------------
  102. SCODE STDMETHODCALLTYPE CIdentityNameTranslator::QueryDocName( ICiCDocName ** ppICiCDocName )
  103. {
  104. Win4Assert( 0 != ppICiCDocName );
  105. SCODE sc = S_OK;
  106. TRY
  107. {
  108. *ppICiCDocName = new CCiCDocName;
  109. }
  110. CATCH( CException,e )
  111. {
  112. sc = e.GetErrorCode();
  113. }
  114. END_CATCH
  115. return sc;
  116. }
  117. //+---------------------------------------------------------------------------
  118. //
  119. // Member: CIdentityNameTranslator::WorkIdToDocName
  120. //
  121. // Synopsis: Translates a WorkId to a document name
  122. //
  123. // Arguments: [workid] - WorkId to translate
  124. // [pICiCDocName] - Doc Name filled in here
  125. //
  126. // History: 24-Feb-1997 SitaramR Created
  127. //
  128. //----------------------------------------------------------------------------
  129. SCODE STDMETHODCALLTYPE CIdentityNameTranslator::WorkIdToDocName( WORKID workid,
  130. ICiCDocName * pICiCDocName )
  131. {
  132. //
  133. // The name is a serialized form of wid, i.e. 4 bytes long
  134. //
  135. Win4Assert( sizeof(WORKID) == 2 * sizeof(WCHAR) );
  136. CCiCDocName *pDocName = (CCiCDocName *) pICiCDocName;
  137. pDocName->SetPath( (WCHAR *)&workid, sizeof(WORKID)/sizeof(WCHAR) );
  138. return S_OK;
  139. }
  140. //+---------------------------------------------------------------------------
  141. //
  142. // Member: CIdentityNameTranslator::DocNameToWorkId
  143. //
  144. // Synopsis: Converts a document name to a WorkId.
  145. //
  146. // Arguments: [pICiCDocName] - Document Name
  147. // [pWorkid] - Workid returned here
  148. //
  149. // History: 24-Feb-1997 SitaramR Created
  150. //
  151. //----------------------------------------------------------------------------
  152. SCODE STDMETHODCALLTYPE CIdentityNameTranslator::DocNameToWorkId( ICiCDocName const * pICiCDocName,
  153. WORKID * pWorkid )
  154. {
  155. Win4Assert( 0 != pICiCDocName );
  156. Win4Assert( 0 != pWorkid );
  157. CCiCDocName const * pDocName = (CCiCDocName const *) pICiCDocName;
  158. WCHAR const *pwszPath = pDocName->GetPath();
  159. RtlCopyMemory( pWorkid, pwszPath, sizeof(WORKID) );
  160. return S_OK;
  161. }