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.

180 lines
4.4 KiB

  1. #include "precomp.h"
  2. #include "fsdiag.h"
  3. DEBUG_FILEZONE(ZONE_T120_CONF_ROSTER);
  4. /*
  5. * crostmsg.cpp
  6. *
  7. * Copyright (c) 1995 by DataBeam Corporation, Lexington, KY
  8. *
  9. * Abstract:
  10. * This is the implementation file for the Conference Roster Message
  11. * Class. This class maintains a conference roster, and is able
  12. * to "serialize" the roster into a block of memory. It utilizes a
  13. * "Lock - UnLock" facility to ensure that the roster memory remains
  14. * valid until all interested parties are through using the object.
  15. *
  16. * Protected Instance Variables:
  17. *
  18. * Private Member Functions:
  19. *
  20. * Caveats:
  21. * None.
  22. *
  23. * Author:
  24. * jbo/blp
  25. */
  26. #include "crostmsg.h"
  27. /*
  28. * CConfRosterMsg ()
  29. *
  30. * Public Function Description
  31. * This constructor is used to create a Conference Roster Message object.
  32. * The pointer to the conference roster will be stored.
  33. */
  34. CConfRosterMsg::CConfRosterMsg(CConfRoster *conference_roster)
  35. :
  36. CRefCount(MAKE_STAMP_ID('A','R','M','g')),
  37. m_pMemoryBlock(NULL),
  38. m_pConfRoster(conference_roster)
  39. {
  40. }
  41. /*
  42. * ~CConfRosterMsg ()
  43. *
  44. * Public Function Description:
  45. * The destructor for the CConfRosterMsg class will clean up
  46. * any memory allocated during the life of the object.
  47. */
  48. CConfRosterMsg::~CConfRosterMsg(void)
  49. {
  50. delete m_pMemoryBlock;
  51. }
  52. /*
  53. * GCCError LockConferenceRosterMessage ()
  54. *
  55. * Public Function Description
  56. * This routine is used to lock an CConfRosterMsg. The memory
  57. * necessary to hold the list of rosters is allocated and the rosters are
  58. * "serialized" into the allocated memory block.
  59. */
  60. GCCError CConfRosterMsg::LockConferenceRosterMessage(void)
  61. {
  62. GCCError rc = GCC_NO_ERROR;
  63. UINT roster_data_length;
  64. PGCCConferenceRoster temporary_roster;
  65. /*
  66. * Return an error if this object has been freed or if the internal
  67. * conference roster pointer is invalid.
  68. */
  69. if (m_pConfRoster == NULL)
  70. return (GCC_ALLOCATION_FAILURE);
  71. /*
  72. * If this is the first time this routine is called, determine the size of
  73. * the memory required to hold the conference roster and go ahead
  74. * and serialize the data. Otherwise, just increment the lock count.
  75. */
  76. if (Lock() == 1)
  77. {
  78. /*
  79. * Determine the size of the memory block needed to hold the roster.
  80. */
  81. roster_data_length = m_pConfRoster->LockConferenceRoster();
  82. /*
  83. * Allocate space to hold the conference roster and all associated data.
  84. * FIX: Switch critical flag to TRUE when Sharded memory manager is
  85. * set up to support it.
  86. */
  87. DBG_SAVE_FILE_LINE
  88. if (NULL != (m_pMemoryBlock = new BYTE[roster_data_length]))
  89. {
  90. /*
  91. * Retrieve all of the data for the conference roster.
  92. */
  93. m_pConfRoster->GetConfRoster(&temporary_roster, m_pMemoryBlock);
  94. }
  95. else
  96. {
  97. ERROR_OUT(("CConfRosterMsg::LockConferenceRosterMessage: "
  98. "can't allocate memory, size=%u", (UINT) roster_data_length));
  99. rc = GCC_ALLOCATION_FAILURE;
  100. }
  101. /*
  102. * Since we do not need the conference roster anymore it is
  103. * OK to unlock it here.
  104. */
  105. m_pConfRoster->UnLockConferenceRoster ();
  106. }
  107. if (GCC_NO_ERROR != rc)
  108. {
  109. Unlock();
  110. }
  111. return rc;
  112. }
  113. /*
  114. * GCCError GetConferenceRosterMessage()
  115. *
  116. * Public Function Description
  117. * This routine is used to obtain a pointer to the Conference Roster
  118. * memory block used to deliver messages. This routine should not be
  119. * called before LockConferenceRosterMessage is called.
  120. */
  121. GCCError CConfRosterMsg::GetConferenceRosterMessage(LPBYTE *ppRosterData)
  122. {
  123. GCCError rc = GCC_ALLOCATION_FAILURE;
  124. if (GetLockCount() > 0)
  125. {
  126. if (m_pMemoryBlock != NULL)
  127. {
  128. *ppRosterData = m_pMemoryBlock;
  129. rc = GCC_NO_ERROR;
  130. }
  131. else
  132. {
  133. ERROR_OUT(("CConfRosterMsg::GetConferenceRosterMessage: no data"));
  134. ASSERT(GCC_ALLOCATION_FAILURE == rc);
  135. }
  136. }
  137. else
  138. {
  139. ERROR_OUT(("CConfRosterMsg::GetConferenceRosterMessage: data not locked"));
  140. ASSERT(GCC_ALLOCATION_FAILURE == rc);
  141. }
  142. return rc;
  143. }
  144. /*
  145. * void UnLockConferenceRosterMessage ()
  146. *
  147. * Public Function Description
  148. * This member function is responsible for unlocking the data locked for
  149. * the "API" conference roster after the lock count goes to zero.
  150. */
  151. void CConfRosterMsg::UnLockConferenceRosterMessage(void)
  152. {
  153. if (Unlock(FALSE) == 0)
  154. {
  155. /*
  156. * Free up the memory block allocated to hold the roster
  157. */
  158. delete m_pMemoryBlock;
  159. m_pMemoryBlock = NULL;
  160. }
  161. // we have to call Release() because we used Unlock(FALSE)
  162. Release();
  163. }