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
)
16 ACE_TRACE ("ACE_Token_Collection::ACE_Token_Collection");
19 name
= ACE_TEXT ("no name");
21 ACE_OS::strsncpy (this->name_
,
22 const_cast<ACE_TCHAR
*> (name
),
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.
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);
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
);
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
;
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;
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;
86 ACELIB_DEBUG ((LM_DEBUG
,
87 ACE_TEXT ("collection acquiring %s\n"),
88 temp
->int_id_
->name ()));
89 if (temp
->int_id_
->acquire (notify
,
93 // Save/restore errno.
94 ACE_Errno_Guard
error (errno
);
104 ACE_Token_Collection::acquire (const ACE_TCHAR
*token_name
,
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
);
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
);
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;
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)
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;
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)
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
);
197 ACELIB_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT ("%p %s\n"),
198 ACE_TEXT ("not in collection "),
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;
216 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("collection releasing %s\n"),
217 temp
->int_id_
->name ()));
218 temp
->int_id_
->release ();
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
);
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;
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.
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.
266 ACE_Token_Collection::create_token (const ACE_TCHAR
*)
268 ACE_TRACE ("ACE_Token_Collection::create_token");
269 return (ACE_Tokens
*) 0;
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")));
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 */