summaryrefslogtreecommitdiff
path: root/ACE/ace/Local_Name_Space_T.cpp
blob: cfe9c762e12d6f7f3fb5170887c57c847dc0a32d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
// $Id$

#ifndef ACE_LOCAL_NAME_SPACE_T_CPP
#define ACE_LOCAL_NAME_SPACE_T_CPP

#include "ace/ACE.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Local_Name_Space.h"
#include "ace/Auto_Ptr.h"
#include "ace/Guard_T.h"
#include "ace/OS_NS_regex.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_unistd.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

template <class ALLOCATOR>
ACE_Name_Space_Map<ALLOCATOR>::ACE_Name_Space_Map (ALLOCATOR *alloc)
  : MAP_MANAGER (alloc)
{
  ACE_TRACE ("ACE_Name_Space_Map::ACE_Name_Space_Map");
}

template <class ALLOCATOR> int
ACE_Name_Space_Map<ALLOCATOR>::close (ALLOCATOR *alloc)
{
  ACE_TRACE ("ACE_Name_Space_Map::close");

  this->table_allocator_ = alloc;
  this->entry_allocator_ = alloc;
  return this->close_i ();
}

template <class ALLOCATOR> int
ACE_Name_Space_Map<ALLOCATOR>::bind (const ACE_NS_String &ext_id,
                                     const ACE_NS_Internal &int_id,
                                     ALLOCATOR *alloc)
{
  ACE_TRACE ("ACE_Name_Space_Map::bind");

  this->table_allocator_ = alloc;
  this->entry_allocator_ = alloc;
  return this->bind_i (ext_id, int_id);
}

template <class ALLOCATOR> int
ACE_Name_Space_Map<ALLOCATOR>::unbind (const ACE_NS_String &ext_id,
                                       ACE_NS_Internal &int_id,
                                       ALLOCATOR *alloc)
{
  ACE_TRACE ("ACE_Name_Space_Map::unbind");

  this->table_allocator_ = alloc;
  this->entry_allocator_ = alloc;
  return this->unbind_i (ext_id, int_id);
}

template <class ALLOCATOR> int
ACE_Name_Space_Map<ALLOCATOR>::rebind (const ACE_NS_String &ext_id,
                                       const ACE_NS_Internal &int_id,
                                       ACE_NS_String &old_ext_id,
                                       ACE_NS_Internal &old_int_id,
                                       ALLOCATOR *alloc)
{
  ACE_TRACE ("ACE_Name_Space_Map::rebind");

  this->table_allocator_ = alloc;
  this->entry_allocator_ = alloc;
  return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id);
}

template <class ALLOCATOR> int
ACE_Name_Space_Map<ALLOCATOR>::find (const ACE_NS_String &ext_id,
                                     ACE_NS_Internal &int_id,
                                     ALLOCATOR *alloc)
{
  ACE_TRACE ("ACE_Name_Space_Map::find");

  this->table_allocator_ = alloc;
  this->entry_allocator_ = alloc;
  return this->find_i (ext_id, int_id);
}

