summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp
blob: 330d39840068f74975011fe2462d6192fd05891c (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
// -*- C++ -*-
// $Id$

#include "orbsvcs/PortableGroup/PG_FactoryRegistry.h"

#include "ace/Get_Opt.h"
#include "ace/Vector_T.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Auto_Ptr.h"
#include "tao/debug.h"
#include "tao/ORB_Constants.h"
#include "tao/PortableServer/POAManagerC.h"
#include "orbsvcs/PortableGroup/PG_Operators.h" // operator == on CosNaming::Name

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

// Use this macro at the beginning of CORBA methods
// to aid in debugging.
#define METHOD_ENTRY(name)            \
  if (TAO_debug_level <= 6){} else    \
    ACE_DEBUG (( LM_DEBUG,            \
    "Enter %s\n", #name               \
      ))

// Use this macro to return from CORBA methods
// to aid in debugging.  Note that you can specify
// the return value after the macro, for example:
// METHOD_RETURN(Plugh::plover) xyzzy; is equivalent
// to return xyzzy;
// METHOD_RETURN(Plugh::troll); is equivalent to
// return;
// WARNING: THIS GENERATES TWO STATEMENTS!!! THE FOLLOWING
// will not do what you want it to:
//  if (cave_is_closing) METHOD_RETURN(Plugh::pirate) aarrggh;
// Moral:  Always use braces.
#define METHOD_RETURN(name)           \
  if (TAO_debug_level <= 6){} else    \
    ACE_DEBUG (( LM_DEBUG,            \
      "Leave %s\n", #name             \
      ));                             \
  return /* value goes here */

TAO::PG_FactoryRegistry::PG_FactoryRegistry (const char * name)
  : identity_(name)
  , orb_ (0)
  , poa_ (0)
  , object_id_ (0)
  , this_obj_ (0)
  , ior_output_file_(0)
  , ns_name_(0)
  , naming_context_(0)
  , this_name_(1)
  , quit_on_idle_(0)
  , quit_state_(LIVE)
  , linger_(0)
{
}

TAO::PG_FactoryRegistry::~PG_FactoryRegistry (void)
{
}

//////////////////////////////////////////////////////
// PG_FactoryRegistry public, non-CORBA methods

int TAO::PG_FactoryRegistry::parse_args (int argc, char * argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "o:n:q");
  int c;

  while ((c = get_opts ()) != -1)
  {
    switch (c)
    {
      case 'o':
      {
        this->ior_output_file_ = get_opts.opt_arg ();
        break;
      }
      case 'n':
      {
        this->ns_name_ = get_opts.opt_arg();
        break;
      }
      case 'q':
      {
        this->quit_on_idle_ = 1;
        break;
      }

      case '?':
        // fall thru
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s"
                           " -o <registry ior file>"
                           " -n <name to use to register with name service>"
                           " -q{uit on idle}"
                           "\n",
                           argv [0]),
                          -1);
      break;
    }
  }
  // Indicates sucessful parsing of the command line
  return 0;
}

const char * TAO::PG_FactoryRegistry::identity () const
{
  return this->identity_.c_str();
}

