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.

137 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999.
  5. //
  6. // File: accbase.hxx
  7. //
  8. // Class: CAccessorBase
  9. //
  10. // Purpose: Base class for CAccessor and CDistributedAccessor. Handles
  11. // accessor refcount, type, and tracks # of current rowsets
  12. // have an inherited copy of the accessor.
  13. //
  14. // History: 22 Apr 1997 emilyb created
  15. //
  16. //--------------------------------------------------------------------------
  17. #pragma once
  18. #include <tbag.hxx>
  19. class CAccessorBase
  20. {
  21. public:
  22. enum EAccessorType {
  23. eInvalidAccessor,
  24. eRowDataAccessor,
  25. eParamsDataAccessor,
  26. };
  27. CAccessorBase (void * pCreator, EAccessorType eType) :
  28. _pCreator(pCreator), _hAccessorParent(0),
  29. _type(eType), _cRef(1),
  30. _cInheritors(0) {}
  31. virtual ~CAccessorBase() {}
  32. void * GetCreator() {return _pCreator;}
  33. virtual ULONG AddRef()
  34. {
  35. return InterlockedIncrement( (LONG *) &_cRef );
  36. }
  37. virtual ULONG Release()
  38. {
  39. // CAccessorBag does the destroy
  40. return InterlockedDecrement( (LONG *) &_cRef );
  41. }
  42. ULONG GetRefcount() { return _cRef; }
  43. BOOL IsValidType() const { return _type == eRowDataAccessor ||
  44. _type == eParamsDataAccessor; }
  45. void SetInvalid( void ) { _type = eInvalidAccessor; };
  46. EAccessorType GetAccessorType() const { return _type; }
  47. BOOL IsRowDataAccessor() const { return eRowDataAccessor == _type; }
  48. CAccessorBase * GetParent() {return _hAccessorParent;}
  49. void SetParent(CAccessorBase * hParent) { _hAccessorParent = hParent;}
  50. ULONG IncInheritors() { return ++_cInheritors; }
  51. ULONG DecInheritors() { return --_cInheritors; }
  52. ULONG GetInheritorCount() { return _cInheritors; }
  53. virtual SCODE GetBindings( DBACCESSORFLAGS * pBindIo,
  54. DBCOUNTITEM * pcBindings,
  55. DBBINDING ** ppBindings) = 0 ;
  56. protected:
  57. ULONG _cRef;
  58. private:
  59. void *_pCreator; // this pointer of comamnd or rowset that
  60. // called CreateAccessor to create this accessor
  61. CAccessorBase * _hAccessorParent; // if this accessor was inherited from a command,
  62. // then the HACCESSOR of the original accessor
  63. ULONG _cInheritors; // count of current rowsets
  64. // which inherited this accessor
  65. EAccessorType _type;
  66. };
  67. //+-------------------------------------------------------------------------
  68. //
  69. // Class: CAccessorBag
  70. //
  71. // Purpose: Holds a number of accessors
  72. //
  73. // History: 12 Jan 1995 dlee Created
  74. //
  75. //--------------------------------------------------------------------------
  76. class CAccessorBag : public TBag<CAccessorBase *>
  77. {
  78. public:
  79. CAccessorBag(void * pOwner): _pOwner(pOwner) { }
  80. CAccessorBase * Convert(HACCESSOR hAccessor)
  81. {
  82. Win4Assert( 0 == DB_INVALID_HACCESSOR );
  83. if ( DB_INVALID_HACCESSOR == hAccessor )
  84. THROW( CException( DB_E_BADACCESSORHANDLE) );
  85. CAccessorBase * pAccBase = (CAccessorBase *) hAccessor;
  86. if (_pOwner != pAccBase->GetCreator())
  87. { // see if we inherited
  88. pAccBase = First();
  89. while (pAccBase && (pAccBase->GetParent() != (CAccessorBase *)hAccessor ))
  90. pAccBase = Next();
  91. if (!pAccBase)
  92. THROW( CException( DB_E_BADACCESSORHANDLE ) );
  93. }
  94. if( !pAccBase->IsValidType() || pAccBase->GetRefcount() <= 0 )
  95. THROW( CException( DB_E_BADACCESSORHANDLE ) );
  96. return pAccBase;
  97. }
  98. ~CAccessorBag();
  99. void AddRef( HACCESSOR hAccessor,
  100. ULONG *pcRef );
  101. void Release( HACCESSOR hAccessor,
  102. ULONG *pcRef );
  103. private:
  104. void Destroy( CAccessorBase * pAccessor );
  105. // This is the pointer of the rowset or command to which this bag belongs
  106. void * _pOwner;
  107. }; //CAccessorBag