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
)
15 ACE_TRACE ("ACE_Token_Collection::ACE_Token_Collection");
18 name
= ACE_TEXT ("no name");
20 ACE_OS::strsncpy (this->name_
,
21 const_cast<ACE_TCHAR
*> (name
),
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.
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);
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
);
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
;
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;
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;
85 ACELIB_DEBUG ((LM_DEBUG
,
86 ACE_TEXT ("collection acquiring %s\n"),
87 temp
->int_id_
->name ()));
88 if (temp
->int_id_
->acquire (notify
,
92 // Save/restore errno.
93 ACE_Errno_Guard
error (errno
);
103 ACE_Token_Collection::acquire (const ACE_TCHAR
*token_name
,
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
);
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
);
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;
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)
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;
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)
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
);
196 ACELIB_ERROR_RETURN ((LM_DEBUG
, ACE_TEXT ("%p %s\n"),
197 ACE_TEXT ("not in collection "),
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;
215 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("collection releasing %s\n"),
216 temp
->int_id_
->name ()));
217 temp
->int_id_
->release ();
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
);
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;
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.
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.
265 ACE_Token_Collection::create_token (const ACE_TCHAR
*)
267 ACE_TRACE ("ACE_Token_Collection::create_token");
268 return (ACE_Tokens
*) 0;
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")));
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 */