Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Token_Collection.cpp
blob7ab8347dd012e1ba30d1c33f30c95b2799c04e41
1 #include "ace/Token_Collection.h"
3 #if defined (ACE_HAS_TOKENS_LIBRARY)
5 #if !defined (__ACE_INLINE__)
6 #include "ace/Token_Collection.inl"
7 #endif /* __ACE_INLINE__ */
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_Token_Collection::ACE_Token_Collection (bool debug,
12 const ACE_TCHAR *name)
13 : debug_ (debug)
15 ACE_TRACE ("ACE_Token_Collection::ACE_Token_Collection");
17 if (name == 0)
18 name = ACE_TEXT ("no name");
20 ACE_OS::strsncpy (this->name_,
21 const_cast<ACE_TCHAR *> (name),
22 ACE_MAXTOKENNAMELEN);
25 int
26 ACE_Token_Collection::insert (ACE_Token_Proxy &new_token)
28 ACE_TRACE ("ACE_Token_Collection::insert");
30 TOKEN_NAME name (new_token.name ());
32 // Check if the new_proxy is already in the list.
33 if (collection_.find (name) == 1)
34 // One already exists, so fail.
35 return -1;
37 // Clone the new token.
38 ACE_Token_Proxy *temp = new_token.clone ();
40 if (collection_.bind (name, temp) == -1)
41 ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("bind failed\n")), -1);
42 return 0;
45 int
46 ACE_Token_Collection::extract (const ACE_TCHAR *token_name, ACE_Token_Proxy *&proxy)
48 ACE_TRACE ("ACE_Token_Collection::extract");
49 TOKEN_NAME name (token_name);
50 return collection_.unbind (token_name, proxy);
53 ACE_Token_Proxy *
54 ACE_Token_Collection::is_member (const ACE_TCHAR *token_name)
56 ACE_TRACE ("ACE_Token_Collection::is_member");
57 TOKEN_NAME name (token_name);
58 ACE_Token_Proxy *temp;
59 // Get the token from the collection.
60 return collection_.find (name, temp) == -1 ? 0 : temp;
63 int
64 ACE_Token_Collection::is_member (const ACE_Token_Proxy &token)
66 ACE_TRACE ("ACE_Token_Collection::is_member");
67 TOKEN_NAME token_name (token.name ());
68 return collection_.find (token_name) == 0;
71 int
72 ACE_Token_Collection::acquire (int notify,
73 void (*sleep_hook)(void *),
74 ACE_Synch_Options &options)
76 ACE_TRACE ("ACE_Token_Collection::acquire");
78 COLLECTION::ITERATOR iterator (collection_);
80 for (COLLECTION::ENTRY *temp = 0;
81 iterator.next (temp) != 0;
82 iterator.advance ())
84 if (debug_)
85 ACELIB_DEBUG ((LM_DEBUG,
86 ACE_TEXT ("collection acquiring %s\n"),
87 temp->int_id_->name ()));
88 if (temp->int_id_->acquire (notify,
89 sleep_hook,
90 options) == -1)
92 // Save/restore errno.
93 ACE_Errno_Guard error (errno);
94 this->release ();
95 ACE_RETURN (-1);
99 return 0;
103 ACE_Token_Collection::acquire (const ACE_TCHAR *token_name,
104 int notify,
105 void (*sleep_hook)(void *),
106 ACE_Synch_Options &options)
108 ACE_TRACE ("ACE_Token_Collection::acquire");
109 TOKEN_NAME name (token_name);
110 ACE_Token_Proxy *temp;
111 // Get the token from the collection.
112 int result = collection_.find (name, temp);
113 // did we find it?
114 if (result == -1)
115 return result;
116 // perform the operation
117 return temp->acquire (notify, sleep_hook, options);
122 ACE_Token_Collection::tryacquire (const ACE_TCHAR *token_name,
123 void (*sleep_hook)(void *))
125 ACE_TRACE ("ACE_Token_Collection::tryacquire");
126 TOKEN_NAME name (token_name);
127 ACE_Token_Proxy *temp;
128 // Get the token from the collection.
129 int result = collection_.find (name, temp);
130 // did we find it?
131 if (result == -1)
132 return result;
134 // perform the operation
135 return temp->tryacquire (sleep_hook);
139 ACE_Token_Collection::tryacquire (void (*sleep_hook)(void *))
141 ACE_TRACE ("ACE_Token_Collection::tryacquire");
143 COLLECTION::ITERATOR iterator (collection_);
145 for (COLLECTION::ENTRY *temp = 0;
146 iterator.next (temp) != 0;
147 iterator.advance ())
149 if (debug_)
150 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection acquiring %s\n"),
151 temp->int_id_->name ()));
152 // We will fail if _any_ token is not free.
153 if (temp->int_id_->tryacquire (sleep_hook) == -1)
154 return -1;
157 return 0;
161 ACE_Token_Collection::renew (int requeue_position,
162 ACE_Synch_Options &options)
164 ACE_TRACE ("ACE_Token_Collection::renew");
166 COLLECTION::ITERATOR iterator (collection_);
168 for (COLLECTION::ENTRY *temp = 0;
169 iterator.next (temp) != 0;
170 iterator.advance ())
172 if (debug_)
173 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection renewing %s\n"),
174 temp->int_id_->name ()));
175 if (temp->int_id_->renew (requeue_position, options) == -1)
176 return -1;
179 return 0;
183 ACE_Token_Collection::renew (const ACE_TCHAR *token_name,
184 int requeue_position,
185 ACE_Synch_Options &options)
187 ACE_TRACE ("ACE_Token_Collection::renew");
188 TOKEN_NAME name (token_name);
189 ACE_Token_Proxy *temp;
191 // Get the token from the collection.
192 int result = collection_.find (name, temp);
194 // Did we find it?
195 if (result == -1)
196 ACELIB_ERROR_RETURN ((LM_DEBUG, ACE_TEXT ("%p %s\n"),
197 ACE_TEXT ("not in collection "),
198 token_name), -1);
199 // perform the operation
200 return temp->renew (requeue_position, options);
204 ACE_Token_Collection::release (ACE_Synch_Options &)
207 ACE_TRACE ("ACE_Token_Collection::release");
208 COLLECTION::ITERATOR iterator (collection_);
210 for (COLLECTION::ENTRY *temp = 0;
211 iterator.next (temp) != 0;
212 iterator.advance ())
214 if (debug_)
215 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection releasing %s\n"),
216 temp->int_id_->name ()));
217 temp->int_id_->release ();
220 return 0;
224 ACE_Token_Collection::release (const ACE_TCHAR *token_name,
225 ACE_Synch_Options &options)
227 ACE_TRACE ("ACE_Token_Collection::release");
228 TOKEN_NAME name (token_name);
229 ACE_Token_Proxy *temp;
230 // get the token from the collection
231 int result = collection_.find (name, temp);
232 // did we find it?
233 if (result != 0)
234 return result;
235 // perform the operation
236 return temp->release (options);
239 ACE_Token_Collection::~ACE_Token_Collection ()
241 ACE_TRACE ("ACE_Token_Collection::~ACE_Token_Collection");
242 COLLECTION::ITERATOR iterator (collection_);
244 for (COLLECTION::ENTRY *temp = 0;
245 iterator.next (temp) != 0;
246 iterator.advance ())
248 delete temp->int_id_;
249 // The ext_id_'s delete themselves when the array of
250 // COLLECTION::ENTRYs goes away.
255 // This method doesn't mean anything for a collection.
256 ACE_Token_Proxy *
257 ACE_Token_Collection::clone () const
259 ACE_TRACE ("ACE_Token_Collection::clone");
260 return (ACE_Token_Proxy *) 0;
263 // This method doesn't mean anything for a collection.
264 ACE_Tokens *
265 ACE_Token_Collection::create_token (const ACE_TCHAR *)
267 ACE_TRACE ("ACE_Token_Collection::create_token");
268 return (ACE_Tokens *) 0;
271 void
272 ACE_Token_Collection::dump () const
274 #if defined (ACE_HAS_DUMP)
275 ACE_TRACE ("ACE_Token_Collection::dump");
276 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
277 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_Token_Collection::dump:\n")
278 ACE_TEXT (" debug_ = %d\n"), debug_));
279 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection_\n")));
280 collection_.dump ();
281 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("base:\n")));
282 ACE_Token_Proxy::dump ();
283 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
284 #endif /* ACE_HAS_DUMP */
287 ACE_END_VERSIONED_NAMESPACE_DECL
289 #endif /* ACE_HAS_TOKENS_LIBRARY */