DescriptorManager.C 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: DescriptorManager.C /main/1 1996/07/29 16:48:58 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #include "splib.h"
  27. #include "DescriptorManager.h"
  28. #include "ListIter.h"
  29. #ifdef SP_NAMESPACE
  30. namespace SP_NAMESPACE {
  31. #endif
  32. DescriptorUser::DescriptorUser(DescriptorManager *manager)
  33. : manager_(manager)
  34. {
  35. if (manager_)
  36. manager_->addUser(this);
  37. }
  38. DescriptorUser::~DescriptorUser()
  39. {
  40. if (manager_)
  41. manager_->removeUser(this);
  42. }
  43. void DescriptorUser::managerDeleted()
  44. {
  45. manager_ = 0;
  46. }
  47. Boolean DescriptorUser::suspend()
  48. {
  49. return 0;
  50. }
  51. void DescriptorUser::acquireD()
  52. {
  53. if (manager_)
  54. manager_->acquireD();
  55. }
  56. void DescriptorUser::releaseD()
  57. {
  58. if (manager_)
  59. manager_->releaseD();
  60. }
  61. DescriptorManager::DescriptorManager(int maxD)
  62. : maxD_(maxD), usedD_(0)
  63. {
  64. }
  65. DescriptorManager::~DescriptorManager()
  66. {
  67. for (ListIter<DescriptorUser *> iter(users_);
  68. !iter.done();
  69. iter.next())
  70. iter.cur()->managerDeleted();
  71. }
  72. void DescriptorManager::addUser(DescriptorUser *p)
  73. {
  74. users_.insert(p);
  75. }
  76. void DescriptorManager::removeUser(DescriptorUser *p)
  77. {
  78. users_.remove(p);
  79. }
  80. void DescriptorManager::acquireD()
  81. {
  82. if (usedD_ >= maxD_) {
  83. for (ListIter<DescriptorUser *> iter(users_);
  84. !iter.done();
  85. iter.next()) {
  86. if (iter.cur()->suspend())
  87. break;
  88. }
  89. }
  90. usedD_++;
  91. }
  92. void DescriptorManager::releaseD()
  93. {
  94. usedD_--;
  95. }
  96. #ifdef SP_NAMESPACE
  97. }
  98. #endif