void TAO::PG_FactoryRegistry::_remove_ref (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
{
  this->quit_state_ = GONE;
}

int TAO::PG_FactoryRegistry::idle (int & result ACE_ENV_ARG_DECL_NOT_USED)
{
  result = 0;
  int quit = 0;
  if (this->quit_state_ == GONE)
  {
    if (linger_ < 2)
    {
      ++linger_;
    }
    else
    {
      quit = 1;
    }
  }
  return quit;
}


int TAO::PG_FactoryRegistry::fini (ACE_ENV_SINGLE_ARG_DECL)
{
  if (this->ior_output_file_ != 0)
  {
    ACE_OS::unlink (this->ior_output_file_);
    this->ior_output_file_ = 0;
  }
  if (this->ns_name_ != 0)
  {
    this->naming_context_->unbind (this_name_
                            ACE_ENV_ARG_PARAMETER);
    this->ns_name_ = 0;
  }
  return 0;
}


void TAO::PG_FactoryRegistry::init (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa ACE_ENV_ARG_DECL)
{
  ACE_ASSERT (CORBA::is_nil (this->orb_.in ()));
  ACE_ASSERT (CORBA::is_nil (this->poa_.in ()));
  this->orb_ = CORBA::ORB::_duplicate (orb);
  this->poa_ = PortableServer::POA::_duplicate (poa);
  ACE_ASSERT ( ! CORBA::is_nil (this->orb_.in ()));
  ACE_ASSERT ( ! CORBA::is_nil (this->poa_.in ()));

  // Register with the POA.
  this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // find my identity as a corba object
  this->this_obj_ =
    this->poa_->id_to_reference (object_id_.in ()
                                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // and create a ior string
  this->ior_ = this->orb_->object_to_string (this->this_obj_.in ()
                                  ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

}

int TAO::PG_FactoryRegistry::init (CORBA::ORB_ptr orb
                                   ACE_ENV_ARG_DECL)
{
  int result = 0;

  this->orb_ = CORBA::ORB::_duplicate (orb);

  // Use the ROOT POA for now
  CORBA::Object_var poa_object =
    this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA
                                            ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (CORBA::is_nil (poa_object.in ()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
                      -1);

  // Get the POA object.
  this->poa_ =
    PortableServer::POA::_narrow (poa_object.in ()
                                  ACE_ENV_ARG_PARAMETER);

  ACE_CHECK_RETURN (-1);

  if (CORBA::is_nil (this->poa_.in()))
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
                      -1);
  }

  PortableServer::POAManager_var poa_manager =
    this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  // Register with the POA.
  this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  // find my identity as a corba object
  this->this_obj_ =
    this->poa_->id_to_reference (object_id_.in ()
                                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);


  // and create a ior string
  this->ior_ = this->orb_->object_to_string (this->this_obj_.in ()
                                  ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);


  if (this->ior_output_file_ != 0)
  {
    this->identity_ = "file:";
    this->identity_ += this->ior_output_file_;
    result = write_ior_file (this->ior_output_file_,
                             this->ior_.in ());
  }

  if (this->ns_name_ != 0)
  {
    this->identity_ = "name:";
    this->identity_ += this->ns_name_;

    CORBA::Object_var naming_obj =
      this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN(-1);

    if (CORBA::is_nil(naming_obj.in ())){
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%T %n (%P|%t) Unable to find the Naming Service\n"),
                        1);
    }

    this->naming_context_ =
      CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN(-1);

    this->this_name_.length (1);
    this->this_name_[0].id = CORBA::string_dup (this->ns_name_);

    this->naming_context_->rebind (this->this_name_, this->this_obj_.in()  //CORBA::Object::_duplicate(this_obj)
                            ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN(-1);
  }

  return result;
}


::PortableGroup::FactoryRegistry_ptr TAO::PG_FactoryRegistry::reference()
{
  // narrow and duplicate
  return ::PortableGroup::FactoryRegistry::_narrow(this->this_obj_.in ());
}


//////////////////////////////////////////
// PG_FactoryRegistry CORBA methods

/* Reference:info
  typedef CosNaming::Name Name;
  typedef Name Location;
  struct FactoryInfo {
    GenericFactory the_factory;
    Location the_location;
    Criteria the_criteria;
  };
  typedef sequence<FactoryInfo> FactoryInfos;
*/

TAO::PG_FactoryRegistry::RoleInfo::RoleInfo(size_t estimated_number_entries)
  : infos_(estimated_number_entries)
{
}


void TAO::PG_FactoryRegistry::register_factory (
    const char * role,
    const char * type_id,
    const PortableGroup::FactoryInfo & factory_info
    ACE_ENV_ARG_DECL
  )
  ACE_THROW_SPEC ((
      CORBA::SystemException
      , PortableGroup::MemberAlreadyPresent
      , PortableGroup::TypeConflict))
{
  METHOD_ENTRY(TAO::PG_FactoryRegistry::register_factory);

  RoleInfo * role_info = 0;
  auto_ptr<RoleInfo> safe_entry;
  if (this->registry_.find(role, role_info) != 0)
    {
      ACE_DEBUG(( LM_DEBUG,
                  "%s: adding new role: %s:%s\n",
                  this->identity_.c_str(), role, type_id));

      // Note the 5.  It's a guess about the number of factories
      // that might exist for any particular role object.
      // todo: make it a parameter.
      ACE_NEW_THROW_EX (role_info,
                        RoleInfo(5),
                        CORBA::NO_MEMORY());
      ACE_CHECK;

      ACE_AUTO_PTR_RESET (safe_entry, role_info, RoleInfo);
      role_info->type_id_ = type_id;
    }
  else
    {
      if (role_info->type_id_ != type_id)
        {
          ACE_THROW ( PortableGroup::TypeConflict() );
        }
    }

  PortableGroup::FactoryInfos & infos = role_info->infos_;;
  size_t length = infos.length();
  for (size_t nInfo = 0; nInfo < length; ++nInfo)
    {
      PortableGroup::FactoryInfo & info = infos[nInfo];
      if (info.the_location == factory_info.the_location)
        {
          ACE_ERROR(( LM_ERROR,
                      "%s: Attempt to register duplicate location %s for role: %s\n" ,
                      this->identity_.c_str(),
                      static_cast<const char *> (info.the_location[0].id),
          role));
      ACE_THROW (PortableGroup::MemberAlreadyPresent() );
    }
  }

  infos.length(length + 1);
  infos[length] = factory_info;

  if (safe_entry.get() != 0)
  {
    this->registry_.bind(role, safe_entry.release());
  }

  ACE_DEBUG(( LM_DEBUG,
    "%s: Added factory: [%d] %s@%s \n",
      this->identity_.c_str(),
      static_cast<int> (length + 1),
      role,
      static_cast<const char *> (factory_info.the_location[0].id)
    ));

  METHOD_RETURN(TAO::PG_FactoryRegistry::register_factory);
}

void TAO::PG_FactoryRegistry::unregister_factory (
    const char * role,
    const PortableGroup::Location & location
    ACE_ENV_ARG_DECL
  )
  ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberNotFound))
{
  METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory);

  RoleInfo * role_info = 0;
  if (this->registry_.find(role, role_info) == 0)
  {
    PortableGroup::FactoryInfos & infos = role_info->infos_;
    int found = 0;
    size_t length = infos.length();
    for (size_t nInfo = 0; !found && nInfo < length; ++nInfo)
    {
      PortableGroup::FactoryInfo & info = infos[nInfo];
      if (info.the_location == location)
      {
        found = 1;

        ACE_ERROR(( LM_INFO,
          "%s: Unregistering  factory %s@%s\n",
            this->identity_.c_str(),
            role,
            static_cast<const char *> (location[0].id)
          ));
        if (length > 1)
        {
          // if this is not the last entry
          if (nInfo + 1 < length)
          {
            // move last entry into newly-emptied slot
            infos[nInfo] = infos[length - 1];
            nInfo = length -1;
          }
          infos.length(nInfo);
        }
        else
        {
          ACE_ASSERT ( length == 1 );
          if (this->registry_.unbind (role) == 0)
          {
            ACE_DEBUG(( LM_INFO,
              "%s: No more factories registered for %s\n",
              this->identity_.c_str(),
              role
              ));
            delete role_info;
          }
          else
          {
            ACE_ERROR ((LM_ERROR,
              "%s: LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n",
              this->identity_.c_str(),
              __LINE__));
          }
        }
      }
    }
  }
  else
  {
    ACE_ERROR(( LM_ERROR,
      "%s, Attempt to unregister factory for unknown role %s\n",
      this->identity_.c_str(),
      role
      ));
    ACE_THROW ( PortableGroup::MemberNotFound() );
  }

  //////////////////////
  // request complete
  // check quit-on-idle
  if (registry_.current_size() == 0 && quit_state_ == LIVE)
  {
    ACE_ERROR(( LM_INFO,
      "%s is idle\n",
      identity()
      ));
    if (quit_on_idle_)
    {
        this->poa_->deactivate_object (this->object_id_.in ()
               ACE_ENV_ARG_PARAMETER);
        quit_state_ = DEACTIVATED;
    }
  }

  METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory);
}

