Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Token_Collection.cpp
blobc15d7cf9c51f65ad0b7623e674922ef3c3bae21a
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__ */
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 ACE_Token_Collection::ACE_Token_Collection (bool debug,
13 const ACE_TCHAR *name)
14 : debug_ (debug)
16 ACE_TRACE ("ACE_Token_Collection::ACE_Token_Collection");
18 if (name == 0)
19 name = ACE_TEXT ("no name");
21 ACE_OS::strsncpy (this->name_,
22 const_cast<ACE_TCHAR *> (name),
23 ACE_MAXTOKENNAMELEN);
26 int
27 ACE_Token_Collection::insert (ACE_Token_Proxy &new_token)
29 ACE_TRACE ("ACE_Token_Collection::insert");
31 TOKEN_NAME name (new_token.name ());
33 // Check if the new_proxy is already in the list.
34 if (collection_.find (name) == 1)
35 // One already exists, so fail.
36 return -1;
38 // Clone the new token.
39 ACE_Token_Proxy *temp = new_token.clone ();
41 if (collection_.bind (name, temp) == -1)
42 ACELIB_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("bind failed\n")), -1);
43 return 0;
46 int
47 ACE_Token_Collection::extract (const ACE_TCHAR *token_name, ACE_Token_Proxy *&proxy)
49 ACE_TRACE ("ACE_Token_Collection::extract");
50 TOKEN_NAME name (token_name);
51 return collection_.unbind (token_name, proxy);
54 ACE_Token_Proxy *
55 ACE_Token_Collection::is_member (const ACE_TCHAR *token_name)
57 ACE_TRACE ("ACE_Token_Collection::is_member");
58 TOKEN_NAME name (token_name);
59 ACE_Token_Proxy *temp;
60 // Get the token from the collection.
61 return collection_.find (name, temp) == -1 ? 0 : temp;
64 int
65 ACE_Token_Collection::is_member (const ACE_Token_Proxy &token)
67 ACE_TRACE ("ACE_Token_Collection::is_member");
68 TOKEN_NAME token_name (token.name ());
69 return collection_.find (token_name) == 0;
72 int
73 ACE_Token_Collection::acquire (int notify,
74 void (*sleep_hook)(void *),
75 ACE_Synch_Options &options)
77 ACE_TRACE ("ACE_Token_Collection::acquire");
79 COLLECTION::ITERATOR iterator (collection_);
81 for (COLLECTION::ENTRY *temp = 0;
82 iterator.next (temp) != 0;
83 iterator.advance ())
85 if (debug_)
86 ACELIB_DEBUG ((LM_DEBUG,
87 ACE_TEXT ("collection acquiring %s\n"),
88 temp->int_id_->name ()));
89 if (temp->int_id_->acquire (notify,
90 sleep_hook,
91 options) == -1)
93 // Save/restore errno.
94 ACE_Errno_Guard error (errno);
95 this->release ();
96 ACE_RETURN (-1);
100 return 0;
104 ACE_Token_Collection::acquire (const ACE_TCHAR *token_name,
105 int notify,
106 void (*sleep_hook)(void *),
107 ACE_Synch_Options &options)
109 ACE_TRACE ("ACE_Token_Collection::acquire");
110 TOKEN_NAME name (token_name);
111 ACE_Token_Proxy *temp;
112 // Get the token from the collection.
113 int result = collection_.find (name, temp);
114 // did we find it?
115 if (result == -1)
116 return result;
117 // perform the operation
118 return temp->acquire (notify, sleep_hook, options);
123 ACE_Token_Collection::tryacquire (const ACE_TCHAR *token_name,
124 void (*sleep_hook)(void *))
126 ACE_TRACE ("ACE_Token_Collection::tryacquire");
127 TOKEN_NAME name (token_name);
128 ACE_Token_Proxy *temp;
129 // Get the token from the collection.
130 int result = collection_.find (name, temp);
131 // did we find it?
132 if (result == -1)
133 return result;
135 // perform the operation
136 return temp->tryacquire (sleep_hook);
140 ACE_Token_Collection::tryacquire (void (*sleep_hook)(void *))
142 ACE_TRACE ("ACE_Token_Collection::tryacquire");
144 COLLECTION::ITERATOR iterator (collection_);
146 for (COLLECTION::ENTRY *temp = 0;
147 iterator.next (temp) != 0;
148 iterator.advance ())
150 if (debug_)
151 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection acquiring %s\n"),
152 temp->int_id_->name ()));
153 // We will fail if _any_ token is not free.
154 if (temp->int_id_->tryacquire (sleep_hook) == -1)
155 return -1;
158 return 0;
162 ACE_Token_Collection::renew (int requeue_position,
163 ACE_Synch_Options &options)
165 ACE_TRACE ("ACE_Token_Collection::renew");
167 COLLECTION::ITERATOR iterator (collection_);
169 for (COLLECTION::ENTRY *temp = 0;
170 iterator.next (temp) != 0;
171 iterator.advance ())
173 if (debug_)
174 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection renewing %s\n"),
175 temp->int_id_->name ()));
176 if (temp->int_id_->renew (requeue_position, options) == -1)
177 return -1;
180 return 0;
184 ACE_Token_Collection::renew (const ACE_TCHAR *token_name,
185 int requeue_position,
186 ACE_Synch_Options &options)
188 ACE_TRACE ("ACE_Token_Collection::renew");
189 TOKEN_NAME name (token_name);
190 ACE_Token_Proxy *temp;
192 // Get the token from the collection.
193 int result = collection_.find (name, temp);
195 // Did we find it?
196 if (result == -1)
197 ACELIB_ERROR_RETURN ((LM_DEBUG, ACE_TEXT ("%p %s\n"),
198 ACE_TEXT ("not in collection "),
199 token_name), -1);
200 // perform the operation
201 return temp->renew (requeue_position, options);
205 ACE_Token_Collection::release (ACE_Synch_Options &)
208 ACE_TRACE ("ACE_Token_Collection::release");
209 COLLECTION::ITERATOR iterator (collection_);
211 for (COLLECTION::ENTRY *temp = 0;
212 iterator.next (temp) != 0;
213 iterator.advance ())
215 if (debug_)
216 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection releasing %s\n"),
217 temp->int_id_->name ()));
218 temp->int_id_->release ();
221 return 0;
225 ACE_Token_Collection::release (const ACE_TCHAR *token_name,
226 ACE_Synch_Options &options)
228 ACE_TRACE ("ACE_Token_Collection::release");
229 TOKEN_NAME name (token_name);
230 ACE_Token_Proxy *temp;
231 // get the token from the collection
232 int result = collection_.find (name, temp);
233 // did we find it?
234 if (result != 0)
235 return result;
236 // perform the operation
237 return temp->release (options);
240 ACE_Token_Collection::~ACE_Token_Collection (void)
242 ACE_TRACE ("ACE_Token_Collection::~ACE_Token_Collection");
243 COLLECTION::ITERATOR iterator (collection_);
245 for (COLLECTION::ENTRY *temp = 0;
246 iterator.next (temp) != 0;
247 iterator.advance ())
249 delete temp->int_id_;
250 // The ext_id_'s delete themselves when the array of
251 // COLLECTION::ENTRYs goes away.
256 // This method doesn't mean anything for a collection.
257 ACE_Token_Proxy *
258 ACE_Token_Collection::clone (void) const
260 ACE_TRACE ("ACE_Token_Collection::clone");
261 return (ACE_Token_Proxy *) 0;
264 // This method doesn't mean anything for a collection.
265 ACE_Tokens *
266 ACE_Token_Collection::create_token (const ACE_TCHAR *)
268 ACE_TRACE ("ACE_Token_Collection::create_token");
269 return (ACE_Tokens *) 0;
272 void
273 ACE_Token_Collection::dump (void) const
275 #if defined (ACE_HAS_DUMP)
276 ACE_TRACE ("ACE_Token_Collection::dump");
277 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
278 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE_Token_Collection::dump:\n")
279 ACE_TEXT (" debug_ = %d\n"), debug_));
280 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("collection_\n")));
281 collection_.dump ();
282 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("base:\n")));
283 ACE_Token_Proxy::dump ();
284 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
285 #endif /* ACE_HAS_DUMP */
288 ACE_END_VERSIONED_NAMESPACE_DECL
290 #endif /* ACE_HAS_TOKENS_LIBRARY */