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.

107 lines
2.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: GroupCon.cpp
  6. * Content: Group Connection object routines
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 03/02/00 mjn Created
  12. * 04/18/00 mjn CConnection tracks connection status better
  13. * 05/05/00 mjn Added GetConnectionRef()
  14. * 08/15/00 mjn Added SetGroup()
  15. * mjn Fixed Release() to take locks and cleanup m_pGroup
  16. *@@END_MSINTERNAL
  17. *
  18. ***************************************************************************/
  19. #include "dncorei.h"
  20. void CGroupConnection::ReturnSelfToPool( void )
  21. {
  22. g_GroupConnectionPool.Release( this );
  23. }
  24. #undef DPF_MODNAME
  25. #define DPF_MODNAME "CGroupConnection::Release"
  26. void CGroupConnection::Release(void)
  27. {
  28. LONG lRefCount;
  29. DNASSERT(m_lRefCount > 0);
  30. lRefCount = DNInterlockedDecrement(const_cast<LONG*>(&m_lRefCount));
  31. if (lRefCount == 0)
  32. {
  33. if (m_pGroup)
  34. {
  35. m_pGroup->Lock();
  36. RemoveFromConnectionList();
  37. m_pGroup->Unlock();
  38. m_pGroup->Release();
  39. m_pGroup = NULL;
  40. }
  41. if (m_pConnection)
  42. {
  43. m_pConnection->Release();
  44. m_pConnection = NULL;
  45. }
  46. m_dwFlags = 0;
  47. m_lRefCount = 0;
  48. ReturnSelfToPool();
  49. }
  50. }
  51. void CGroupConnection::SetConnection( CConnection *const pConnection )
  52. {
  53. if (pConnection)
  54. {
  55. pConnection->Lock();
  56. if (pConnection->IsConnected())
  57. {
  58. pConnection->AddRef();
  59. m_pConnection = pConnection;
  60. }
  61. pConnection->Unlock();
  62. }
  63. }
  64. #undef DPF_MODNAME
  65. #define DPF_MODNAME "CGroupConnection::GetConnectionRef"
  66. HRESULT CGroupConnection::GetConnectionRef( CConnection **const ppConnection )
  67. {
  68. HRESULT hResultCode;
  69. DNASSERT( ppConnection != NULL);
  70. Lock();
  71. if ( m_pConnection && !m_pConnection->IsInvalid())
  72. {
  73. m_pConnection->AddRef();
  74. *ppConnection = m_pConnection;
  75. hResultCode = DPN_OK;
  76. }
  77. else
  78. {
  79. hResultCode = DPNERR_NOCONNECTION;
  80. }
  81. Unlock();
  82. return( hResultCode );
  83. }
  84. void CGroupConnection::SetGroup( CNameTableEntry *const pGroup )
  85. {
  86. if (pGroup)
  87. {
  88. pGroup->AddRef();
  89. }
  90. m_pGroup = pGroup;
  91. }