#if defined (ACE_WIN32)
template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::remap (EXCEPTION_POINTERS *ep)
{
  ACE_TRACE ("ACE_Local_Name_Space::remap");

  void *addr = (void *) ep->ExceptionRecord->ExceptionInformation[1];

  // The following requires Memory Pool to have ::remap()
  // defined. Thus currently this will only work for
  // ACE_MMap_Memory_Pool.
  if (this->allocator_->alloc ().memory_pool ().remap (addr) == -1)
    // Kick it upstairs...
    return EXCEPTION_CONTINUE_SEARCH;

#if __X86__
  // This is 80x86-specific.
  ep->ContextRecord->Edi = (DWORD) addr;
#elif __MIPS__
  ep->ContextRecord->IntA0 =
    ep->ContextRecord->IntV0 = (DWORD) addr;
  ep->ContextRecord->IntT5 = ep->ContextRecord->IntA0 + 3;
#endif /* __X86__ */
    // Resume execution at the original point of "failure."
  return EXCEPTION_CONTINUE_EXECUTION;
}
#endif /* ACE_WIN32 */

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::shared_bind (
  const ACE_NS_WString &name,
  const ACE_NS_WString &value,
  const char *type,
  int rebind)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->shared_bind_i (name, value, type, rebind);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::shared_bind_i (
  const ACE_NS_WString &name,
  const ACE_NS_WString &value,
  const char *type,
  int rebind)
{

  ACE_TRACE ("ACE_Local_Name_Space::shared_bind_i");
  const size_t name_len = (name.length () + 1) * sizeof (ACE_WCHAR_T);
  const size_t value_len = (value.length () + 1) * sizeof (ACE_WCHAR_T);
  const size_t type_len = ACE_OS::strlen (type) + 1;
  const size_t total_len = name_len + value_len + type_len;
  char *ptr = (char *) this->allocator_->malloc (total_len);

  if (ptr == 0)
    return -1;
  else
    {
      // Note that the value_rep *must* come first to make sure we can
      // retrieve this pointer later on in unbind().
      ACE_WCHAR_T *value_rep = (ACE_WCHAR_T *) (ptr);
      ACE_WCHAR_T *name_rep = (ACE_WCHAR_T *) (ptr + value_len);
      char *new_type = (char *) (ptr + value_len + name_len);

      ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> name_urep (name.rep ());
      ACE_Auto_Basic_Array_Ptr<ACE_WCHAR_T> value_urep (value.rep ());
      ACE_NS_String new_name (name_rep, name_urep.get (), name_len);
      ACE_NS_String new_value (value_rep, value_urep.get (), value_len);

      ACE_OS::strcpy (new_type, type);
      ACE_NS_Internal new_internal (new_value, new_type);
      int result = -1;

      if (rebind == 0)
        {
          // Do a normal bind.  This will fail if there's already an
          // <new_internal> with the same name.
          result = this->name_space_map_->bind (new_name,
                                                new_internal,
                                                this->allocator_);

          if (result == 1)
            {
              // Entry already existed so bind failed. Free our
              // dynamically allocated memory.
              this->allocator_->free ((void *) ptr);
              return result;
            }
        }
      else
        {
          // Do a rebind.  If there's already any entry, this will
          // return the existing <new_name> and <new_internal> and
          // overwrite the existing name binding.
          ACE_NS_String old_name;
          ACE_NS_Internal old_internal;

          result = this->name_space_map_->rebind (new_name, new_internal,
                                                  old_name, old_internal,
                                                  this->allocator_);
          if (result == 1)
            {
              // Free up the memory we allocated in shared_bind().
              // Note that this assumes that the "value" pointer comes
              // first and that the value, name, and type are
              // contiguously allocated (see above for details)
              this->allocator_->free ((void *) (old_internal.value ()).fast_rep ());
            }
        }

      if (result == -1)
        // Free our dynamically allocated memory.
        this->allocator_->free ((void *) ptr);
      else
        // If bind() or rebind() succeed, they will automatically sync
        // up the map manager entry.  However, we must sync up our
        // name/value memory.
        this->allocator_->sync (ptr, total_len);

      return result;
    }
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::unbind (
  const ACE_NS_WString &name)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->unbind_i (name);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;

}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::unbind_i (
  const ACE_NS_WString &name)
{
  ACE_TRACE ("ACE_Local_Name_Space::unbind_i");

  ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);
  ACE_NS_String ns_name (name);
  ACE_NS_Internal ns_internal;
  if (this->name_space_map_->unbind (ns_name,
                                     ns_internal,
                                     this->allocator_) != 0)
    return -1;

  // Free up the memory we allocated in shared_bind().  Note that this
  // assumes that the "value" pointer comes first and that the value,
  // name and type are contiguously allocated (see shared_bind() for
  // details)
  this->allocator_->free ((void *) (ns_internal.value ()).fast_rep ());
  return 0;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::bind (
  const ACE_NS_WString &name,
  const ACE_NS_WString &value,
  const char *type)
{
  ACE_TRACE ("ACE_Local_Name_Space::bind");
  ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  return this->shared_bind (name, value, type, 0);
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::rebind (
  const ACE_NS_WString &name,
  const ACE_NS_WString &value,
  const char *type)
{
  ACE_TRACE ("ACE_Local_Name_Space::rebind");
  ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  return this->shared_bind (name, value, type, 1);
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::resolve (
  const ACE_NS_WString &name,
  ACE_NS_WString &value,
  char *&type)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->resolve_i (name, value, type);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}


template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::resolve_i (
  const ACE_NS_WString &name,
  ACE_NS_WString &value,
  char *&type)
{
  ACE_TRACE ("ACE_Local_Name_Space::resolve_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  ACE_NS_String ns_name (name);
  ACE_NS_Internal ns_internal;
  ACE_NS_String nbc_string; // Note the classy variable name! :)

  if (this->name_space_map_->find (ns_name,
                                   ns_internal,
                                   this->allocator_) != 0)
    return -1;

  // Calls conversion operator and then calls the ACE_NS_WString
  // assignment operator to get a fresh copy.  (*#*(@#&!*@!!*@&( HP
  // compiler causes us to add an extra copy explicitly !! :)
  nbc_string = ns_internal.value ();
  value = nbc_string;

  // Gets type and then the actual reprsentation which is a
  // ACE_WCHAR_T
  const char *temp = ns_internal.type ();

  size_t len = ACE_OS::strlen (ns_internal.type ());
  // Makes a copy here. Caller needs to call delete to free up
  // memory.
  char *new_type = 0;
  ACE_NEW_RETURN (new_type,
                  char [len + 1],
                  -1);

  ACE_OS::strsncpy (new_type, temp, len + 1);
  type = new_type;
  return 0;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::open (
  ACE_Naming_Context::Context_Scope_Type scope_in)
{
  ACE_TRACE ("ACE_Local_Name_Space::open");
  this->ns_scope_ = scope_in;

  return this->create_manager ();
}

template <ACE_MEM_POOL_1, class ACE_LOCK>
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Local_Name_Space (void)
  : allocator_ (0),
    name_space_map_ (0),
    name_options_ (0)
{
  ACE_TRACE ("ACE_Local_Name_Space::ACE_Local_Name_Space");
}

template <ACE_MEM_POOL_1, class ACE_LOCK>
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::ACE_Local_Name_Space (
  ACE_Naming_Context::Context_Scope_Type scope_in,
  ACE_Name_Options *name_options)
  : name_options_ (name_options)
{
  ACE_TRACE ("ACE_Local_Name_Space::ACE_Local_Name_Space");
  if (this->open (scope_in) == -1)
    ACE_ERROR ((LM_ERROR,  ACE_TEXT ("%p\n"),  ACE_TEXT ("ACE_Local_Name_Space::ACE_Local_Name_Space")));
}

template <ACE_MEM_POOL_1, class ACE_LOCK>
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::~ACE_Local_Name_Space (void)
{
  ACE_TRACE ("ACE_Local_Name_Space::~ACE_Local_Name_Space");

  // Remove the map.
  delete this->allocator_;
  delete this->lock_;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::create_manager (void)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->create_manager_i ();
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}


template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::create_manager_i (void)
{
  ACE_TRACE ("ACE_Local_Name_Space::create_manager_i");
  // Get directory name
  const ACE_TCHAR *dir = this->name_options_->namespace_dir ();
  const ACE_TCHAR *database = this->name_options_->database ();

  // Use process name as the file name.
  size_t len = ACE_OS::strlen (dir);
  len += ACE_OS::strlen (ACE_DIRECTORY_SEPARATOR_STR);
  len += ACE_OS::strlen (database) + 1;

  if (len >= MAXNAMELEN + MAXPATHLEN)
    {
      errno = ENAMETOOLONG;
      return -1;
    }

  ACE_OS::strcpy (this->context_file_, dir);
  ACE_OS::strcat (this->context_file_, ACE_DIRECTORY_SEPARATOR_STR);
  ACE_OS::strcat (this->context_file_, database);

  ACE_MEM_POOL_OPTIONS options (this->name_options_->base_address ());

  ACE_TCHAR lock_name_for_local_name_space [MAXNAMELEN + MAXPATHLEN];
  ACE_TCHAR lock_name_for_backing_store [MAXPATHLEN + MAXNAMELEN];
  const ACE_TCHAR *postfix = database;

  size_t length = 0;
  length = sizeof lock_name_for_local_name_space / sizeof (ACE_TCHAR);
  ACE_OS::strsncpy (lock_name_for_local_name_space,
                    dir,
                    length);

  ACE_OS::strncat (lock_name_for_local_name_space,
                   ACE_DIRECTORY_SEPARATOR_STR,
                   length -  ACE_OS::strlen (lock_name_for_local_name_space));
  ACE_OS::strncat (lock_name_for_local_name_space,
                   ACE_TEXT ("name_space_"),
                   length -  ACE_OS::strlen (lock_name_for_local_name_space));
  ACE_OS::strncat (lock_name_for_local_name_space,
                   postfix,
                   length -  ACE_OS::strlen (lock_name_for_local_name_space));

  length = sizeof lock_name_for_backing_store / sizeof (ACE_TCHAR);
  ACE_OS::strsncpy (lock_name_for_backing_store,
                    dir,
                    length);
  ACE_OS::strncat (lock_name_for_backing_store,
                   ACE_DIRECTORY_SEPARATOR_STR,
                   length -  ACE_OS::strlen (lock_name_for_backing_store));
  ACE_OS::strncat (lock_name_for_backing_store,
                   ACE_TEXT ("backing_store_"),
                   length -  ACE_OS::strlen (lock_name_for_backing_store));
  ACE_OS::strncat (lock_name_for_backing_store,
                   postfix,
                   length - ACE_OS::strlen (ACE_TEXT ("backing_store_")));

  // Create the allocator with the appropriate options.
  ACE_NEW_RETURN (this->allocator_,
                  ALLOCATOR (this->context_file_,
                             lock_name_for_backing_store,
                             &options), -1);

  if (ACE_LOG_MSG->op_status ())
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("Allocator::Allocator\n")),
                      -1);

  ACE_NEW_RETURN (this->lock_,
                  ACE_LOCK (lock_name_for_local_name_space),
                  -1);

#if !defined (ACE_LACKS_ACCESS)
  // Now check if the backing store has been created successfully
  if (ACE_OS::access (this->context_file_, F_OK) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT ("create_manager\n")),
                      -1);
#endif /* ACE_LACKS_ACCESS */

  void *ns_map = 0;

  // This is the easy case since if we find the Name Server Map
  // Manager we know it's already initialized.
  if (this->allocator_->find (ACE_NAME_SERVER_MAP, ns_map) == 0)
    {
      this->name_space_map_ = (ACE_Name_Space_Map <ALLOCATOR> *) ns_map;
      if (ACE::debug ())
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("name_space_map_ = %@, ns_map = %@\n"),
                    this->name_space_map_, ns_map));
    }

  // This is the hard part since we have to avoid potential race
  // conditions...  We will use the double check here
  else
    {
      ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

      // This is the easy case since if we find the Name Server Map
      // Manager we know it's already initialized.
      if (this->allocator_->find (ACE_NAME_SERVER_MAP, ns_map) == 0)
        {
          this->name_space_map_ = (ACE_Name_Space_Map <ALLOCATOR> *) ns_map;
          if (ACE::debug ())
            ACE_DEBUG ((LM_DEBUG,
                        ACE_TEXT ("name_space_map_ = %@, ns_map = %@\n"),
                        this->name_space_map_, ns_map));
        }
      else
        {
          size_t map_size = sizeof *this->name_space_map_;
          ns_map = this->allocator_->malloc (map_size);

          // Initialize the map into its memory location (e.g., shared memory).
          this->name_space_map_ =
            new (ns_map) ACE_Name_Space_Map <ALLOCATOR> (this->allocator_);

          if (this->allocator_->bind (ACE_NAME_SERVER_MAP, ns_map) == -1)
            ACE_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT ("create_manager\n")), -1);
        }

      if (ACE::debug ())
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("name_space_map_ = %@, ns_map = %@\n"),
                    this->name_space_map_, ns_map));
    }

  return 0;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_names_i (
  ACE_WSTRING_SET &set,
  const ACE_NS_WString &pattern)
{
  ACE_TRACE ("ACE_Local_Name_Space::list_names_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  int result = 1;

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance())
    {
      if (map_entry->ext_id_.strstr (pattern) != -1)
        {
          ACE_NS_WString entry (map_entry->ext_id_ );

          if (set.insert (entry) == -1)
            {
              result = -1;
              break;
            }
          else
            result = 0;
        }
    }

  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_values_i (
  ACE_WSTRING_SET &set,
  const ACE_NS_WString &pattern)
{
  ACE_TRACE ("ACE_Local_Name_Space::list_values_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  int result = 1;

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance ())
    {
      if (map_entry->int_id_.value ().strstr (pattern) != -1)
        {
          ACE_NS_WString entry (map_entry->int_id_.value ());

          if (set.insert (entry) == -1)
            {
              result = -1;
              break;
            }
          else
            result = 0;
        }
    }

  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_types_i (
  ACE_WSTRING_SET &set,
  const ACE_NS_WString &pattern)
{
  ACE_TRACE ("ACE_Local_Name_Space::list_types_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  char *compiled_regexp = 0;

  // Note that char_rep() allocates memory so we need to delete it
  char *pattern_rep = pattern.char_rep ();

  // Check for wildcard case first.
  if (ACE_OS::strcmp ("", pattern_rep) == 0)
    ACE_ALLOCATOR_RETURN (compiled_regexp,
                          ACE_OS::strdup (""),
                          -1);
  else
    // Compile the regular expression (the 0's cause ACE_OS::compile
    // to allocate space).
#if defined (ACE_HAS_REGEX)
    compiled_regexp = ACE_OS::compile (pattern_rep, 0, 0);
#else
  // If we don't have regular expressions just use the pattern
  // directly.
  compiled_regexp = pattern_rep;
#endif /* ACE_HAS_REGEX */

  int result = 1;

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance ())
    {
      // Get the type
      const char *type = map_entry->int_id_.type ();

      // Everything matches the wildcard.
      if (ACE_OS::strcmp ("", pattern_rep) == 0
#if defined (ACE_HAS_REGEX)
          || ACE_OS::step (type, compiled_regexp) != 0)
#else
        // If we don't have regular expressions just use strstr() for
        // substring matching.
        || ACE_OS::strstr (type, compiled_regexp) != 0)
#endif /* ACE_HAS_REGEX */

        {
          ACE_NS_WString entry (type);

          if (set.insert (entry) == -1)
            {
              result = -1;
              break;
            }
          else
            result = 0;
        }
    }
#if defined (ACE_HAS_REGEX)
  if (compiled_regexp)
    ACE_OS::free ((void *) compiled_regexp);
#endif /* ACE_HAS_REGEX */
  delete [] pattern_rep;  // delete pattern_rep;
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space <ACE_MEM_POOL_2, ACE_LOCK>::list_name_entries_i (
  ACE_BINDING_SET &set,
  const ACE_NS_WString &pattern)
{
  ACE_TRACE ("ACE_Local_Name_Space::list_name_entries_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance())
    {
      if (map_entry->ext_id_.strstr (pattern) != -1)
        {
          ACE_Name_Binding entry (map_entry->ext_id_,
                                  map_entry->int_id_.value (),
                                  map_entry->int_id_.type ());

          if (set.insert (entry) == -1)
            return -1;
        }
    }

  return 0;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_value_entries_i (
  ACE_BINDING_SET &set,
  const ACE_NS_WString &pattern)
{
  ACE_TRACE ("ACE_Local_Name_Space::list_value_entries_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance ())
    {
      if (map_entry->int_id_.value ().strstr (pattern) != -1)
        {
          ACE_Name_Binding entry (map_entry->ext_id_,
                                  map_entry->int_id_.value (),
                                  map_entry->int_id_.type ());

          if (set.insert (entry) == -1)
            return -1;
        }
    }
  return 0;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_type_entries_i (
  ACE_BINDING_SET &set,
  const ACE_NS_WString &pattern)
{
  ACE_TRACE ("ACE_Local_Name_Space::list_type_entries_i");
  ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, *this->lock_, -1);

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  char *compiled_regexp = 0;
  // Note that char_rep() allocates memory so we need to delete it
  char *pattern_rep = pattern.char_rep ();

  // Check for wildcard case first.
  if (ACE_OS::strcmp ("", pattern_rep) == 0)
    compiled_regexp = ACE_OS::strdup ("");
  else
    // Compile the regular expression (the 0's cause ACE_OS::compile
    // to allocate space).
#if defined (ACE_HAS_REGEX)
    compiled_regexp = ACE_OS::compile (pattern_rep, 0, 0);
#else /* If we don't have regular expressions just the pattern
         directly. */
  compiled_regexp = pattern_rep;
#endif /* ACE_HAS_REGEX */

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance ())
    {
      // Get the type.
      const char *type = map_entry->int_id_.type ();

      if (ACE_OS::strcmp ("", pattern_rep) == 0 // Everything matches
                                                // the wildcard.
#if defined (ACE_HAS_REGEX)
          || ACE_OS::step (type, compiled_regexp) != 0)
#else /* If we don't have regular expressions just use strstr() for
         substring matching. */
        || ACE_OS::strstr (type, compiled_regexp) != 0)
#endif /* ACE_HAS_REGEX */
        {
          ACE_Name_Binding entry (map_entry->ext_id_,
                                  map_entry->int_id_.value (),
                                  map_entry->int_id_.type ());

          if (set.insert (entry) == -1)
            return -1;
        }
    }
#if defined (ACE_HAS_REGEX)
  if (compiled_regexp)
    ACE_OS::free ((void *) compiled_regexp);
#endif /* ACE_HAS_REGEX */
  delete [] pattern_rep;  // delete pattern_rep;
  return 0;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> void
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::dump_i (void) const
{
  ACE_TRACE ("ACE_Local_Name_Space::dump_i");

  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));

  MAP_MANAGER::ITERATOR map_iterator (*this->name_space_map_);
  MAP_MANAGER::ENTRY *map_entry;

  for (map_entry = 0;
       map_iterator.next (map_entry) != 0;
       map_iterator.advance())
    {
      char *key = map_entry->ext_id_.char_rep ();
      char *value = map_entry->int_id_.value ().char_rep ();
#if !defined (ACE_NLOGGING)
      const char *type = map_entry->int_id_.type ();
#endif /* ! ACE_NLOGGING */

      ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("key=%C\nvalue=%C\ntype=%C\n"),
                  key, value, type));
      // We need to delete key and value since char_rep allocates
      // memory for them
      delete [] key;
      delete [] value;
    }

  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_names (
  ACE_WSTRING_SET &set,
  const ACE_NS_WString &pattern)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->list_names_i (set, pattern);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_values (
  ACE_WSTRING_SET &set,
  const ACE_NS_WString &pattern)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->list_values_i (set, pattern);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_types (
  ACE_WSTRING_SET &set,
  const ACE_NS_WString &pattern)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->list_types_i (set, pattern);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space <ACE_MEM_POOL_2, ACE_LOCK>::list_name_entries (
  ACE_BINDING_SET &set,
  const ACE_NS_WString &pattern)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->list_name_entries_i (set, pattern);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_value_entries (
  ACE_BINDING_SET &set,
  const ACE_NS_WString &pattern)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->list_value_entries_i (set, pattern);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> int
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::list_type_entries (
  ACE_BINDING_SET &set,
  const ACE_NS_WString &pattern)
{
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.
  int result = 0;
  ACE_SEH_TRY
    {
      result = this->list_type_entries_i (set, pattern);
    }
  ACE_SEH_EXCEPT (this->remap (GetExceptionInformation ()))
    {
    }
  return result;
}

template <ACE_MEM_POOL_1, class ACE_LOCK> void
ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK>::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  // Note that we *must* use structured exception handling here
  // because (1) we may need to commit virtual memory pages and (2)
  // C++ exception handling doesn't support resumption.

  // This should really be a const cast
  ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK> *fake_this =
    (ACE_Local_Name_Space<ACE_MEM_POOL_2, ACE_LOCK> *) this;
  ACE_UNUSED_ARG (fake_this);

  ACE_SEH_TRY
    {
      this->dump_i ();
    }
  ACE_SEH_EXCEPT (fake_this->remap (GetExceptionInformation ()))
    {
    }
#endif /* ACE_HAS_DUMP */
}

ACE_END_VERSIONED_NAMESPACE_DECL

#endif /* ACE_LOCAL_NAME_SPACE_T_CPP */