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.

203 lines
4.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: propmap.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-11-96 srikants Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <pch.cxx>
  18. #pragma hdrstop
  19. #include <propmap.hxx>
  20. #include <pidtable.hxx>
  21. CFwPropertyMapper::~CFwPropertyMapper()
  22. {
  23. if ( _fOwned )
  24. delete _pPidTable;
  25. delete _papsShortLived;
  26. }
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Member: CFwPropertyMapper::QueryInterface
  30. //
  31. // Synopsis: Supports IID_IUnknown and IID_IPropertyMapper.
  32. //
  33. // History: 11-27-96 srikants Created
  34. //
  35. //----------------------------------------------------------------------------
  36. STDMETHODIMP CFwPropertyMapper::QueryInterface(
  37. REFIID riid,
  38. void **ppvObject)
  39. {
  40. Win4Assert( 0 != ppvObject );
  41. if ( IID_IPropertyMapper == riid )
  42. *ppvObject = (void *)((IPropertyMapper *)this);
  43. else if ( IID_IUnknown == riid )
  44. *ppvObject = (void *)((IUnknown *) (IPropertyMapper *) this);
  45. else
  46. {
  47. *ppvObject = 0;
  48. return E_NOINTERFACE;
  49. }
  50. AddRef();
  51. return S_OK;
  52. } //QueryInterface
  53. //+---------------------------------------------------------------------------
  54. //
  55. // Member: CFwPropertyMapper::AddRef
  56. //
  57. // History: 11-22-96 srikants Created
  58. //
  59. //----------------------------------------------------------------------------
  60. STDMETHODIMP_(ULONG) CFwPropertyMapper::AddRef()
  61. {
  62. return InterlockedIncrement(&_refCount);
  63. } //AddRef
  64. //+---------------------------------------------------------------------------
  65. //
  66. // Member: CFwPropertyMapper::Release
  67. //
  68. // History: 11-22-96 srikants Created
  69. //
  70. //----------------------------------------------------------------------------
  71. STDMETHODIMP_(ULONG) CFwPropertyMapper::Release()
  72. {
  73. Win4Assert( _refCount > 0 );
  74. LONG refCount = InterlockedDecrement(&_refCount);
  75. if ( refCount <= 0 )
  76. delete this;
  77. return (ULONG) refCount;
  78. } //Release
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Member: CFwPropertyMapper::PropertyToPropid
  82. //
  83. // Synopsis: Maps a FULLPROPSPEC into a 32bit PropertyId.
  84. //
  85. // Arguments: [fps] - FULLPROPSPEC of the property to be converted
  86. // [fCreate] - If set to TRUE, the pid will be created if the
  87. // property is a new one.
  88. // [pPropId] - On output, will have the pid.
  89. //
  90. // Returns: S_OK if successful, other error code as appropriate.
  91. //
  92. // History: 12-11-96 srikants Created
  93. //
  94. //----------------------------------------------------------------------------
  95. STDMETHODIMP CFwPropertyMapper::PropertyToPropid(
  96. FULLPROPSPEC const * fps,
  97. BOOL fCreate,
  98. PROPID * pPropId )
  99. {
  100. Win4Assert( fps );
  101. Win4Assert( pPropId );
  102. CFullPropSpec const * ps = (CFullPropSpec *) fps;
  103. PROPID pid = _propMapper.StandardPropertyToPropId( *ps );
  104. if ( pidInvalid != pid )
  105. {
  106. *pPropId = pid;
  107. return S_OK;
  108. }
  109. SCODE sc = S_OK;
  110. TRY
  111. {
  112. //
  113. // Since a null catalog didn't have an opportunity
  114. // to enter properties into the prop store, we have to
  115. // let it enter them into a in memory table whose
  116. // lifetime is that of the null catalog.
  117. //
  118. if (_fMapStdOnly)
  119. *pPropId = LocateOrAddProperty(*ps);
  120. else
  121. _pPidTable->FindPropid( *ps, *pPropId, fCreate );
  122. }
  123. CATCH( CException,e )
  124. {
  125. sc = e.GetErrorCode();
  126. }
  127. END_CATCH
  128. return sc;
  129. }
  130. //+-------------------------------------------------------------------------
  131. //
  132. // Method: CFwPropertyMapper::LocateOrAddProperty, private
  133. //
  134. // Synopsis: Lookup property and enter if it doesn't exist.
  135. //
  136. // Arguments: [ps] -- Property specification (name)
  137. //
  138. // Returns: The pid of [ps].
  139. //
  140. // History: 23-July-1997 KrishnaN Created
  141. //
  142. //--------------------------------------------------------------------------
  143. PROPID CFwPropertyMapper::LocateOrAddProperty(CFullPropSpec const & ps)
  144. {
  145. PROPID pid = pidInvalid;
  146. //
  147. // Create pid good only for life of catalog.
  148. //
  149. //
  150. // Have we seen this property before? Use linear search since
  151. // we shouldn't have too many of these.
  152. //
  153. for ( unsigned i = 0; i < _cps; i++ )
  154. {
  155. if ( ps == _papsShortLived->Get(i)->PS() )
  156. break;
  157. }
  158. if ( i < _cps )
  159. {
  160. pid = _papsShortLived->Get(i)->Pid();
  161. }
  162. else
  163. {
  164. pid = _pidNextAvailable++;
  165. CPropSpecPidMap * ppm = new CPropSpecPidMap( ps, pid );
  166. _papsShortLived->Add( ppm, _cps );
  167. _cps++;
  168. }
  169. return pid;
  170. }