Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Token_Collection.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: Token_Collection.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:23 chad Exp $
00003 
00004 #include "ace/Token_Collection.h"
00005 
00006 #if !defined (__ACE_INLINE__)
00007 #include "ace/Token_Collection.i"
00008 #endif /* __ACE_INLINE__ */
00009 
00010 #if defined (ACE_HAS_TOKENS_LIBRARY)
00011 
00012 ACE_RCSID(ace, Token_Collection, "$Id: Token_Collection.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:23 chad Exp $")
00013 
00014 ACE_Token_Collection::ACE_Token_Collection (int debug,
00015                                             const ACE_TCHAR *name)
00016 : debug_ (debug)
00017 {
00018   ACE_TRACE ("ACE_Token_Collection::ACE_Token_Collection");
00019 
00020   if (name == 0)
00021     name = ACE_LIB_TEXT ("no name");
00022 
00023   ACE_OS::strsncpy (this->name_,
00024                     ACE_const_cast (ACE_TCHAR *,
00025                                     name),
00026                     ACE_MAXTOKENNAMELEN);
00027 }
00028 
00029 int
00030 ACE_Token_Collection::insert (ACE_Token_Proxy &new_token)
00031 {
00032   ACE_TRACE ("ACE_Token_Collection::insert");
00033 
00034   TOKEN_NAME name (new_token.name ());
00035 
00036   // Check if the new_proxy is already in the list.
00037   if (collection_.find (name) == 1)
00038     // One already exists, so fail.
00039     return -1;
00040 
00041   // Clone the new token.
00042   ACE_Token_Proxy *temp = new_token.clone ();
00043 
00044   if (collection_.bind (name, temp) == -1)
00045     ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("bind failed\n")), -1);
00046   return 0;
00047 }
00048 
00049 int
00050 ACE_Token_Collection::extract (const ACE_TCHAR *token_name, ACE_Token_Proxy *&proxy)
00051 {
00052   ACE_TRACE ("ACE_Token_Collection::extract");
00053   TOKEN_NAME name (token_name);
00054   return collection_.unbind (token_name, proxy);
00055 }
00056 
00057 ACE_Token_Proxy *
00058 ACE_Token_Collection::is_member (const ACE_TCHAR *token_name)
00059 {
00060   ACE_TRACE ("ACE_Token_Collection::is_member");
00061   TOKEN_NAME name (token_name);
00062   ACE_Token_Proxy *temp;
00063   // Get the token from the collection.
00064   return collection_.find (name, temp) == -1 ? 0 : temp;
00065 }
00066 
00067 int
00068 ACE_Token_Collection::is_member (const ACE_Token_Proxy &token)
00069 {
00070   ACE_TRACE ("ACE_Token_Collection::is_member");
00071   TOKEN_NAME token_name (token.name ());
00072   return collection_.find (token_name) == 0;
00073 }
00074 
00075 int
00076 ACE_Token_Collection::acquire (int notify,
00077                                void (*sleep_hook)(void *),
00078                                ACE_Synch_Options &options)
00079 {
00080   ACE_TRACE ("ACE_Token_Collection::acquire");
00081 
00082   COLLECTION_ITERATOR iterator (collection_);
00083 
00084   for (COLLECTION_ENTRY *temp = 0;
00085        iterator.next (temp) != 0;
00086        iterator.advance ())
00087     {
00088       if (debug_)
00089         ACE_DEBUG ((LM_DEBUG,
00090                     ACE_LIB_TEXT ("collection acquiring %s\n"),
00091                     temp->int_id_->name ()));
00092       if (temp->int_id_->acquire (notify,
00093                                   sleep_hook,
00094                                   options) == -1)
00095         {
00096           // Save/restore errno.
00097           ACE_Errno_Guard error (errno);
00098           this->release ();
00099           ACE_RETURN (-1);
00100         }
00101     }
00102 
00103   return 0;
00104 }
00105 
00106 int
00107 ACE_Token_Collection::acquire (const ACE_TCHAR *token_name,
00108                                int notify,
00109                                void (*sleep_hook)(void *),
00110                                ACE_Synch_Options &options)
00111 {
00112   ACE_TRACE ("ACE_Token_Collection::acquire");
00113   TOKEN_NAME name (token_name);
00114   ACE_Token_Proxy *temp;
00115   // Get the token from the collection.
00116   int result = collection_.find (name, temp);
00117   // did we find it?
00118   if (result == -1)
00119     return result;
00120   // perform the operation
00121   return temp->acquire (notify, sleep_hook, options);
00122 }
00123 
00124 
00125 int
00126 ACE_Token_Collection::tryacquire (const ACE_TCHAR *token_name,
00127                                   void (*sleep_hook)(void *))
00128 {
00129   ACE_TRACE ("ACE_Token_Collection::tryacquire");
00130   TOKEN_NAME name (token_name);
00131   ACE_Token_Proxy *temp;
00132   // Get the token from the collection.
00133   int result = collection_.find (name, temp);
00134   // did we find it?
00135   if (result == -1)
00136     return result;
00137 
00138   // perform the operation
00139   return temp->tryacquire (sleep_hook);
00140 }
00141 
00142 int
00143 ACE_Token_Collection::tryacquire (void (*sleep_hook)(void *))
00144 {
00145   ACE_TRACE ("ACE_Token_Collection::tryacquire");
00146 
00147   COLLECTION_ITERATOR iterator (collection_);
00148 
00149   for (COLLECTION_ENTRY *temp = 0;
00150        iterator.next (temp) != 0;
00151        iterator.advance ())
00152     {
00153       if (debug_)
00154         ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("collection acquiring %s\n"),
00155                     temp->int_id_->name ()));
00156       // We will fail if _any_ token is not free.
00157       if (temp->int_id_->tryacquire (sleep_hook) == -1)
00158         return -1;
00159     }
00160 
00161   return 0;
00162 }
00163 
00164 int
00165 ACE_Token_Collection::renew (int requeue_position,
00166                              ACE_Synch_Options &options)
00167 {
00168   ACE_TRACE ("ACE_Token_Collection::renew");
00169 
00170   COLLECTION_ITERATOR iterator (collection_);
00171 
00172   for (COLLECTION_ENTRY *temp = 0;
00173        iterator.next (temp) != 0;
00174        iterator.advance ())
00175     {
00176       if (debug_)
00177         ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("collection renewing %s\n"),
00178                     temp->int_id_->name ()));
00179       if (temp->int_id_->renew (requeue_position, options) == -1)
00180         return -1;
00181     }
00182 
00183   return 0;
00184 }
00185 
00186 int
00187 ACE_Token_Collection::renew (const ACE_TCHAR *token_name,
00188                              int requeue_position,
00189                              ACE_Synch_Options &options)
00190 {
00191   ACE_TRACE ("ACE_Token_Collection::renew");
00192   TOKEN_NAME name (token_name);
00193   ACE_Token_Proxy *temp;
00194 
00195   // Get the token from the collection.
00196   int result = collection_.find (name, temp);
00197 
00198   // Did we find it?
00199   if (result == -1)
00200     ACE_ERROR_RETURN ((LM_DEBUG, ACE_LIB_TEXT ("%p %s\n"),
00201                        ACE_LIB_TEXT ("not in collection "),
00202                        token_name), -1);
00203   // perform the operation
00204   return temp->renew (requeue_position, options);
00205 }
00206 
00207 int
00208 ACE_Token_Collection::release (ACE_Synch_Options &)
00209 
00210 {
00211   ACE_TRACE ("ACE_Token_Collection::release");
00212   COLLECTION_ITERATOR iterator (collection_);
00213 
00214   for (COLLECTION_ENTRY *temp = 0;
00215        iterator.next (temp) != 0;
00216        iterator.advance ())
00217     {
00218       if (debug_)
00219         ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("collection releasing %s\n"),
00220                     temp->int_id_->name ()));
00221       temp->int_id_->release ();
00222     }
00223 
00224   return 0;
00225 }
00226 
00227 int
00228 ACE_Token_Collection::release (const ACE_TCHAR *token_name,
00229                                ACE_Synch_Options &options)
00230 {
00231   ACE_TRACE ("ACE_Token_Collection::release");
00232   TOKEN_NAME name (token_name);
00233   ACE_Token_Proxy *temp;
00234   // get the token from the collection
00235   int result = collection_.find (name, temp);
00236   // did we find it?
00237   if (result != 0)
00238     return result;
00239   // perform the operation
00240   return temp->release (options);
00241 }
00242 
00243 ACE_Token_Collection::~ACE_Token_Collection (void)
00244 {
00245   ACE_TRACE ("ACE_Token_Collection::~ACE_Token_Collection");
00246   COLLECTION_ITERATOR iterator (collection_);
00247 
00248   for (COLLECTION_ENTRY *temp = 0;
00249        iterator.next (temp) != 0;
00250        iterator.advance ())
00251     {
00252       delete temp->int_id_;
00253       // The ext_id_'s delete themselves when the array of
00254       // COLLECTION_ENTRYs goes away.
00255     }
00256 }
00257 
00258 
00259 // This method doesn't mean anything for a collection.
00260 ACE_Token_Proxy *
00261 ACE_Token_Collection::clone (void) const
00262 {
00263   ACE_TRACE ("ACE_Token_Collection::clone");
00264   return (ACE_Token_Proxy *) 0;
00265 }
00266 
00267 // This method doesn't mean anything for a collection.
00268 ACE_Tokens *
00269 ACE_Token_Collection::create_token (const ACE_TCHAR *)
00270 {
00271   ACE_TRACE ("ACE_Token_Collection::create_token");
00272   return (ACE_Tokens *) 0;
00273 }
00274 
00275 void
00276 ACE_Token_Collection::dump (void) const
00277 {
00278   ACE_TRACE ("ACE_Token_Collection::dump");
00279   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00280   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("ACE_Token_Collection::dump:\n")
00281               ACE_LIB_TEXT (" debug_ = %d\n"), debug_));
00282   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("collection_\n")));
00283   collection_.dump ();
00284   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("base:\n")));
00285   ACE_Token_Proxy::dump ();
00286   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00287 }
00288 
00289 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00290 template class ACE_Map_Manager<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>;
00291 template class ACE_Map_Iterator_Base<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>;
00292 template class ACE_Map_Iterator<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>;
00293 template class ACE_Map_Reverse_Iterator<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>;
00294 template class ACE_Map_Entry<ACE_Token_Name, ACE_Token_Proxy *>;
00295 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00296 #pragma instantiate ACE_Map_Manager<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>
00297 #pragma instantiate ACE_Map_Iterator_Base<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>
00298 #pragma instantiate ACE_Map_Iterator<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>
00299 #pragma instantiate ACE_Map_Reverse_Iterator<ACE_Token_Name, ACE_Token_Proxy *, ACE_Null_Mutex>
00300 #pragma instantiate ACE_Map_Entry<ACE_Token_Name, ACE_Token_Proxy *>
00301 #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
00302 
00303 #endif /* ACE_HAS_TOKENS_LIBRARY */

Generated on Mon Jun 16 11:21:57 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002