Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Local_Name_Space_T.cpp
blobcf04a35f4211342125ac56132dd3ff0176460bd8
1 #ifndef ACE_LOCAL_NAME_SPACE_T_CPP
2 #define ACE_LOCAL_NAME_SPACE_T_CPP
4 #include "ace/ACE.h"
6 #if !defined (ACE_LACKS_PRAGMA_ONCE)
7 # pragma once
8 #endif /* ACE_LACKS_PRAGMA_ONCE */
10 #include "ace/Local_Name_Space.h"
11 #include "ace/Auto_Ptr.h"
12 #include "ace/Guard_T.h"
13 #include "ace/OS_NS_regex.h"
14 #include "ace/OS_NS_string.h"
15 #include "ace/OS_NS_unistd.h"
17 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
19 template <class ALLOCATOR>
20 ACE_Name_Space_Map<ALLOCATOR>::ACE_Name_Space_Map (ALLOCATOR *alloc)
21 : MAP_MANAGER (alloc)
23 ACE_TRACE ("ACE_Name_Space_Map::ACE_Name_Space_Map");
26 template <class ALLOCATOR> int
27 ACE_Name_Space_Map<ALLOCATOR>::close (ALLOCATOR *alloc)
29 ACE_TRACE ("ACE_Name_Space_Map::close");
31 this->table_allocator_ = alloc;
32 this->entry_allocator_ = alloc;
33 return this->close_i ();
36 template <class ALLOCATOR> int
37 ACE_Name_Space_Map<ALLOCATOR>::bind (const ACE_NS_String &ext_id,
38 const ACE_NS_Internal &int_id,
39 ALLOCATOR *alloc)
41 ACE_TRACE ("ACE_Name_Space_Map::bind");
43 this->table_allocator_ = alloc;
44 this->entry_allocator_ = alloc;
45 return this->bind_i (ext_id, int_id);
48 template <class ALLOCATOR> int
49 ACE_Name_Space_Map<ALLOCATOR>::unbind (const ACE_NS_String &ext_id,
50 ACE_NS_Internal &int_id,
51 ALLOCATOR *alloc)
53 ACE_TRACE ("ACE_Name_Space_Map::unbind");
55 this->table_allocator_ = alloc;
56 this->entry_allocator_ = alloc;
57 return this->unbind_i (ext_id, int_id);
60 template <class ALLOCATOR> int
61 ACE_Name_Space_Map<ALLOCATOR>::rebind (const ACE_NS_String &ext_id,
62 const ACE_NS_Internal &int_id,
63 ACE_NS_String &old_ext_id,
64 ACE_NS_Internal &old_int_id,
65 ALLOCATOR *alloc)
67 ACE_TRACE ("ACE_Name_Space_Map::rebind");
69 this->table_allocator_ = alloc;
70 this->entry_allocator_ = alloc;
71 return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id);
74 template <class ALLOCATOR> int
75 ACE_Name_Space_Map<ALLOCATOR>::find (const ACE_NS_String &ext_id,
76 ACE_NS_Internal &int_id,
77 ALLOCATOR *alloc)
79 ACE_TRACE ("ACE_Name_Space_Map::find");
81 this->table_allocator_ = alloc;
82 this->entry_allocator_ = alloc;
83 return this->find_i (ext_id, int_id);
86 #if defined (ACE_WIN32)
87 template <ACE_MEM_POOL_1, class ACE_LOCK> int
88 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::remap (EXCEPTION_POINTERS *ep)
90 ACE_TRACE ("ACE_Local_Name_Space::remap");
92 void *addr = (void *) ep->ExceptionRecord->ExceptionInformation[1];
94 // The following requires Memory Pool to have ::remap()
95 // defined. Thus currently this will only work for
96 // ACE_MMap_Memory_Pool.
97 if (this->allocator_->alloc ().memory_pool ().remap (addr) == -1)
98 // Kick it upstairs...
99 return EXCEPTION_CONTINUE_SEARCH;
101 #if __X86__
102 // This is 80x86-specific.
103 ep->ContextRecord->Edi = (DWORD) addr;
104 #elif __MIPS__
105 ep->ContextRecord->IntA0 =
106 ep->ContextRecord->IntV0 = (DWORD) addr;
107 ep->ContextRecord->IntT5 = ep->ContextRecord->IntA0 + 3;
108 #endif /* __X86__ */
109 // Resume execution at the original point of "failure."
110 return EXCEPTION_CONTINUE_EXECUTION;
112 #endif /* ACE_WIN32 */
114 template <ACE_MEM_POOL_1, class ACE_LOCK> int
115 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::shared_bind (
116 const ACE_NS_WString &name,
117 const ACE_NS_WString &value,
118 const char *type,
119 int rebind)
121 // Note that we *must* use structured exception handling here
122 // because (1) we may need to commit virtual memory pages and (2)
123 // C++ exception handling doesn't support resumption.
124 int result = 0;
125 ACE_SEH_TRY
127 result = this->shared_bind_i (name, value, type, rebind);
129 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
132 return result;
135 template <ACE_MEM_POOL_1, class ACE_LOCK> int
136 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::shared_bind_i (
137 const ACE_NS_WString &name,
138 const ACE_NS_WString &value,
139 const char *type,
140 int rebind)
143 ACE_TRACE ("ACE_Local_Name_Space::shared_bind_i");
144 const size_t name_len = (name.length () + 1) * sizeof (ACE_WCHAR_T);
145 const size_t value_len = (value.length () + 1) * sizeof (ACE_WCHAR_T);
146 const size_t type_len = ACE_OS::strlen (type) + 1;
147 const size_t total_len = name_len + value_len + type_len;
148 char *ptr = (char *) this->allocator_->malloc (total_len);
150 if (ptr == 0)
151 return -1;
152 else
154 // Note that the value_rep *must* come first to make sure we can
155 // retrieve this pointer later on in unbind().
156 ACE_WCHAR_T *value_rep = (ACE_WCHAR_T *) (ptr);
157 ACE_WCHAR_T *name_rep = (ACE_WCHAR_T *) (ptr + value_len);
158 char *new_type = (char *) (ptr + value_len + name_len);
160 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
161 ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> value_urep (value.rep ());
162 ACE_NS_String new_name (name_rep, name_urep.get (), name_len);
163 ACE_NS_String new_value (value_rep, value_urep.get (), value_len);
165 ACE_OS::strcpy (new_type, type);
166 ACE_NS_Internal new_internal (new_value, new_type);
167 int result = -1;
169 if (rebind == 0)
171 // Do a normal bind. This will fail if there's already an
172 // <new_internal> with the same name.
173 result = this->name_space_map_->bind (new_name,
174 new_internal,
175 this->allocator_);
177 if (result == 1)
179 // Entry already existed so bind failed. Free our
180 // dynamically allocated memory.
181 this->allocator_->free ((void *) ptr);
182 return result;
185 else
187 // Do a rebind. If there's already any entry, this will
188 // return the existing <new_name> and <new_internal> and
189 // overwrite the existing name binding.
190 ACE_NS_String old_name;
191 ACE_NS_Internal old_internal;
193 result = this->name_space_map_->rebind (new_name, new_internal,
194 old_name, old_internal,
195 this->allocator_);
196 if (result == 1)
198 // Free up the memory we allocated in shared_bind().
199 // Note that this assumes that the "value" pointer comes
200 // first and that the value, name, and type are
201 // contiguously allocated (see above for details)
202 this->allocator_->free ((void *) (old_internal.value ()).fast_rep ());
206 if (result == -1)
207 // Free our dynamically allocated memory.
208 this->allocator_->free ((void *) ptr);
209 else
210 // If bind() or rebind() succeed, they will automatically sync
211 // up the map manager entry. However, we must sync up our
212 // name/value memory.
213 this->allocator_->sync (ptr, total_len);
215 return result;
219 template <ACE_MEM_POOL_1, class ACE_LOCK> int
220 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::unbind (
221 const ACE_NS_WString &name)
223 // Note that we *must* use structured exception handling here
224 // because (1) we may need to commit virtual memory pages and (2)
225 // C++ exception handling doesn't support resumption.
226 int result = 0;
227 ACE_SEH_TRY
229 result = this->unbind_i (name);
231 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
234 return result;
238 template <ACE_MEM_POOL_1, class ACE_LOCK> int
239 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::unbind_i (
240 const ACE_NS_WString &name)
242 ACE_TRACE ("ACE_Local_Name_Space::unbind_i");
244 ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
245 ACE_NS_String ns_name (name);
246 ACE_NS_Internal ns_internal;
247 if (this->name_space_map_->unbind (ns_name,
248 ns_internal,
249 this->allocator_) != 0)
250 return -1;
252 // Free up the memory we allocated in shared_bind(). Note that this
253 // assumes that the "value" pointer comes first and that the value,
254 // name and type are contiguously allocated (see shared_bind() for
255 // details)
256 this->allocator_->free ((void *) (ns_internal.value ()).fast_rep ());
257 return 0;
260 template <ACE_MEM_POOL_1, class ACE_LOCK> int
261 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::bind (
262 const ACE_NS_WString &name,
263 const ACE_NS_WString &value,
264 const char *type)
266 ACE_TRACE ("ACE_Local_Name_Space::bind");
267 ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
269 return this->shared_bind (name, value, type, 0);
272 template <ACE_MEM_POOL_1, class ACE_LOCK> int
273 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::rebind (
274 const ACE_NS_WString &name,
275 const ACE_NS_WString &value,
276 const char *type)
278 ACE_TRACE ("ACE_Local_Name_Space::rebind");
279 ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
281 return this->shared_bind (name, value, type, 1);
284 template <ACE_MEM_POOL_1, class ACE_LOCK> int
285 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::resolve (
286 const ACE_NS_WString &name,
287 ACE_NS_WString &value,
288 char *&type)
290 // Note that we *must* use structured exception handling here
291 // because (1) we may need to commit virtual memory pages and (2)
292 // C++ exception handling doesn't support resumption.
293 int result = 0;
294 ACE_SEH_TRY
296 result = this->resolve_i (name, value, type);
298 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
301 return result;
305 template <ACE_MEM_POOL_1, class ACE_LOCK> int
306 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::resolve_i (
307 const ACE_NS_WString &name,
308 ACE_NS_WString &value,
309 char *&type)
311 ACE_TRACE ("ACE_Local_Name_Space::resolve_i");
312 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
314 ACE_NS_String ns_name (name);
315 ACE_NS_Internal ns_internal;
316 ACE_NS_String nbc_string; // Note the classy variable name! :)
318 if (this->name_space_map_->find (ns_name,
319 ns_internal,
320 this->allocator_) != 0)
321 return -1;
323 // Calls conversion operator and then calls the ACE_NS_WString
324 // assignment operator to get a fresh copy. (*#*(@#&!*@!!*@&( HP
325 // compiler causes us to add an extra copy explicitly !! :)
326 nbc_string = ns_internal.value ();
327 value = nbc_string;
329 // Gets type and then the actual reprsentation which is a
330 // ACE_WCHAR_T
331 const char *temp = ns_internal.type ();
333 size_t len = ACE_OS::strlen (ns_internal.type ());
334 // Makes a copy here. Caller needs to call delete to free up
335 // memory.
336 char *new_type = 0;
337 #if defined (ACE_HAS_ALLOC_HOOKS)
338 ACE_ALLOCATOR_RETURN (new_type,
339 static_cast<char*>(ACE_Allocator::instance()->malloc(sizeof(char) * (len + 1))),
340 -1);
341 #else
342 ACE_NEW_RETURN (new_type,
343 char [len + 1],
344 -1);
345 #endif /* ACE_HAS_ALLOC_HOOKS */
347 ACE_OS::strsncpy (new_type, temp, len + 1);
348 type = new_type;
349 return 0;
352 template <ACE_MEM_POOL_1, class ACE_LOCK> int
353 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::open (
354 ACE_Naming_Context::Context_Scope_Type scope_in)
356 ACE_TRACE ("ACE_Local_Name_Space::open");
357 this->ns_scope_ = scope_in;
359 return this->create_manager ();
362 template <ACE_MEM_POOL_1, class ACE_LOCK>
363 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Local_Name_Space (void)
364 : allocator_ (0),
365 name_space_map_ (0),
366 name_options_ (0)
368 ACE_TRACE ("ACE_Local_Name_Space::ACE_Local_Name_Space");
371 template <ACE_MEM_POOL_1, class ACE_LOCK>
372 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Local_Name_Space (
373 ACE_Naming_Context::Context_Scope_Type scope_in,
374 ACE_Name_Options *name_options)
375 : allocator_ (0),
376 name_space_map_ (0),
377 name_options_ (name_options),
378 lock_ (0)
380 ACE_TRACE ("ACE_Local_Name_Space::ACE_Local_Name_Space");
381 if (this->open (scope_in) == -1)
382 ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ACE_Local_Name_Space::ACE_Local_Name_Space")));
385 template <ACE_MEM_POOL_1, class ACE_LOCK>
386 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::~ACE_Local_Name_Space (void)
388 ACE_TRACE ("ACE_Local_Name_Space::~ACE_Local_Name_Space");
390 // Remove the map.
391 delete this->allocator_;
392 delete this->lock_;
395 ACE_ALLOC_HOOK_DEFINE_Tcc(ACE_Local_Name_Space)
397 template <ACE_MEM_POOL_1, class ACE_LOCK> int
398 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::create_manager (void)
400 // Note that we *must* use structured exception handling here
401 // because (1) we may need to commit virtual memory pages and (2)
402 // C++ exception handling doesn't support resumption.
403 int result = 0;
404 ACE_SEH_TRY
406 result = this->create_manager_i ();
408 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
411 return result;
415 template <ACE_MEM_POOL_1, class ACE_LOCK> int
416 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::create_manager_i (void)
418 ACE_TRACE ("ACE_Local_Name_Space::create_manager_i");
419 // Get directory name
420 const ACE_TCHAR *dir = this->name_options_->namespace_dir ();
421 const ACE_TCHAR *database = this->name_options_->database ();
423 // Use process name as the file name.
424 size_t len = ACE_OS::strlen (dir);
425 len += ACE_OS::strlen (ACE_DIRECTORY_SEPARATOR_STR);
426 len += ACE_OS::strlen (database) + 1;
428 if (len >= MAXNAMELEN + MAXPATHLEN)
430 errno = ENAMETOOLONG;
431 return -1;
434 ACE_OS::strcpy (this->context_file_, dir);
435 ACE_OS::strcat (this->context_file_, ACE_DIRECTORY_SEPARATOR_STR);
436 ACE_OS::strcat (this->context_file_, database);
438 ACE_MEM_POOL_OPTIONS options (this->name_options_->base_address ());
440 ACE_TCHAR lock_name_for_local_name_space [MAXNAMELEN + MAXPATHLEN];
441 ACE_TCHAR lock_name_for_backing_store [MAXPATHLEN + MAXNAMELEN];
442 const ACE_TCHAR *postfix = database;
444 size_t length = 0;
445 length = sizeof lock_name_for_local_name_space / sizeof (ACE_TCHAR);
446 ACE_OS::strsncpy (lock_name_for_local_name_space,
447 dir,
448 length);
450 ACE_OS::strncat (lock_name_for_local_name_space,
451 ACE_DIRECTORY_SEPARATOR_STR,
452 length - ACE_OS::strlen (lock_name_for_local_name_space));
453 ACE_OS::strncat (lock_name_for_local_name_space,
454 ACE_TEXT ("name_space_"),
455 length - ACE_OS::strlen (lock_name_for_local_name_space));
456 ACE_OS::strncat (lock_name_for_local_name_space,
457 postfix,
458 length - ACE_OS::strlen (lock_name_for_local_name_space));
460 length = sizeof lock_name_for_backing_store / sizeof (ACE_TCHAR);
461 ACE_OS::strsncpy (lock_name_for_backing_store,
462 dir,
463 length);
464 ACE_OS::strncat (lock_name_for_backing_store,
465 ACE_DIRECTORY_SEPARATOR_STR,
466 length - ACE_OS::strlen (lock_name_for_backing_store));
467 ACE_OS::strncat (lock_name_for_backing_store,
468 ACE_TEXT ("backing_store_"),
469 length - ACE_OS::strlen (lock_name_for_backing_store));
470 ACE_OS::strncat (lock_name_for_backing_store,
471 postfix,
472 length - ACE_OS::strlen (ACE_TEXT ("backing_store_")));
474 // Create the allocator with the appropriate options.
475 ACE_NEW_RETURN (this->allocator_,
476 ALLOCATOR (this->context_file_,
477 lock_name_for_backing_store,
478 &options), -1);
480 if (ACE_LOG_MSG->op_status ())
481 ACELIB_ERROR_RETURN ((LM_ERROR,
482 ACE_TEXT ("Allocator::Allocator\n")),
483 -1);
485 ACE_NEW_RETURN (this->lock_,
486 ACE_LOCK (lock_name_for_local_name_space),
487 -1);
489 #if !defined (ACE_LACKS_ACCESS)
490 // Now check if the backing store has been created successfully
491 if (ACE_OS::access (this->context_file_, F_OK) != 0)
492 ACELIB_ERROR_RETURN ((LM_ERROR,
493 ACE_TEXT ("create_manager\n")),
494 -1);
495 #endif /* ACE_LACKS_ACCESS */
497 void *ns_map = 0;
499 // This is the easy case since if we find the Name Server Map
500 // Manager we know it's already initialized.
501 if (this->allocator_->find (ACE_NAME_SERVER_MAP, ns_map) == 0)
503 this->name_space_map_ = (ACE_Name_Space_Map <ALLOCATOR> *) ns_map;
504 if (ACE::debug ())
505 ACELIB_DEBUG ((LM_DEBUG,
506 ACE_TEXT ("name_space_map_ = %@, ns_map = %@\n"),
507 this->name_space_map_, ns_map));
510 // This is the hard part since we have to avoid potential race
511 // conditions... We will use the double check here
512 else
514 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
516 // This is the easy case since if we find the Name Server Map
517 // Manager we know it's already initialized.
518 if (this->allocator_->find (ACE_NAME_SERVER_MAP, ns_map) == 0)
520 this->name_space_map_ = (ACE_Name_Space_Map <ALLOCATOR> *) ns_map;
521 if (ACE::debug ())
522 ACELIB_DEBUG ((LM_DEBUG,
523 ACE_TEXT ("name_space_map_ = %@, ns_map = %@\n"),
524 this->name_space_map_, ns_map));
526 else
528 size_t map_size = sizeof *this->name_space_map_;
529 ns_map = this->allocator_->malloc (map_size);
531 // Initialize the map into its memory location (e.g., shared memory).
532 this->name_space_map_ =
533 new (ns_map) ACE_Name_Space_Map <ALLOCATOR> (this->allocator_);
535 if (this->allocator_->bind (ACE_NAME_SERVER_MAP, ns_map) == -1)
536 ACELIB_ERROR_RETURN ((LM_ERROR,
537 ACE_TEXT ("create_manager\n")), -1);
540 if (ACE::debug ())
541 ACELIB_DEBUG ((LM_DEBUG,
542 ACE_TEXT ("name_space_map_ = %@, ns_map = %@\n"),
543 this->name_space_map_, ns_map));
546 return 0;
549 template <ACE_MEM_POOL_1, class ACE_LOCK> int
550 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_names_i (
551 ACE_WSTRING_SET &set,
552 const ACE_NS_WString &pattern)
554 ACE_TRACE ("ACE_Local_Name_Space::list_names_i");
555 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
557 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
558 MAP_MANAGER::ENTRY *map_entry;
560 int result = 1;
562 for (map_entry = 0;
563 map_iterator.next (map_entry) != 0;
564 map_iterator.advance())
566 if (map_entry->ext_id_.strstr (pattern) != -1)
568 ACE_NS_WString entry (map_entry->ext_id_ );
570 if (set.insert (entry) == -1)
572 result = -1;
573 break;
575 else
576 result = 0;
580 return result;
583 template <ACE_MEM_POOL_1, class ACE_LOCK> int
584 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_values_i (
585 ACE_WSTRING_SET &set,
586 const ACE_NS_WString &pattern)
588 ACE_TRACE ("ACE_Local_Name_Space::list_values_i");
589 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
591 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
592 MAP_MANAGER::ENTRY *map_entry;
594 int result = 1;
596 for (map_entry = 0;
597 map_iterator.next (map_entry) != 0;
598 map_iterator.advance ())
600 if (map_entry->int_id_.value ().strstr (pattern) != -1)
602 ACE_NS_WString entry (map_entry->int_id_.value ());
604 if (set.insert (entry) == -1)
606 result = -1;
607 break;
609 else
610 result = 0;
614 return result;
617 template <ACE_MEM_POOL_1, class ACE_LOCK> int
618 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_types_i (
619 ACE_WSTRING_SET &set,
620 const ACE_NS_WString &pattern)
622 ACE_TRACE ("ACE_Local_Name_Space::list_types_i");
623 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
625 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
626 MAP_MANAGER::ENTRY *map_entry;
628 char *compiled_regexp = 0;
630 // Note that char_rep() allocates memory so we need to delete it
631 char *pattern_rep = pattern.char_rep ();
633 // Check for wildcard case first.
634 if (ACE_OS::strcmp ("", pattern_rep) == 0)
635 ACE_ALLOCATOR_RETURN (compiled_regexp,
636 ACE_OS::strdup (""),
637 -1);
638 else
639 // Compile the regular expression (the 0's cause ACE_OS::compile
640 // to allocate space).
641 #if defined (ACE_HAS_REGEX)
642 compiled_regexp = ACE_OS::compile (pattern_rep, 0, 0);
643 #else
644 // If we don't have regular expressions just use the pattern
645 // directly.
646 compiled_regexp = pattern_rep;
647 #endif /* ACE_HAS_REGEX */
649 int result = 1;
651 for (map_entry = 0;
652 map_iterator.next (map_entry) != 0;
653 map_iterator.advance ())
655 // Get the type
656 const char *type = map_entry->int_id_.type ();
658 // Everything matches the wildcard.
659 if (ACE_OS::strcmp ("", pattern_rep) == 0
660 #if defined (ACE_HAS_REGEX)
661 || ACE_OS::step (type, compiled_regexp) != 0)
662 #else
663 // If we don't have regular expressions just use strstr() for
664 // substring matching.
665 || ACE_OS::strstr (type, compiled_regexp) != 0)
666 #endif /* ACE_HAS_REGEX */
669 ACE_NS_WString entry (type);
671 if (set.insert (entry) == -1)
673 result = -1;
674 break;
676 else
677 result = 0;
680 #if defined (ACE_HAS_REGEX)
681 if (compiled_regexp)
682 ACE_OS::free ((void *) compiled_regexp);
683 #endif /* ACE_HAS_REGEX */
684 #if defined (ACE_HAS_ALLOC_HOOKS)
685 ACE_Allocator::instance()->free(pattern_rep);
686 #else
687 delete [] pattern_rep; // delete pattern_rep;
688 #endif /* ACE_HAS_ALLOC_HOOKS */
689 return result;
692 template <ACE_MEM_POOL_1, class ACE_LOCK> int
693 ACE_Local_Name_Space <ACE_MEM_POOL_2, ACE_LOCK>::list_name_entries_i (
694 ACE_BINDING_SET &set,
695 const ACE_NS_WString &pattern)
697 ACE_TRACE ("ACE_Local_Name_Space::list_name_entries_i");
698 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
700 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
701 MAP_MANAGER::ENTRY *map_entry;
703 for (map_entry = 0;
704 map_iterator.next (map_entry) != 0;
705 map_iterator.advance())
707 if (map_entry->ext_id_.strstr (pattern) != -1)
709 ACE_Name_Binding entry (map_entry->ext_id_,
710 map_entry->int_id_.value (),
711 map_entry->int_id_.type ());
713 if (set.insert (entry) == -1)
714 return -1;
718 return 0;
721 template <ACE_MEM_POOL_1, class ACE_LOCK> int
722 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_value_entries_i (
723 ACE_BINDING_SET &set,
724 const ACE_NS_WString &pattern)
726 ACE_TRACE ("ACE_Local_Name_Space::list_value_entries_i");
727 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
729 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
730 MAP_MANAGER::ENTRY *map_entry;
732 for (map_entry = 0;
733 map_iterator.next (map_entry) != 0;
734 map_iterator.advance ())
736 if (map_entry->int_id_.value ().strstr (pattern) != -1)
738 ACE_Name_Binding entry (map_entry->ext_id_,
739 map_entry->int_id_.value (),
740 map_entry->int_id_.type ());
742 if (set.insert (entry) == -1)
743 return -1;
746 return 0;
749 template <ACE_MEM_POOL_1, class ACE_LOCK> int
750 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_type_entries_i (
751 ACE_BINDING_SET &set,
752 const ACE_NS_WString &pattern)
754 ACE_TRACE ("ACE_Local_Name_Space::list_type_entries_i");
755 ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
757 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
758 MAP_MANAGER::ENTRY *map_entry;
760 char *compiled_regexp = 0;
761 // Note that char_rep() allocates memory so we need to delete it
762 char *pattern_rep = pattern.char_rep ();
764 // Check for wildcard case first.
765 if (ACE_OS::strcmp ("", pattern_rep) == 0)
766 compiled_regexp = ACE_OS::strdup ("");
767 else
768 // Compile the regular expression (the 0's cause ACE_OS::compile
769 // to allocate space).
770 #if defined (ACE_HAS_REGEX)
771 compiled_regexp = ACE_OS::compile (pattern_rep, 0, 0);
772 #else /* If we don't have regular expressions just the pattern
773 directly. */
774 compiled_regexp = pattern_rep;
775 #endif /* ACE_HAS_REGEX */
777 for (map_entry = 0;
778 map_iterator.next (map_entry) != 0;
779 map_iterator.advance ())
781 // Get the type.
782 const char *type = map_entry->int_id_.type ();
784 if (ACE_OS::strcmp ("", pattern_rep) == 0 // Everything matches
785 // the wildcard.
786 #if defined (ACE_HAS_REGEX)
787 || ACE_OS::step (type, compiled_regexp) != 0)
788 #else /* If we don't have regular expressions just use strstr() for
789 substring matching. */
790 || ACE_OS::strstr (type, compiled_regexp) != 0)
791 #endif /* ACE_HAS_REGEX */
793 ACE_Name_Binding entry (map_entry->ext_id_,
794 map_entry->int_id_.value (),
795 map_entry->int_id_.type ());
797 if (set.insert (entry) == -1)
798 return -1;
801 #if defined (ACE_HAS_REGEX)
802 if (compiled_regexp)
803 ACE_OS::free ((void *) compiled_regexp);
804 #endif /* ACE_HAS_REGEX */
805 #if defined (ACE_HAS_ALLOC_HOOKS)
806 ACE_Allocator::instance()->free(pattern_rep);
807 #else
808 delete [] pattern_rep; // delete pattern_rep;
809 #endif /* ACE_HAS_ALLOC_HOOKS */
810 return 0;
813 template <ACE_MEM_POOL_1, class ACE_LOCK> void
814 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::dump_i (void) const
816 ACE_TRACE ("ACE_Local_Name_Space::dump_i");
818 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
820 MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
821 MAP_MANAGER::ENTRY *map_entry;
823 for (map_entry = 0;
824 map_iterator.next (map_entry) != 0;
825 map_iterator.advance())
827 char *key = map_entry->ext_id_.char_rep ();
828 char *value = map_entry->int_id_.value ().char_rep ();
829 #if !defined (ACE_NLOGGING)
830 const char *type = map_entry->int_id_.type ();
831 #endif /* ! ACE_NLOGGING */
833 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("key=%C\nvalue=%C\ntype=%C\n"),
834 key, value, type));
835 // We need to delete key and value since char_rep allocates
836 // memory for them
837 #if defined (ACE_HAS_ALLOC_HOOKS)
838 ACE_Allocator::instance()->free(key);
839 ACE_Allocator::instance()->free(value);
840 #else
841 delete [] key;
842 delete [] value;
843 #endif /* ACE_HAS_ALLOC_HOOKS */
846 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
849 template <ACE_MEM_POOL_1, class ACE_LOCK> int
850 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_names (
851 ACE_WSTRING_SET &set,
852 const ACE_NS_WString &pattern)
854 // Note that we *must* use structured exception handling here
855 // because (1) we may need to commit virtual memory pages and (2)
856 // C++ exception handling doesn't support resumption.
857 int result = 0;
858 ACE_SEH_TRY
860 result = this->list_names_i (set, pattern);
862 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
865 return result;
868 template <ACE_MEM_POOL_1, class ACE_LOCK> int
869 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_values (
870 ACE_WSTRING_SET &set,
871 const ACE_NS_WString &pattern)
873 // Note that we *must* use structured exception handling here
874 // because (1) we may need to commit virtual memory pages and (2)
875 // C++ exception handling doesn't support resumption.
876 int result = 0;
877 ACE_SEH_TRY
879 result = this->list_values_i (set, pattern);
881 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
884 return result;
887 template <ACE_MEM_POOL_1, class ACE_LOCK> int
888 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_types (
889 ACE_WSTRING_SET &set,
890 const ACE_NS_WString &pattern)
892 // Note that we *must* use structured exception handling here
893 // because (1) we may need to commit virtual memory pages and (2)
894 // C++ exception handling doesn't support resumption.
895 int result = 0;
896 ACE_SEH_TRY
898 result = this->list_types_i (set, pattern);
900 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
903 return result;
906 template <ACE_MEM_POOL_1, class ACE_LOCK> int
907 ACE_Local_Name_Space <ACE_MEM_POOL_2, ACE_LOCK>::list_name_entries (
908 ACE_BINDING_SET &set,
909 const ACE_NS_WString &pattern)
911 // Note that we *must* use structured exception handling here
912 // because (1) we may need to commit virtual memory pages and (2)
913 // C++ exception handling doesn't support resumption.
914 int result = 0;
915 ACE_SEH_TRY
917 result = this->list_name_entries_i (set, pattern);
919 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
922 return result;
925 template <ACE_MEM_POOL_1, class ACE_LOCK> int
926 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_value_entries (
927 ACE_BINDING_SET &set,
928 const ACE_NS_WString &pattern)
930 // Note that we *must* use structured exception handling here
931 // because (1) we may need to commit virtual memory pages and (2)
932 // C++ exception handling doesn't support resumption.
933 int result = 0;
934 ACE_SEH_TRY
936 result = this->list_value_entries_i (set, pattern);
938 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
941 return result;
944 template <ACE_MEM_POOL_1, class ACE_LOCK> int
945 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_type_entries (
946 ACE_BINDING_SET &set,
947 const ACE_NS_WString &pattern)
949 // Note that we *must* use structured exception handling here
950 // because (1) we may need to commit virtual memory pages and (2)
951 // C++ exception handling doesn't support resumption.
952 int result = 0;
953 ACE_SEH_TRY
955 result = this->list_type_entries_i (set, pattern);
957 ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
960 return result;
963 template <ACE_MEM_POOL_1, class ACE_LOCK> void
964 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::dump (void) const
966 #if defined (ACE_HAS_DUMP)
967 // Note that we *must* use structured exception handling here
968 // because (1) we may need to commit virtual memory pages and (2)
969 // C++ exception handling doesn't support resumption.
971 // This should really be a const cast
972 ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK> *fake_this =
973 (ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK> *) this;
974 ACE_UNUSED_ARG (fake_this);
976 ACE_SEH_TRY
978 this->dump_i ();
980 ACE_SEH_EXCEPT (fake_this->remap (GetExceptionInformation ()))
983 #endif /* ACE_HAS_DUMP */
986 ACE_END_VERSIONED_NAMESPACE_DECL
988 #endif /* ACE_LOCAL_NAME_SPACE_T_CPP */