Introduction of BSDArchitecture
[oweals/cde.git] / cde / programs / nsgmls / DescriptorManager.C
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 librararies 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
27 #include "splib.h"
28 #include "DescriptorManager.h"
29 #include "ListIter.h"
30
31 #ifdef SP_NAMESPACE
32 namespace SP_NAMESPACE {
33 #endif
34
35 DescriptorUser::DescriptorUser(DescriptorManager *manager)
36 : manager_(manager)
37 {
38   if (manager_)
39     manager_->addUser(this);
40 }
41
42 DescriptorUser::~DescriptorUser()
43 {
44   if (manager_)
45     manager_->removeUser(this);
46 }
47
48 void DescriptorUser::managerDeleted()
49 {
50   manager_ = 0;
51 }
52
53 Boolean DescriptorUser::suspend()
54 {
55   return 0;
56 }
57
58 void DescriptorUser::acquireD()
59 {
60   if (manager_)
61     manager_->acquireD();
62 }
63
64 void DescriptorUser::releaseD()
65 {
66   if (manager_)
67     manager_->releaseD();
68 }
69
70 DescriptorManager::DescriptorManager(int maxD)
71 : maxD_(maxD), usedD_(0)
72 {
73 }
74
75 DescriptorManager::~DescriptorManager()
76 {
77   for (ListIter<DescriptorUser *> iter(users_);
78        !iter.done();
79        iter.next())
80     iter.cur()->managerDeleted();
81 }
82
83 void DescriptorManager::addUser(DescriptorUser *p)
84 {
85   users_.insert(p);
86 }
87
88 void DescriptorManager::removeUser(DescriptorUser *p)
89 {
90   users_.remove(p);
91 }
92
93 void DescriptorManager::acquireD()
94 {
95   if (usedD_ >= maxD_) {
96     for (ListIter<DescriptorUser *> iter(users_);
97          !iter.done();
98          iter.next()) {
99       if (iter.cur()->suspend())
100         break;
101     }
102   }
103   usedD_++;
104 }
105
106 void DescriptorManager::releaseD()
107 {
108   usedD_--;
109 }
110
111 #ifdef SP_NAMESPACE
112 }
113 #endif