void TAO::PG_FactoryRegistry::unregister_factory_by_role (
    const char * role
    ACE_ENV_ARG_DECL
  )
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_role);

  RoleInfo * role_info = 0;
  if (this->registry_.unbind(role, role_info) == 0)
  {
    ACE_DEBUG(( LM_DEBUG,
      "%s: Unregistering all factories for role %s\n",
      this->identity_.c_str(),
      role
      ));
    // delete the entire set of factories for this location.
    delete role_info;
  }
  else
  {
    ACE_ERROR(( LM_INFO,
      "%s: Unregister_factory_by_role: unknown role: %s\n",
      this->identity_.c_str(),
      role
      ));
  }

  /////////////////////
  // Function complete
  // check quit options
  if (registry_.current_size() == 0 && quit_state_ == LIVE)
  {
    ACE_ERROR(( LM_INFO,
      "%s is idle\n",
      identity()
      ));
    if (quit_on_idle_)
    {
        this->poa_->deactivate_object (this->object_id_.in ()
               ACE_ENV_ARG_PARAMETER);
        quit_state_ = DEACTIVATED;
    }
  }

  METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_role);
}

void TAO::PG_FactoryRegistry::unregister_factory_by_location (
    const PortableGroup::Location & location
    ACE_ENV_ARG_DECL
  )
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_location);

  ////////////////////////////////////////////
  // a vector of roles that need to be deleted.
  ACE_Vector<ACE_CString> emptyRoles;

  // iterate through the registery
  for (RegistryType_Iterator it = this->registry_.begin();
       it != this->registry_.end();
       ++it)
  {
    RegistryType_Entry & entry = *it;
    ACE_CString & role = entry.ext_id_;
    RoleInfo * role_info =  entry.int_id_;

    PortableGroup::FactoryInfos & infos = role_info->infos_;
    // ACE_ERROR((LM_INFO,  "unregister_factory_by_location: Checking role %s\n", role.c_str()  ));

    int found = 0;
    size_t length = infos.length();
    for (size_t nInfo = 0; !found && nInfo < length; ++nInfo)
    {
      PortableGroup::FactoryInfo & info = infos[nInfo];
      if (info.the_location == location)
      {

        ACE_ERROR((LM_INFO,
          "%s: Unregister_factory_by_location: Removing: [%d] %s@%s\n",
          this->identity_.c_str(),
          static_cast<int> (nInfo),
          role.c_str(),
          static_cast<const char *> (location[0].id)
          ));
        found = 1;
        if (length > 1)
        {
          while (nInfo + 1 < length)
          {
            ACE_ERROR((LM_INFO,
              "%s: Unregister_factory_by_location: Move: [%d] %s to [%d]\n",
              this->identity_.c_str(),
              (int)nInfo + 1, role.c_str(), (int)nInfo
              ));
            infos[nInfo] = infos[nInfo + 1];
            nInfo += 1;
          }
          ACE_ERROR((LM_INFO,
            "%s: unregister_factory_by_location: New length [%d] %s\n",
            this->identity_.c_str(),
            (int)nInfo, role.c_str()
            ));
          infos.length(nInfo);
        }
        else
        {
          ACE_ERROR((LM_INFO,
            "%s: Removed all entries for %s\n",
            this->identity_.c_str(),
            role.c_str()
            ));
          ACE_ASSERT ( length == 1 );
          // remember entries to be deleted
          emptyRoles.push_back(entry.ext_id_);
        }
      }
    }
  }

  // now remove any roles that became empty

  for (size_t nRole = 0; nRole < emptyRoles.size(); ++nRole)
  {
    ACE_ERROR((LM_INFO,
      "%s: Remove role %s\n",
      this->identity_.c_str(),
      emptyRoles[nRole].c_str()
      ));
    RoleInfo * role_info;
    if (this->registry_.unbind(emptyRoles[nRole], role_info) == 0)
    {
      delete role_info;
    }
    else
    {
      ACE_ERROR ((LM_ERROR,
        "%s: LOGIC ERROR AT " __FILE__ " (%d): Role to be deleted disappeared\n",
        this->identity_.c_str(),
        __LINE__));
    }
  }
  //////////////////////////
  // If all types are gone...
  if (registry_.current_size() == 0 && quit_state_ == LIVE)
  {
    ACE_ERROR(( LM_INFO,
      "%s is idle\n",
      identity()
      ));
    if (quit_on_idle_)
    {
        this->poa_->deactivate_object (this->object_id_.in ()
               ACE_ENV_ARG_PARAMETER);
        quit_state_ = DEACTIVATED;
    }
  }

  METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_location);
}

