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.

162 lines
4.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: cmap.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <precomp.hxx>
  11. #include <mqtrans.hxx>
  12. //------------------------------------------------------------------------
  13. // Constructor
  14. //------------------------------------------------------------------------
  15. CQueueMap::CQueueMap() : cs((InitStatus = RPC_S_OK, &InitStatus))
  16. {
  17. dwMapSize = 0;
  18. dwOldest = 0;
  19. pMap = 0;
  20. }
  21. //------------------------------------------------------------------------
  22. // Initialize()
  23. //------------------------------------------------------------------------
  24. BOOL CQueueMap::Initialize( DWORD dwNewMapSize )
  25. {
  26. if (!dwNewMapSize)
  27. return FALSE;
  28. if (!dwMapSize)
  29. {
  30. if (InitStatus != RPC_S_OK)
  31. return FALSE;
  32. pMap = new QUEUEMAP_ENTRY [dwNewMapSize];
  33. if (!pMap)
  34. return FALSE;
  35. dwMapSize = dwNewMapSize;
  36. for (unsigned i=0; i<dwMapSize; i++)
  37. {
  38. pMap[i].hQueue = 0;
  39. pMap[i].pwsQFormat = 0;
  40. }
  41. }
  42. return TRUE;
  43. }
  44. //------------------------------------------------------------------------
  45. // Destructor
  46. //------------------------------------------------------------------------
  47. CQueueMap::~CQueueMap()
  48. {
  49. if (pMap)
  50. {
  51. for (unsigned i=0; i<dwMapSize; i++)
  52. {
  53. if (pMap[i].hQueue)
  54. MQCloseQueue(pMap[i].hQueue);
  55. if (pMap[i].pwsQFormat)
  56. delete [] pMap[i].pwsQFormat;
  57. }
  58. }
  59. delete pMap;
  60. }
  61. //------------------------------------------------------------------------
  62. // Lookup()
  63. //------------------------------------------------------------------------
  64. QUEUEHANDLE CQueueMap::Lookup( RPC_CHAR *pwsQFormat )
  65. {
  66. cs.Request();
  67. for (unsigned i=0; i<dwMapSize; i++)
  68. {
  69. if ((pMap[i].pwsQFormat)&&(!RpcpStringSCompare(pwsQFormat,pMap[i].pwsQFormat)))
  70. {
  71. cs.Clear();
  72. return pMap[i].hQueue;
  73. }
  74. }
  75. cs.Clear();
  76. return 0;
  77. }
  78. //------------------------------------------------------------------------
  79. // Add()
  80. //------------------------------------------------------------------------
  81. BOOL CQueueMap::Add( RPC_CHAR *pwsQFormat, QUEUEHANDLE hQueue )
  82. {
  83. // Only add entries that look valid...
  84. if ( !pwsQFormat || !hQueue )
  85. {
  86. return FALSE;
  87. }
  88. cs.Request();
  89. // If the table is full, the clear out the oldest entry:
  90. if (pMap[dwOldest].hQueue)
  91. {
  92. MQCloseQueue(pMap[dwOldest].hQueue);
  93. pMap[dwOldest].hQueue = 0;
  94. }
  95. if (pMap[dwOldest].pwsQFormat)
  96. {
  97. delete [] pMap[dwOldest].pwsQFormat;
  98. pMap[dwOldest].pwsQFormat = 0;
  99. }
  100. // New entry:
  101. pMap[dwOldest].pwsQFormat = new RPC_CHAR [1+RpcpStringLength(pwsQFormat)];
  102. if (!pMap[dwOldest].pwsQFormat)
  103. {
  104. cs.Clear();
  105. return FALSE;
  106. }
  107. RpcpStringCopy(pMap[dwOldest].pwsQFormat,pwsQFormat);
  108. pMap[dwOldest].hQueue = hQueue;
  109. dwOldest = (1 + dwOldest)%dwMapSize;
  110. cs.Clear();
  111. return TRUE;
  112. }
  113. //------------------------------------------------------------------------
  114. // Remove()
  115. //------------------------------------------------------------------------
  116. BOOL CQueueMap::Remove( RPC_CHAR *pwsQFormat )
  117. {
  118. cs.Request();
  119. for (unsigned i=0; i<dwMapSize; i++)
  120. {
  121. if ((pMap[i].pwsQFormat)&&(!RpcpStringSCompare(pwsQFormat,pMap[i].pwsQFormat)))
  122. {
  123. delete [] pMap[i].pwsQFormat;
  124. pMap[i].pwsQFormat = 0;
  125. pMap[i].hQueue = 0;
  126. cs.Clear();
  127. return TRUE;
  128. }
  129. }
  130. cs.Clear();
  131. return FALSE;
  132. }
  133.