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

Local_Name_Space_T.cpp

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

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