::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_role (
    const char * role,
    CORBA::String_out type_id
    ACE_ENV_ARG_DECL
  )
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_role);

  // allocate stucture to be returned.
  PortableGroup::FactoryInfos_var result = 0;
  ACE_NEW_THROW_EX (result, ::PortableGroup::FactoryInfos(),
    CORBA::NO_MEMORY (TAO::VMCID, CORBA::COMPLETED_NO));

  ACE_CHECK_RETURN (0);

  RoleInfo * role_info = 0;
  if (this->registry_.find(role, role_info) == 0)
  {
    type_id =  CORBA::string_dup(role_info->type_id_.c_str());
    (*result) = role_info->infos_;
  }
  else
  {
    type_id = CORBA::string_dup("");
    ACE_ERROR(( LM_INFO,
      "%s: list_factories_by_role: unknown role %s\n",
      this->identity_.c_str(),
      role
      ));
  }
  METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_role) result._retn();
}

::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_location (
    const PortableGroup::Location & location
    ACE_ENV_ARG_DECL
  )
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_location);
  ::PortableGroup::FactoryInfos_var result;
  ACE_NEW_THROW_EX (result, ::PortableGroup::FactoryInfos(this->registry_.current_size()),
    CORBA::NO_MEMORY (TAO::VMCID, CORBA::COMPLETED_NO));

   ACE_CHECK_RETURN (0);

  size_t result_length = 0;

  // iterate through the registery
  for (RegistryType_Iterator it = this->registry_.begin();
       it != this->registry_.end();
       ++it)
  {
    RegistryType_Entry & entry = *it;
    RoleInfo * role_info = entry.int_id_;

    PortableGroup::FactoryInfos & found_infos = role_info->infos_;
    // iterate through the entry for this type
    int found = 0;
    size_t length = found_infos.length();
    for (size_t nInfo = 0; !found && nInfo < length; ++nInfo)
    {
      PortableGroup::FactoryInfo & info = found_infos[nInfo];
      if (info.the_location == location)
      {
        found = 1;
        result_length += 1;
        result->length(result_length);
        (*result)[result_length-1] = info;
      }
    }
  }

  METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_location) result._retn();
}

//////////////////////////////
// Implementation methods

int TAO::PG_FactoryRegistry::write_ior_file(const char * outputFile, const char * ior)
{
  int result = -1;
  FILE* out = ACE_OS::fopen (outputFile, "w");
  if (out)
  {
    ACE_OS::fprintf (out, "%s", ior);
    ACE_OS::fclose (out);
    result = 0;
  }
  else
  {
    ACE_ERROR ((LM_ERROR,
      "Open failed for %s\n", outputFile
    ));
  }
  return result;
}

TAO_END_VERSIONED_NAMESPACE_DECL