Local_Name_Space_T.cpp

Go to the documentation of this file.
00001 // Local_Name_Space_T.cpp,v 4.72 2006/06/09 14:09:14 schmidt Exp
00002 
00003 #ifndef ACE_LOCAL_NAME_SPACE_T_CPP
00004 #define ACE_LOCAL_NAME_SPACE_T_CPP
00005 
00006 #include "ace/ACE.h"
00007 
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif /* ACE_LACKS_PRAGMA_ONCE */
00011 
00012 #include "ace/Local_Name_Space.h"
00013 #include "ace/Auto_Ptr.h"
00014 #include "ace/Guard_T.h"
00015 #include "ace/OS_NS_regex.h"
00016 #include "ace/OS_NS_string.h"
00017 #include "ace/OS_NS_unistd.h"
00018 
00019 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00020 
00021 template <class ALLOCATOR>
00022 ACE_Name_Space_Map<ALLOCATOR>::ACE_Name_Space_Map (ALLOCATOR *alloc)
00023   : MAP_MANAGER (alloc)
00024 {
00025   ACE_TRACE ("ACE_Name_Space_Map::ACE_Name_Space_Map");
00026 }
00027 
00028 template <class ALLOCATOR> int
00029 ACE_Name_Space_Map<ALLOCATOR>::close (ALLOCATOR *alloc)
00030 {
00031   ACE_TRACE ("ACE_Name_Space_Map::close");
00032 
00033   this->table_allocator_ = alloc;
00034   this->entry_allocator_ = alloc;
00035   return this->close_i ();
00036 }
00037 
00038 template <class ALLOCATOR> int
00039 ACE_Name_Space_Map<ALLOCATOR>::bind (const ACE_NS_String &ext_id,
00040                                      const ACE_NS_Internal &int_id,
00041                                      ALLOCATOR *alloc)
00042 {
00043   ACE_TRACE ("ACE_Name_Space_Map::bind");
00044 
00045   this->table_allocator_ = alloc;
00046   this->entry_allocator_ = alloc;
00047   return this->bind_i (ext_id, int_id);
00048 }
00049 
00050 template <class ALLOCATOR> int
00051 ACE_Name_Space_Map<ALLOCATOR>::unbind (const ACE_NS_String &ext_id,
00052                                        ACE_NS_Internal &int_id,
00053                                        ALLOCATOR *alloc)
00054 {
00055   ACE_TRACE ("ACE_Name_Space_Map::unbind");
00056 
00057   this->table_allocator_ = alloc;
00058   this->entry_allocator_ = alloc;
00059   return this->unbind_i (ext_id, int_id);
00060 }
00061 
00062 template <class ALLOCATOR> int
00063 ACE_Name_Space_Map<ALLOCATOR>::rebind (const ACE_NS_String &ext_id,
00064                                        const ACE_NS_Internal &int_id,
00065                                        ACE_NS_String &old_ext_id,
00066                                        ACE_NS_Internal &old_int_id,
00067                                        ALLOCATOR *alloc)
00068 {
00069   ACE_TRACE ("ACE_Name_Space_Map::rebind");
00070 
00071   this->table_allocator_ = alloc;
00072   this->entry_allocator_ = alloc;
00073   return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id);
00074 }
00075 
00076 template <class ALLOCATOR> int
00077 ACE_Name_Space_Map<ALLOCATOR>::find (const ACE_NS_String &ext_id,
00078                                      ACE_NS_Internal &int_id,
00079                                      ALLOCATOR *alloc)
00080 {
00081   ACE_TRACE ("ACE_Name_Space_Map::find");
00082 
00083   this->table_allocator_ = alloc;
00084   this->entry_allocator_ = alloc;
00085   return this->find_i (ext_id, int_id);
00086 }
00087 
00088 #if defined (ACE_WIN32)
00089 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00090 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::remap (EXCEPTION_POINTERS *ep)
00091 {
00092   ACE_TRACE ("ACE_Local_Name_Space::remap");
00093 
00094   void *addr = (void *) ep->ExceptionRecord->ExceptionInformation[1];
00095 
00096   // The following requires Memory Pool to have ::remap()
00097   // defined. Thus currently this will only work for
00098   // ACE_MMap_Memory_Pool.
00099   if (this->allocator_->alloc ().memory_pool ().remap (addr) == -1)
00100     // Kick it upstairs...
00101     return EXCEPTION_CONTINUE_SEARCH;
00102 
00103 #if __X86__
00104   // This is 80x86-specific.
00105   ep->ContextRecord->Edi = (DWORD) addr;
00106 #elif __MIPS__
00107   ep->ContextRecord->IntA0 =
00108     ep->ContextRecord->IntV0 = (DWORD) addr;
00109   ep->ContextRecord->IntT5 = ep->ContextRecord->IntA0 + 3;
00110 #endif /* __X86__ */
00111     // Resume execution at the original point of "failure."
00112   return EXCEPTION_CONTINUE_EXECUTION;
00113 }
00114 #endif /* ACE_WIN32 */
00115 
00116 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00117 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::shared_bind (
00118   const ACE_NS_WString &name,
00119   const ACE_NS_WString &value,
00120   const char *type,
00121   int rebind)
00122 {
00123   // Note that we *must* use structured exception handling here
00124   // because (1) we may need to commit virtual memory pages and (2)
00125   // C++ exception handling doesn't support resumption.
00126   int result = 0;
00127   ACE_SEH_TRY
00128     {
00129       result = this->shared_bind_i (name, value, type, rebind);
00130     }
00131   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00132     {
00133     }
00134   return result;
00135 }
00136 
00137 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00138 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::shared_bind_i (
00139   const ACE_NS_WString &name,
00140   const ACE_NS_WString &value,
00141   const char *type,
00142   int rebind)
00143 {
00144 
00145   ACE_TRACE ("ACE_Local_Name_Space::shared_bind_i");
00146   const size_t name_len = (name.length () + 1) * sizeof (ACE_WCHAR_T);
00147   const size_t value_len = (value.length () + 1) * sizeof (ACE_WCHAR_T);
00148   const size_t type_len = ACE_OS::strlen (type) + 1;
00149   const size_t total_len = name_len + value_len + type_len;
00150   char *ptr = (char *) this->allocator_->malloc (total_len);
00151 
00152   if (ptr == 0)
00153     return -1;
00154   else
00155     {
00156       // Note that the value_rep *must* come first to make sure we can
00157       // retrieve this pointer later on in unbind().
00158       ACE_WCHAR_T *value_rep = (ACE_WCHAR_T *) (ptr);
00159       ACE_WCHAR_T *name_rep = (ACE_WCHAR_T *) (ptr + value_len);
00160       char *new_type = (char *) (ptr + value_len + name_len);
00161 
00162       ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
00163       ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> value_urep (value.rep ());
00164       ACE_NS_String new_name (name_rep, name_urep.get (), name_len);
00165       ACE_NS_String new_value (value_rep, value_urep.get (), value_len);
00166 
00167       ACE_OS::strcpy (new_type, type);
00168       ACE_NS_Internal new_internal (new_value, new_type);
00169       int result = -1;
00170 
00171       if (rebind == 0)
00172         {
00173           // Do a normal bind.  This will fail if there's already an
00174           // <new_internal> with the same name.
00175           result = this->name_space_map_->bind (new_name,
00176                                                 new_internal,
00177                                                 this->allocator_);
00178 
00179           if (result == 1)
00180             {
00181               // Entry already existed so bind failed. Free our
00182               // dynamically allocated memory.
00183               this->allocator_->free ((void *) ptr);
00184               return result;
00185             }
00186         }
00187       else
00188         {
00189           // Do a rebind.  If there's already any entry, this will
00190           // return the existing <new_name> and <new_internal> and
00191           // overwrite the existing name binding.
00192           ACE_NS_String old_name;
00193           ACE_NS_Internal old_internal;
00194 
00195           result = this->name_space_map_->rebind (new_name, new_internal,
00196                                                   old_name, old_internal,
00197                                                   this->allocator_);
00198           if (result == 1)
00199             {
00200               // Free up the memory we allocated in shared_bind().
00201               // Note that this assumes that the "value" pointer comes
00202               // first and that the value, name, and type are
00203               // contiguously allocated (see above for details)
00204               this->allocator_->free ((void *) (old_internal.value ()).fast_rep ());
00205             }
00206         }
00207 
00208       if (result == -1)
00209         // Free our dynamically allocated memory.
00210         this->allocator_->free ((void *) ptr);
00211       else
00212         // If bind() or rebind() succeed, they will automatically sync
00213         // up the map manager entry.  However, we must sync up our
00214         // name/value memory.
00215         this->allocator_->sync (ptr, total_len);
00216 
00217       return result;
00218     }
00219 }
00220 
00221 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00222 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::unbind (
00223   const ACE_NS_WString &name)
00224 {
00225   // Note that we *must* use structured exception handling here
00226   // because (1) we may need to commit virtual memory pages and (2)
00227   // C++ exception handling doesn't support resumption.
00228   int result = 0;
00229   ACE_SEH_TRY
00230     {
00231       result = this->unbind_i (name);
00232     }
00233   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00234     {
00235     }
00236   return result;
00237 
00238 }
00239 
00240 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00241 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::unbind_i (
00242   const ACE_NS_WString &name)
00243 {
00244   ACE_TRACE ("ACE_Local_Name_Space::unbind_i");
00245 
00246   ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00247   ACE_NS_String ns_name (name);
00248   ACE_NS_Internal ns_internal;
00249   if (this->name_space_map_->unbind (ns_name,
00250                                      ns_internal,
00251                                      this->allocator_) != 0)
00252     return -1;
00253 
00254   // Free up the memory we allocated in shared_bind().  Note that this
00255   // assumes that the "value" pointer comes first and that the value,
00256   // name and type are contiguously allocated (see shared_bind() for
00257   // details)
00258   this->allocator_->free ((void *) (ns_internal.value ()).fast_rep ());
00259   return 0;
00260 }
00261 
00262 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00263 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::bind (
00264   const ACE_NS_WString &name,
00265   const ACE_NS_WString &value,
00266   const char *type)
00267 {
00268   ACE_TRACE ("ACE_Local_Name_Space::bind");
00269   ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00270 
00271   return this->shared_bind (name, value, type, 0);
00272 }
00273 
00274 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00275 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::rebind (
00276   const ACE_NS_WString &name,
00277   const ACE_NS_WString &value,
00278   const char *type)
00279 {
00280   ACE_TRACE ("ACE_Local_Name_Space::rebind");
00281   ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00282 
00283   return this->shared_bind (name, value, type, 1);
00284 }
00285 
00286 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00287 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::resolve (
00288   const ACE_NS_WString &name,
00289   ACE_NS_WString &value,
00290   char *&type)
00291 {
00292   // Note that we *must* use structured exception handling here
00293   // because (1) we may need to commit virtual memory pages and (2)
00294   // C++ exception handling doesn't support resumption.
00295   int result = 0;
00296   ACE_SEH_TRY
00297     {
00298       result = this->resolve_i (name, value, type);
00299     }
00300   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00301     {
00302     }
00303   return result;
00304 }
00305 
00306 
00307 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00308 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::resolve_i (
00309   const ACE_NS_WString &name,
00310   ACE_NS_WString &value,
00311   char *&type)
00312 {
00313   ACE_TRACE ("ACE_Local_Name_Space::resolve_i");
00314   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00315 
00316   ACE_NS_String ns_name (name);
00317   ACE_NS_Internal ns_internal;
00318   ACE_NS_String nbc_string; // Note the classy variable name! :)
00319 
00320   if (this->name_space_map_->find (ns_name,
00321                                    ns_internal,
00322                                    this->allocator_) != 0)
00323     return -1;
00324 
00325   // Calls conversion operator and then calls the ACE_NS_WString
00326   // assignment operator to get a fresh copy.  (*#*(@#&!*@!!*@&( HP
00327   // compiler causes us to add an extra copy explicitly !! :)
00328   nbc_string = ns_internal.value ();
00329   value = nbc_string;
00330 
00331   // Gets type and then the actual reprsentation which is a
00332   // ACE_WCHAR_T
00333   const char *temp = ns_internal.type ();
00334 
00335   size_t len = ACE_OS::strlen (ns_internal.type ());
00336   // Makes a copy here. Caller needs to call delete to free up
00337   // memory.
00338   char *new_type = 0;
00339   ACE_NEW_RETURN (new_type,
00340                   char [len + 1],
00341                   -1);
00342 
00343   ACE_OS::strsncpy (new_type, temp, len + 1);
00344   type = new_type;
00345   return 0;
00346 }
00347 
00348 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00349 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::open (
00350   ACE_Naming_Context::Context_Scope_Type scope_in)
00351 {
00352   ACE_TRACE ("ACE_Local_Name_Space::open");
00353   this->ns_scope_ = scope_in;
00354 
00355   return this->create_manager ();
00356 }
00357 
00358 template <ACE_MEM_POOL_1, class ACE_LOCK>
00359 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Local_Name_Space (void)
00360   : allocator_ (0),
00361     name_space_map_ (0),
00362     name_options_ (0)
00363 {
00364   ACE_TRACE ("ACE_Local_Name_Space::ACE_Local_Name_Space");
00365 }
00366 
00367 template <ACE_MEM_POOL_1, class ACE_LOCK>
00368 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Local_Name_Space (
00369   ACE_Naming_Context::Context_Scope_Type scope_in,
00370   ACE_Name_Options *name_options)
00371   : name_options_ (name_options)
00372 {
00373   ACE_TRACE ("ACE_Local_Name_Space::ACE_Local_Name_Space");
00374   if (this->open (scope_in) == -1)
00375     ACE_ERROR ((LM_ERROR,  ACE_LIB_TEXT ("%p\n"),  ACE_LIB_TEXT ("ACE_Local_Name_Space::ACE_Local_Name_Space")));
00376 }
00377 
00378 template <ACE_MEM_POOL_1, class ACE_LOCK>
00379 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::~ACE_Local_Name_Space (void)
00380 {
00381   ACE_TRACE ("ACE_Local_Name_Space::~ACE_Local_Name_Space");
00382 
00383   // Remove the map.
00384   delete this->allocator_;
00385   delete this->lock_;
00386 }
00387 
00388 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00389 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::create_manager (void)
00390 {
00391   // Note that we *must* use structured exception handling here
00392   // because (1) we may need to commit virtual memory pages and (2)
00393   // C++ exception handling doesn't support resumption.
00394   int result = 0;
00395   ACE_SEH_TRY
00396     {
00397       result = this->create_manager_i ();
00398     }
00399   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00400     {
00401     }
00402   return result;
00403 }
00404 
00405 
00406 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00407 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::create_manager_i (void)
00408 {
00409   ACE_TRACE ("ACE_Local_Name_Space::create_manager_i");
00410   // Get directory name
00411   const ACE_TCHAR *dir = this->name_options_->namespace_dir ();
00412   const ACE_TCHAR *database = this->name_options_->database ();
00413 
00414   // Use process name as the file name.
00415   size_t len = ACE_OS::strlen (dir);
00416   len += ACE_OS::strlen (ACE_DIRECTORY_SEPARATOR_STR);
00417   len += ACE_OS::strlen (database) + 1;
00418 
00419   if (len >= MAXNAMELEN + MAXPATHLEN)
00420     {
00421       errno = ENAMETOOLONG;
00422       return -1;
00423     }
00424 
00425   ACE_OS::strcpy (this->context_file_, dir);
00426   ACE_OS::strcat (this->context_file_, ACE_DIRECTORY_SEPARATOR_STR);
00427   ACE_OS::strcat (this->context_file_, database);
00428 
00429   ACE_MEM_POOL_OPTIONS options (this->name_options_->base_address ());
00430 
00431   ACE_TCHAR lock_name_for_local_name_space [MAXNAMELEN + MAXPATHLEN];
00432   ACE_TCHAR lock_name_for_backing_store [MAXPATHLEN + MAXNAMELEN];
00433   const ACE_TCHAR *postfix = database;
00434 
00435   size_t length = 0;
00436   length = sizeof lock_name_for_local_name_space / sizeof (ACE_TCHAR);
00437   ACE_OS::strsncpy (lock_name_for_local_name_space,
00438                     dir,
00439                     length);
00440 
00441   ACE_OS::strncat (lock_name_for_local_name_space,
00442                    ACE_DIRECTORY_SEPARATOR_STR,
00443                    length -  ACE_OS::strlen (lock_name_for_local_name_space));
00444   ACE_OS::strncat (lock_name_for_local_name_space,
00445                    ACE_LIB_TEXT ("name_space_"),
00446                    length -  ACE_OS::strlen (lock_name_for_local_name_space));
00447   ACE_OS::strncat (lock_name_for_local_name_space,
00448                    postfix,
00449                    length -  ACE_OS::strlen (lock_name_for_local_name_space));
00450 
00451   length = sizeof lock_name_for_backing_store / sizeof (ACE_TCHAR);
00452   ACE_OS::strsncpy (lock_name_for_backing_store,
00453                     dir,
00454                     length);
00455   ACE_OS::strncat (lock_name_for_backing_store,
00456                    ACE_DIRECTORY_SEPARATOR_STR,
00457                    length -  ACE_OS::strlen (lock_name_for_backing_store));
00458   ACE_OS::strncat (lock_name_for_backing_store,
00459                    ACE_LIB_TEXT ("backing_store_"),
00460                    length -  ACE_OS::strlen (lock_name_for_backing_store));
00461   ACE_OS::strncat (lock_name_for_backing_store,
00462                    postfix,
00463                    length - ACE_OS::strlen (ACE_LIB_TEXT ("backing_store_")));
00464 
00465   // Create the allocator with the appropriate options.
00466   ACE_NEW_RETURN (this->allocator_,
00467                   ALLOCATOR (this->context_file_,
00468                              lock_name_for_backing_store,
00469                              &options), -1);
00470 
00471   if (ACE_LOG_MSG->op_status ())
00472     ACE_ERROR_RETURN ((LM_ERROR,
00473                        ACE_LIB_TEXT ("Allocator::Allocator\n")),
00474                       -1);
00475 
00476   ACE_NEW_RETURN (this->lock_,
00477                   ACE_LOCK (lock_name_for_local_name_space),
00478                   -1);
00479 
00480 #if !defined (ACE_LACKS_ACCESS)
00481   // Now check if the backing store has been created successfully
00482   if (ACE_OS::access (this->context_file_, F_OK) != 0)
00483     ACE_ERROR_RETURN ((LM_ERROR,
00484                        ACE_LIB_TEXT ("create_manager\n")),
00485                       -1);
00486 #endif /* ACE_LACKS_ACCESS */
00487 
00488   void *ns_map = 0;
00489 
00490   // This is the easy case since if we find the Name Server Map
00491   // Manager we know it's already initialized.
00492   if (this->allocator_->find (ACE_NAME_SERVER_MAP, ns_map) == 0)
00493     {
00494       this->name_space_map_ = (ACE_Name_Space_Map <ALLOCATOR> *) ns_map;
00495       if (ACE::debug ())
00496         ACE_DEBUG ((LM_DEBUG,
00497                     ACE_LIB_TEXT ("name_space_map_ = %d, ns_map = %d\n"),
00498                     this->name_space_map_, ns_map));
00499     }
00500 
00501   // This is the hard part since we have to avoid potential race
00502   // conditions...  We will use the double check here
00503   else
00504     {
00505       ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00506 
00507       // This is the easy case since if we find the Name Server Map
00508       // Manager we know it's already initialized.
00509       if (this->allocator_->find (ACE_NAME_SERVER_MAP, ns_map) == 0)
00510         {
00511           this->name_space_map_ = (ACE_Name_Space_Map <ALLOCATOR> *) ns_map;
00512           if (ACE::debug ())
00513             ACE_DEBUG ((LM_DEBUG,
00514                         ACE_LIB_TEXT ("name_space_map_ = %d, ns_map = %d\n"),
00515                         this->name_space_map_, ns_map));
00516         }
00517       else
00518         {
00519           size_t map_size = sizeof *this->name_space_map_;
00520           ns_map = this->allocator_->malloc (map_size);
00521 
00522           // Initialize the map into its memory location (e.g., shared memory).
00523           this->name_space_map_ =
00524             new (ns_map) ACE_Name_Space_Map <ALLOCATOR> (this->allocator_);
00525 
00526           if (this->allocator_->bind (ACE_NAME_SERVER_MAP, ns_map) == -1)
00527             ACE_ERROR_RETURN ((LM_ERROR,
00528                                ACE_LIB_TEXT ("create_manager\n")), -1);
00529         }
00530 
00531       if (ACE::debug ())
00532         ACE_DEBUG ((LM_DEBUG,
00533                     ACE_LIB_TEXT ("name_space_map_ = %d, ns_map = %d\n"),
00534                     this->name_space_map_, ns_map));
00535     }
00536 
00537   return 0;
00538 }
00539 
00540 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00541 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_names_i (
00542   ACE_WSTRING_SET &set,
00543   const ACE_NS_WString &pattern)
00544 {
00545   ACE_TRACE ("ACE_Local_Name_Space::list_names_i");
00546   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00547 
00548   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00549   MAP_MANAGER::ENTRY *map_entry;
00550 
00551   int result = 1;
00552 
00553   for (map_entry = 0;
00554        map_iterator.next (map_entry) != 0;
00555        map_iterator.advance())
00556     {
00557       if (map_entry->ext_id_.strstr (pattern) != -1)
00558         {
00559           ACE_NS_WString entry (map_entry->ext_id_ );
00560 
00561           if (set.insert (entry) == -1)
00562             {
00563               result = -1;
00564               break;
00565             }
00566           else
00567             result = 0;
00568         }
00569     }
00570 
00571   return result;
00572 }
00573 
00574 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00575 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_values_i (
00576   ACE_WSTRING_SET &set,
00577   const ACE_NS_WString &pattern)
00578 {
00579   ACE_TRACE ("ACE_Local_Name_Space::list_values_i");
00580   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00581 
00582   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00583   MAP_MANAGER::ENTRY *map_entry;
00584 
00585   int result = 1;
00586 
00587   for (map_entry = 0;
00588        map_iterator.next (map_entry) != 0;
00589        map_iterator.advance ())
00590     {
00591       if (map_entry->int_id_.value ().strstr (pattern) != -1)
00592         {
00593           ACE_NS_WString entry (map_entry->int_id_.value ());
00594 
00595           if (set.insert (entry) == -1)
00596             {
00597               result = -1;
00598               break;
00599             }
00600           else
00601             result = 0;
00602         }
00603     }
00604 
00605   return result;
00606 }
00607 
00608 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00609 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_types_i (
00610   ACE_WSTRING_SET &set,
00611   const ACE_NS_WString &pattern)
00612 {
00613   ACE_TRACE ("ACE_Local_Name_Space::list_types_i");
00614   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00615 
00616   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00617   MAP_MANAGER::ENTRY *map_entry;
00618 
00619   char *compiled_regexp = 0;
00620 
00621   // Note that char_rep() allocates memory so we need to delete it
00622   char *pattern_rep = pattern.char_rep ();
00623 
00624   // Check for wildcard case first.
00625   if (ACE_OS::strcmp ("", pattern_rep) == 0)
00626     ACE_ALLOCATOR_RETURN (compiled_regexp,
00627                           ACE_OS::strdup (""),
00628                           -1);
00629   else
00630     // Compile the regular expression (the 0's cause ACE_OS::compile
00631     // to allocate space).
00632 #if defined (ACE_HAS_REGEX)
00633     compiled_regexp = ACE_OS::compile (pattern_rep, 0, 0);
00634 #else
00635   // If we don't have regular expressions just use the pattern
00636   // directly.
00637   compiled_regexp = pattern_rep;
00638 #endif /* ACE_HAS_REGEX */
00639 
00640   int result = 1;
00641 
00642   for (map_entry = 0;
00643        map_iterator.next (map_entry) != 0;
00644        map_iterator.advance ())
00645     {
00646       // Get the type
00647       const char *type = map_entry->int_id_.type ();
00648 
00649       // Everything matches the wildcard.
00650       if (ACE_OS::strcmp ("", pattern_rep) == 0
00651 #if defined (ACE_HAS_REGEX)
00652           || ACE_OS::step (type, compiled_regexp) != 0)
00653 #else
00654         // If we don't have regular expressions just use strstr() for
00655         // substring matching.
00656         || ACE_OS::strstr (type, compiled_regexp) != 0)
00657 #endif /* ACE_HAS_REGEX */
00658 
00659         {
00660           ACE_NS_WString entry (type);
00661 
00662           if (set.insert (entry) == -1)
00663             {
00664               result = -1;
00665               break;
00666             }
00667           else
00668             result = 0;
00669         }
00670     }
00671 #if defined (ACE_HAS_REGEX)
00672   if (compiled_regexp)
00673     ACE_OS::free ((void *) compiled_regexp);
00674 #endif /* ACE_HAS_REGEX */
00675   delete [] pattern_rep;  // delete pattern_rep;
00676   return result;
00677 }
00678 
00679 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00680 ACE_Local_Name_Space <ACE_MEM_POOL_2, ACE_LOCK>::list_name_entries_i (
00681   ACE_BINDING_SET &set,
00682   const ACE_NS_WString &pattern)
00683 {
00684   ACE_TRACE ("ACE_Local_Name_Space::list_name_entries_i");
00685   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00686 
00687   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00688   MAP_MANAGER::ENTRY *map_entry;
00689 
00690   for (map_entry = 0;
00691        map_iterator.next (map_entry) != 0;
00692        map_iterator.advance())
00693     {
00694       if (map_entry->ext_id_.strstr (pattern) != -1)
00695         {
00696           ACE_Name_Binding entry (map_entry->ext_id_,
00697                                   map_entry->int_id_.value (),
00698                                   map_entry->int_id_.type ());
00699 
00700           if (set.insert (entry) == -1)
00701             return -1;
00702         }
00703     }
00704 
00705   return 0;
00706 }
00707 
00708 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00709 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_value_entries_i (
00710   ACE_BINDING_SET &set,
00711   const ACE_NS_WString &pattern)
00712 {
00713   ACE_TRACE ("ACE_Local_Name_Space::list_value_entries_i");
00714   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00715 
00716   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00717   MAP_MANAGER::ENTRY *map_entry;
00718 
00719   for (map_entry = 0;
00720        map_iterator.next (map_entry) != 0;
00721        map_iterator.advance ())
00722     {
00723       if (map_entry->int_id_.value ().strstr (pattern) != -1)
00724         {
00725           ACE_Name_Binding entry (map_entry->ext_id_,
00726                                   map_entry->int_id_.value (),
00727                                   map_entry->int_id_.type ());
00728 
00729           if (set.insert (entry) == -1)
00730             return -1;
00731         }
00732     }
00733   return 0;
00734 }
00735 
00736 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00737 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_type_entries_i (
00738   ACE_BINDING_SET &set,
00739   const ACE_NS_WString &pattern)
00740 {
00741   ACE_TRACE ("ACE_Local_Name_Space::list_type_entries_i");
00742   ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
00743 
00744   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00745   MAP_MANAGER::ENTRY *map_entry;
00746 
00747   char *compiled_regexp = 0;
00748   // Note that char_rep() allocates memory so we need to delete it
00749   char *pattern_rep = pattern.char_rep ();
00750 
00751   // Check for wildcard case first.
00752   if (ACE_OS::strcmp ("", pattern_rep) == 0)
00753     compiled_regexp = ACE_OS::strdup ("");
00754   else
00755     // Compile the regular expression (the 0's cause ACE_OS::compile
00756     // to allocate space).
00757 #if defined (ACE_HAS_REGEX)
00758     compiled_regexp = ACE_OS::compile (pattern_rep, 0, 0);
00759 #else /* If we don't have regular expressions just the pattern
00760          directly. */
00761   compiled_regexp = pattern_rep;
00762 #endif /* ACE_HAS_REGEX */
00763 
00764   for (map_entry = 0;
00765        map_iterator.next (map_entry) != 0;
00766        map_iterator.advance ())
00767     {
00768       // Get the type.
00769       const char *type = map_entry->int_id_.type ();
00770 
00771       if (ACE_OS::strcmp ("", pattern_rep) == 0 // Everything matches
00772                                                 // the wildcard.
00773 #if defined (ACE_HAS_REGEX)
00774           || ACE_OS::step (type, compiled_regexp) != 0)
00775 #else /* If we don't have regular expressions just use strstr() for
00776          substring matching. */
00777         || ACE_OS::strstr (type, compiled_regexp) != 0)
00778 #endif /* ACE_HAS_REGEX */
00779         {
00780           ACE_Name_Binding entry (map_entry->ext_id_,
00781                                   map_entry->int_id_.value (),
00782                                   map_entry->int_id_.type ());
00783 
00784           if (set.insert (entry) == -1)
00785             return -1;
00786         }
00787     }
00788 #if defined (ACE_HAS_REGEX)
00789   if (compiled_regexp)
00790     ACE_OS::free ((void *) compiled_regexp);
00791 #endif /* ACE_HAS_REGEX */
00792   delete [] pattern_rep;  // delete pattern_rep;
00793   return 0;
00794 }
00795 
00796 template <ACE_MEM_POOL_1, class ACE_LOCK> void
00797 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::dump_i (void) const
00798 {
00799   ACE_TRACE ("ACE_Local_Name_Space::dump_i");
00800 
00801   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00802 
00803   MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
00804   MAP_MANAGER::ENTRY *map_entry;
00805 
00806   for (map_entry = 0;
00807        map_iterator.next (map_entry) != 0;
00808        map_iterator.advance())
00809     {
00810       char *key = map_entry->ext_id_.char_rep ();
00811       char *value = map_entry->int_id_.value ().char_rep ();
00812 #if !defined (ACE_NLOGGING)
00813       const char *type = map_entry->int_id_.type ();
00814 #endif /* ! ACE_NLOGGING */
00815 
00816       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("key=%s\nvalue=%s\ntype=%s\n"),
00817                   ACE_TEXT_CHAR_TO_TCHAR (key), ACE_TEXT_CHAR_TO_TCHAR (value), ACE_TEXT_CHAR_TO_TCHAR (type)));
00818       // We need to delete key and value since char_rep allocates
00819       // memory for them
00820       delete [] key;
00821       delete [] value;
00822     }
00823 
00824   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00825 }
00826 
00827 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00828 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_names (
00829   ACE_WSTRING_SET &set,
00830   const ACE_NS_WString &pattern)
00831 {
00832   // Note that we *must* use structured exception handling here
00833   // because (1) we may need to commit virtual memory pages and (2)
00834   // C++ exception handling doesn't support resumption.
00835   int result = 0;
00836   ACE_SEH_TRY
00837     {
00838       result = this->list_names_i (set, pattern);
00839     }
00840   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00841     {
00842     }
00843   return result;
00844 }
00845 
00846 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00847 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_values (
00848   ACE_WSTRING_SET &set,
00849   const ACE_NS_WString &pattern)
00850 {
00851   // Note that we *must* use structured exception handling here
00852   // because (1) we may need to commit virtual memory pages and (2)
00853   // C++ exception handling doesn't support resumption.
00854   int result = 0;
00855   ACE_SEH_TRY
00856     {
00857       result = this->list_values_i (set, pattern);
00858     }
00859   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00860     {
00861     }
00862   return result;
00863 }
00864 
00865 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00866 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_types (
00867   ACE_WSTRING_SET &set,
00868   const ACE_NS_WString &pattern)
00869 {
00870   // Note that we *must* use structured exception handling here
00871   // because (1) we may need to commit virtual memory pages and (2)
00872   // C++ exception handling doesn't support resumption.
00873   int result = 0;
00874   ACE_SEH_TRY
00875     {
00876       result = this->list_types_i (set, pattern);
00877     }
00878   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00879     {
00880     }
00881   return result;
00882 }
00883 
00884 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00885 ACE_Local_Name_Space <ACE_MEM_POOL_2, ACE_LOCK>::list_name_entries (
00886   ACE_BINDING_SET &set,
00887   const ACE_NS_WString &pattern)
00888 {
00889   // Note that we *must* use structured exception handling here
00890   // because (1) we may need to commit virtual memory pages and (2)
00891   // C++ exception handling doesn't support resumption.
00892   int result = 0;
00893   ACE_SEH_TRY
00894     {
00895       result = this->list_name_entries_i (set, pattern);
00896     }
00897   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00898     {
00899     }
00900   return result;
00901 }
00902 
00903 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00904 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_value_entries (
00905   ACE_BINDING_SET &set,
00906   const ACE_NS_WString &pattern)
00907 {
00908   // Note that we *must* use structured exception handling here
00909   // because (1) we may need to commit virtual memory pages and (2)
00910   // C++ exception handling doesn't support resumption.
00911   int result = 0;
00912   ACE_SEH_TRY
00913     {
00914       result = this->list_value_entries_i (set, pattern);
00915     }
00916   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00917     {
00918     }
00919   return result;
00920 }
00921 
00922 template <ACE_MEM_POOL_1, class ACE_LOCK> int
00923 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_type_entries (
00924   ACE_BINDING_SET &set,
00925   const ACE_NS_WString &pattern)
00926 {
00927   // Note that we *must* use structured exception handling here
00928   // because (1) we may need to commit virtual memory pages and (2)
00929   // C++ exception handling doesn't support resumption.
00930   int result = 0;
00931   ACE_SEH_TRY
00932     {
00933       result = this->list_type_entries_i (set, pattern);
00934     }
00935   ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
00936     {
00937     }
00938   return result;
00939 }
00940 
00941 template <ACE_MEM_POOL_1, class ACE_LOCK> void
00942 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::dump (void) const
00943 {
00944 #if defined (ACE_HAS_DUMP)
00945   // Note that we *must* use structured exception handling here
00946   // because (1) we may need to commit virtual memory pages and (2)
00947   // C++ exception handling doesn't support resumption.
00948 
00949   // This should really be a const cast
00950   ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK> *fake_this =
00951     (ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK> *) this;
00952   ACE_UNUSED_ARG (fake_this);
00953 
00954   ACE_SEH_TRY
00955     {
00956       this->dump_i ();
00957     }
00958   ACE_SEH_EXCEPT (fake_this->remap (GetExceptionInformation ()))
00959     {
00960     }
00961 #endif /* ACE_HAS_DUMP */
00962 }
00963 
00964 ACE_END_VERSIONED_NAMESPACE_DECL
00965 
00966 #endif /* ACE_LOCAL_NAME_SPACE_T_CPP */

Generated on Thu Nov 9 09:41:53 2006 for ACE by doxygen 1.3.6